From cc77204f653ff5a564d4e66bc27d5eff8edc1e25 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Wed, 27 Nov 2019 10:13:40 +0100 Subject: [PATCH] Add activationBefore and activationAfter options --- modules/build/activation.nix | 38 ++++++++++++++++++++++++++++++++--- modules/environment/links.nix | 2 +- modules/home-manager.nix | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/modules/build/activation.nix b/modules/build/activation.nix index 3802883..f266596 100644 --- a/modules/build/activation.nix +++ b/modules/build/activation.nix @@ -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. + + Any script should respect the DRY_RUN + variable, if it is set then no actual action should be taken. + The variable DRY_RUN_CMD is set to + echo if dry run is enabled. Thus, many cases you + can use the idiom $DRY_RUN_CMD rm -rf /. + ''; + }; + + activationAfter = mkOption { + default = {}; + type = types.attrs; + description = '' + Activation scripts for the nix-on-droid environment that + need to be run last. + + Any script should respect the DRY_RUN + variable, if it is set then no actual action should be taken. + The variable DRY_RUN_CMD is set to + echo if dry run is enabled. Thus, many cases you + can use the idiom $DRY_RUN_CMD rm -rf /. + ''; + }; + activationPackage = mkOption { type = types.package; readOnly = true; diff --git a/modules/environment/links.nix b/modules/environment/links.nix index 5475b62..73a33a0 100644 --- a/modules/environment/links.nix +++ b/modules/environment/links.nix @@ -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 diff --git a/modules/home-manager.nix b/modules/home-manager.nix index f560c64..cb1186a 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -49,7 +49,7 @@ in inherit (cfg.config) assertions warnings; - build.activation.homeManager = '' + build.activationAfter.homeManager = '' ${cfg.config.home.activationPackage}/activate '';