diff options
author | Peter Hoeg <peter@hoeg.com> | 2018-10-04 11:57:18 +0800 |
---|---|---|
committer | Peter Hoeg <peter@hoeg.com> | 2018-10-05 11:26:22 +0800 |
commit | c5b97d47b833d62c9a498152b571da2f7b2961db (patch) | |
tree | 3fa0e952a344614085d146f7b5cc180d8dd32653 /nixos | |
parent | b4d7324678c3eebcd48a697ac8f5f4bc3c50873b (diff) |
system-activation: support script fragments to run in a user context
(cherry picked from commit 1353ba26787d398f3595deea28e21a134978df83)
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/system/activation/activation-script.nix | 54 |
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 93a1b13a81dda..5a87a2ec7623a 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"; + }; + }; }; } |