summaryrefslogtreecommitdiff
path: root/home/config/direnv.nix
blob: 7594ee59367d20c3c6bc7e730a91bcba013f680d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{ config, lib, pkgs, ... }:

let cfg = config.programs.direnv;
in {
  programs.direnv = {
    enable = true;
    nix-direnv.enable = true;
  };

  systemd.user = lib.mkIf cfg.enable
    (pkgs.personal.lib.serviceWithTimer "direnv-clean-update" {
      Unit = {
        Description =
          "Remove old virtual environments and update the current ones";
        After = [ "network-online.target" ];
      };
      Service = {
        Type = "oneshot";
        ExecSearchPath = "${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.direnv}/bin:/bin/sh";
        WorkingDirectory = "${config.home.homeDirectory}";
        ExecStart = ''
          find -type d -name .direnv \
               -execdir /bin/sh -c "rm -f .direnv/{nix,flake}-profile*" \; \
               -execdir direnv exec . true \;
        '';
      };
      Timer = {
        Persistent = true;
        OnCalendar = "daily";
      };
      Install = { WantedBy = [ "default.target " ]; };
    });
}