2023-06-10 13:08:38 +00:00
|
|
|
/*
|
|
|
|
This module adds the activation script to toplevel, so that any previously
|
|
|
|
built configuration can be activated again, as long as they're available in
|
|
|
|
the store, e.g. through the profile's older generations.
|
|
|
|
|
|
|
|
Alternate applications of the NixOS modules may omit this module, e.g. to
|
|
|
|
build images that are pre-activated and omit the activation script and its
|
|
|
|
dependencies.
|
|
|
|
*/
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
optionalString
|
|
|
|
;
|
2023-06-21 13:51:11 +00:00
|
|
|
|
|
|
|
perlWrapped = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]);
|
|
|
|
|
2023-06-10 13:08:38 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
config = {
|
|
|
|
system.systemBuilderArgs = {
|
|
|
|
activationScript = config.system.activationScripts.script;
|
|
|
|
dryActivationScript = config.system.dryActivationScript;
|
|
|
|
};
|
|
|
|
|
|
|
|
system.systemBuilderCommands = ''
|
|
|
|
echo "$activationScript" > $out/activate
|
|
|
|
echo "$dryActivationScript" > $out/dry-activate
|
|
|
|
substituteInPlace $out/activate --subst-var out
|
|
|
|
substituteInPlace $out/dry-activate --subst-var out
|
|
|
|
chmod u+x $out/activate $out/dry-activate
|
|
|
|
unset activationScript dryActivationScript
|
|
|
|
|
|
|
|
mkdir $out/bin
|
2023-06-10 14:37:58 +00:00
|
|
|
substitute ${./switch-to-configuration.pl} $out/bin/switch-to-configuration \
|
|
|
|
--subst-var out \
|
2023-06-21 13:51:11 +00:00
|
|
|
--subst-var-by coreutils "${pkgs.coreutils}" \
|
|
|
|
--subst-var-by distroId ${lib.escapeShellArg config.system.nixos.distroId} \
|
|
|
|
--subst-var-by installBootLoader ${lib.escapeShellArg config.system.build.installBootLoader} \
|
|
|
|
--subst-var-by localeArchive "${config.i18n.glibcLocales}/lib/locale/locale-archive" \
|
|
|
|
--subst-var-by perl "${perlWrapped}" \
|
|
|
|
--subst-var-by shell "${pkgs.bash}/bin/sh" \
|
|
|
|
--subst-var-by su "${pkgs.shadow.su}/bin/su" \
|
|
|
|
--subst-var-by systemd "${config.systemd.package}"\
|
|
|
|
--subst-var-by utillinux "${pkgs.util-linux}" \
|
2023-06-10 14:37:58 +00:00
|
|
|
;
|
|
|
|
|
2023-06-10 13:08:38 +00:00
|
|
|
chmod +x $out/bin/switch-to-configuration
|
|
|
|
${optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
|
2023-06-21 13:51:11 +00:00
|
|
|
if ! output=$(${perlWrapped}/bin/perl -c $out/bin/switch-to-configuration 2>&1); then
|
2023-06-10 13:08:38 +00:00
|
|
|
echo "switch-to-configuration syntax is not valid:"
|
|
|
|
echo "$output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
''}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|