summaryrefslogtreecommitdiff
path: root/nixos
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2022-09-21 20:04:22 +0200
committerQuentin Aristote <quentin@aristote.fr>2022-09-21 20:04:22 +0200
commit2cacc732759d3e4366ad87677b1dd42c9d7f8f6d (patch)
tree8b3558e3e795298de932f7273f7ecb2ad6e47541 /nixos
parentcf88b57f14965cec9fc57a256224595dfe60ba54 (diff)
nixos: services: direnv: refactor and prune direnvs
Diffstat (limited to 'nixos')
-rw-r--r--nixos/services.nix62
1 files changed, 37 insertions, 25 deletions
diff --git a/nixos/services.nix b/nixos/services.nix
index 1d9d850..f0a04ef 100644
--- a/nixos/services.nix
+++ b/nixos/services.nix
@@ -1,28 +1,9 @@
{ lib, config, pkgs, ... }:
let
- direnv-reload-service = user: {
- description = "Update virtual environments of user ${user}";
-
- restartIfChanged = false;
- unitConfig.X-StopOnRemoval = false;
- serviceConfig = {
- Type = "oneshot";
- User = user;
- };
-
- environment = {
- inherit (config.environment.sessionVariables) NIX_PATH;
- HOME = config.users.users."${user}".home;
- };
-
- path = with pkgs; [ direnv ];
- script = ''
- find $HOME -type d -name .nix-gc-roots -execdir direnv exec . true \;
- '';
-
- after = [ "nixos-upgrade.service" ];
- wantedBy = [ "nixos-upgrade.service" ];
+ userService = user: {
+ serviceConfig.User = user;
+ environment.HOME = config.users.users."${user}".home;
};
in {
# List services that you want to enable:
@@ -30,9 +11,40 @@ in {
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
- systemd.services.direnv-reload = lib.mkIf config.system.autoUpgrade.enable
- (direnv-reload-service "qaristote");
- systemd.services.nix-gc.after = [ "direnv-reload.service" ];
+ 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 = {
+ enable = true;
+ description = "Clean virtual environments of user qaristote";
+
+ serviceConfig.Type = "oneshot";
+
+ path = with pkgs; [ direnv ];
+ script = "find $HOME -type d -name .direnv -execdir direnv prune \\;";
+
+ 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");
+ };
# virtualisation.docker.enable = true;
}