Add activationBefore and activationAfter options

This commit is contained in:
Tobias Happ 2019-11-27 10:13:40 +01:00 committed by Alexander Sosedkin
parent 867aa587ea
commit cc77204f65
3 changed files with 37 additions and 5 deletions

View file

@ -19,11 +19,11 @@ let
pkgs.nix
];
activationCmds = concatStringsSep "\n" (
mkActivationCmds = activation: concatStringsSep "\n" (
mapAttrsToList (name: value: ''
noteEcho "Activating ${name}"
${value}
'') cfg.activation
'') activation
);
activationScript = pkgs.writeScript "activation-script" ''
@ -39,7 +39,9 @@ let
${builtins.readFile ../lib-bash/color-echo.sh}
${builtins.readFile ../lib-bash/activation-init.sh}
${activationCmds}
${mkActivationCmds cfg.activationBefore}
${mkActivationCmds cfg.activation}
${mkActivationCmds cfg.activationAfter}
'';
in
@ -64,6 +66,36 @@ in
'';
};
activationBefore = mkOption {
default = {};
type = types.attrs;
description = ''
Activation scripts for the nix-on-droid environment that
need to be run first.
</para><para>
Any script should respect the <varname>DRY_RUN</varname>
variable, if it is set then no actual action should be taken.
The variable <varname>DRY_RUN_CMD</varname> is set to
<code>echo</code> if dry run is enabled. Thus, many cases you
can use the idiom <code>$DRY_RUN_CMD rm -rf /</code>.
'';
};
activationAfter = mkOption {
default = {};
type = types.attrs;
description = ''
Activation scripts for the nix-on-droid environment that
need to be run last.
</para><para>
Any script should respect the <varname>DRY_RUN</varname>
variable, if it is set then no actual action should be taken.
The variable <varname>DRY_RUN_CMD</varname> is set to
<code>echo</code> if dry run is enabled. Thus, many cases you
can use the idiom <code>$DRY_RUN_CMD rm -rf /</code>.
'';
};
activationPackage = mkOption {
type = types.package;
readOnly = true;

View file

@ -36,7 +36,7 @@ in
config = {
build.activation = {
build.activationBefore = {
linkBinSh = ''
$DRY_RUN_CMD mkdir $VERBOSE_ARG --parents /bin
$DRY_RUN_CMD ln $VERBOSE_ARG --symbolic --force ${cfg.binSh} /bin/.sh.tmp

View file

@ -49,7 +49,7 @@ in
inherit (cfg.config) assertions warnings;
build.activation.homeManager = ''
build.activationAfter.homeManager = ''
${cfg.config.home.activationPackage}/activate
'';