summary refs log tree commit diff
path: root/nixos/modules/system/activation/activation-script.nix
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2018-10-04 11:57:18 +0800
committerPeter Hoeg <peter@hoeg.com>2018-10-05 10:06:40 +0800
commit1353ba26787d398f3595deea28e21a134978df83 (patch)
tree840ece06d9eca343883424bf9d8f86125e61a783 /nixos/modules/system/activation/activation-script.nix
parent13b2903169f18ac98ed737effb36dabc48051978 (diff)
downloadnixpkgs-1353ba26787d398f3595deea28e21a134978df83.tar
nixpkgs-1353ba26787d398f3595deea28e21a134978df83.tar.gz
nixpkgs-1353ba26787d398f3595deea28e21a134978df83.tar.bz2
nixpkgs-1353ba26787d398f3595deea28e21a134978df83.tar.lz
nixpkgs-1353ba26787d398f3595deea28e21a134978df83.tar.xz
nixpkgs-1353ba26787d398f3595deea28e21a134978df83.tar.zst
nixpkgs-1353ba26787d398f3595deea28e21a134978df83.zip
system-activation: support script fragments to run in a user context
Diffstat (limited to 'nixos/modules/system/activation/activation-script.nix')
-rw-r--r--nixos/modules/system/activation/activation-script.nix54
1 files changed, 54 insertions, 0 deletions
diff --git a/nixos/modules/system/activation/activation-script.nix b/nixos/modules/system/activation/activation-script.nix
index 93a1b13a81d..5a87a2ec762 100644
--- a/nixos/modules/system/activation/activation-script.nix
+++ b/nixos/modules/system/activation/activation-script.nix
@@ -100,6 +100,52 @@ in
             exit $_status
           '';
       };
+    };
+
+    system.userActivationScripts = mkOption {
+      default = {};
+
+      example = literalExample ''
+        { plasmaSetup = {
+            text = '''
+              ${pkgs.libsForQt5.kservice}/bin/kbuildsycoca5"
+            ''';
+            deps = [];
+          };
+        }
+      '';
+
+      description = ''
+        A set of shell script fragments that are executed by a systemd user
+        service when a NixOS system configuration is activated. Examples are
+        rebuilding the .desktop file cache for showing applications in the menu.
+        Since these are executed every time you run
+        <command>nixos-rebuild</command>, it's important that they are
+        idempotent and fast.
+      '';
+
+      type = types.attrsOf types.unspecified;
+
+      apply = set: {
+        script = ''
+          unset PATH
+          for i in ${toString path}; do
+            PATH=$PATH:$i/bin:$i/sbin
+          done
+
+          _status=0
+          trap "_status=1 _localstatus=\$?" ERR
+
+          ${
+            let
+              set' = mapAttrs (n: v: if isString v then noDepEntry v else v) set;
+              withHeadlines = addAttributeName set';
+            in textClosureMap id (withHeadlines) (attrNames withHeadlines)
+          }
+
+          exit $_status
+        '';
+      };
 
     };
 
@@ -177,6 +223,14 @@ in
         source ${config.system.build.earlyMountScript}
       '';
 
+    systemd.user = {
+      services.nixos-activation = {
+        description = "Run user specific NixOS activation";
+        script = config.system.userActivationScripts.script;
+        unitConfig.ConditionUser = "!@system";
+        serviceConfig.Type = "oneshot";
+      };
+    };
   };
 
 }