summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2022-09-25 14:12:11 +0200
committerQuentin Aristote <quentin@aristote.fr>2022-09-25 14:12:11 +0200
commitd6080ef128404a97a0b7dc1653b78260d473f159 (patch)
tree0bd433e30d78c8205912b5334848fbc4806f941e
parent6b7c3879c75f41469edc6897a9dfabf5f0ae17d9 (diff)
move direnv-{clean,reload} services to home-manager
-rw-r--r--home/config/default.nix1
-rw-r--r--home/config/direnv.nix34
-rw-r--r--home/config/environment.nix5
-rw-r--r--nixos/services.nix38
4 files changed, 41 insertions, 37 deletions
diff --git a/home/config/default.nix b/home/config/default.nix
index 0d02561..7fab93f 100644
--- a/home/config/default.nix
+++ b/home/config/default.nix
@@ -3,6 +3,7 @@
{
imports = [
./alacritty.nix
+ ./direnv.nix
./environment.nix
./emacs.nix
./firefox
diff --git a/home/config/direnv.nix b/home/config/direnv.nix
new file mode 100644
index 0000000..fc5c61b
--- /dev/null
+++ b/home/config/direnv.nix
@@ -0,0 +1,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";
+ WorkingDirectory = "${config.home.homeDirectory}";
+ ExecStart = ''
+ find -type d -name .direnv \
+ -execdir rm -f .direnv/{nix,flake}-profile* \; \
+ -execdir direnv exec . true \;
+ '';
+ };
+ Timer = {
+ Persistent = true;
+ OnCalendar = "daily";
+ };
+ Install = { WantedBy = [ "default.target " ]; };
+ });
+}
+
diff --git a/home/config/environment.nix b/home/config/environment.nix
index 88120e9..77d00e5 100644
--- a/home/config/environment.nix
+++ b/home/config/environment.nix
@@ -56,11 +56,6 @@
};
};
- programs.direnv = {
- enable = true;
- nix-direnv.enable = true;
- };
-
services.gpg-agent = {
enable = true;
enableSshSupport = true;
diff --git a/nixos/services.nix b/nixos/services.nix
index f0a04ef..f8baf85 100644
--- a/nixos/services.nix
+++ b/nixos/services.nix
@@ -1,49 +1,23 @@
{ lib, config, pkgs, ... }:
-let
- userService = user: {
- serviceConfig.User = user;
- environment.HOME = config.users.users."${user}".home;
- };
-in {
+{
# List services that you want to enable:
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
systemd.services = {
- direnv-reload = {
- enable = true;
- description = "Update virtual environments of user qaristote";
-
- restartIfChanged = false;
- unitConfig.X-StopOnRemoval = false;
- serviceConfig.Type = "oneshot";
-
- environment.NIX_PATH = config.environment.sessionVariables.NIX_PATH;
-
- path = with pkgs; [ direnv ];
- script =
- "find $HOME -type d -name .nix-gc-roots -execdir direnv exec . true \\;";
-
- after =
- lib.mkIf config.system.autoUpgrade.enable [ "nixos-upgrade.service" ];
- requiredBy =
- lib.mkIf config.system.autoUpgrade.enable [ "nixos-upgrade.service" ];
- } // (userService "qaristote");
- direnv-prune = {
+ nix-gc-remove-dead-roots = {
enable = true;
- description = "Clean virtual environments of user qaristote";
+ description = "Remove dead symlinks in /nix/var/nix/gcroots";
serviceConfig.Type = "oneshot";
- path = with pkgs; [ direnv ];
- script = "find $HOME -type d -name .direnv -execdir direnv prune \\;";
+ script = "find /nix/var/nix/gcroots -xtype l -delete";
- after = [ "direnv-reload.service" ];
before = lib.mkIf config.nix.gc.automatic [ "nix-gc.service" ];
- requiredBy = lib.mkIf config.nix.gc.automatic [ "nix-gc.service" ];
- } // (userService "qaristote");
+ wantedBy = lib.mkIf config.nix.gc.automatic [ "nix-gc.service" ];
+ };
};
# virtualisation.docker.enable = true;