summaryrefslogtreecommitdiff
path: root/nixos
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2022-08-31 14:32:14 +0200
committerQuentin Aristote <quentin@aristote.fr>2022-08-31 14:32:14 +0200
commit142e09b930ff4ce2f3afeaa1cbb70674f27b0111 (patch)
tree09617dc953f0e1ceaffded4a3193cc1d7316a247 /nixos
parent338c0e24b923a6cc0aff4af1b44999441cdb281e (diff)
nixos: services: add service to reload direnvs after auto nixos upgrades
Diffstat (limited to 'nixos')
-rw-r--r--nixos/configuration.nix3
-rw-r--r--nixos/services.nix43
2 files changed, 31 insertions, 15 deletions
diff --git a/nixos/configuration.nix b/nixos/configuration.nix
index c384a54..085bcf2 100644
--- a/nixos/configuration.nix
+++ b/nixos/configuration.nix
@@ -2,7 +2,7 @@
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
-{ config, pkgs, ... }:
+{ lib, config, pkgs, ... }:
{
imports = [
@@ -37,6 +37,7 @@
enable = true;
flags = [ "--upgrade-all" ];
};
+ systemd.services.nix-gc.after = lib.mkIf config.system.autoUpgrade.enable [ "nixos-upgrade.service" ];
# Some programs need SUID wrappers, can be configured further or are
# started in user sessions.
diff --git a/nixos/services.nix b/nixos/services.nix
index 984eace..1d9d850 100644
--- a/nixos/services.nix
+++ b/nixos/services.nix
@@ -1,23 +1,38 @@
-{ pkgs, config, ... }:
+{ 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" ];
+ };
+in {
# List services that you want to enable:
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
- services = {
- fcron = {
- enable = true;
- allow = [ "root" "qaristote" ];
- systab = ''
- # Update the system.
- # @daily root ${pkgs.nix}/bin/nix-channel --update; ${pkgs.nixos-rebuild}/bin/nixos-rebuild switch
- # Update virtual environments
- @daily qaristote find /home/qaristote -type d -name .nix-gc-roots -execdir ${pkgs.direnv}/bin/direnv exec . true \;
- '';
- };
- };
+ systemd.services.direnv-reload = lib.mkIf config.system.autoUpgrade.enable
+ (direnv-reload-service "qaristote");
+ systemd.services.nix-gc.after = [ "direnv-reload.service" ];
# virtualisation.docker.enable = true;
}