mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-14 13:39:15 +03:00
nixos: Extract module for activation script inclusion into toplevel
Allows omission of this functionality through disabledModules, e.g. for image building.
This commit is contained in:
parent
493b08c410
commit
61d43dee5f
3 changed files with 49 additions and 26 deletions
|
@ -1326,6 +1326,7 @@
|
||||||
./services/x11/xbanish.nix
|
./services/x11/xbanish.nix
|
||||||
./services/x11/xfs.nix
|
./services/x11/xfs.nix
|
||||||
./services/x11/xserver.nix
|
./services/x11/xserver.nix
|
||||||
|
./system/activation/activatable-system.nix
|
||||||
./system/activation/activation-script.nix
|
./system/activation/activation-script.nix
|
||||||
./system/activation/specialisation.nix
|
./system/activation/specialisation.nix
|
||||||
./system/activation/bootspec.nix
|
./system/activation/bootspec.nix
|
||||||
|
|
47
nixos/modules/system/activation/activatable-system.nix
Normal file
47
nixos/modules/system/activation/activatable-system.nix
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
system.systemBuilderArgs = {
|
||||||
|
activationScript = config.system.activationScripts.script;
|
||||||
|
dryActivationScript = config.system.dryActivationScript;
|
||||||
|
localeArchive = "${config.i18n.glibcLocales}/lib/locale/locale-archive";
|
||||||
|
distroId = config.system.nixos.distroId;
|
||||||
|
perl = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]);
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration
|
||||||
|
chmod +x $out/bin/switch-to-configuration
|
||||||
|
${optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
|
||||||
|
if ! output=$($perl/bin/perl -c $out/bin/switch-to-configuration 2>&1); then
|
||||||
|
echo "switch-to-configuration syntax is not valid:"
|
||||||
|
echo "$output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
''}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -36,13 +36,6 @@ let
|
||||||
ln -s ${config.hardware.firmware}/lib/firmware $out/firmware
|
ln -s ${config.hardware.firmware}/lib/firmware $out/firmware
|
||||||
''}
|
''}
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
${if config.boot.initrd.systemd.enable then ''
|
${if config.boot.initrd.systemd.enable then ''
|
||||||
cp ${config.system.build.bootStage2} $out/prepare-root
|
cp ${config.system.build.bootStage2} $out/prepare-root
|
||||||
substituteInPlace $out/prepare-root --subst-var-by systemConfig $out
|
substituteInPlace $out/prepare-root --subst-var-by systemConfig $out
|
||||||
|
@ -63,19 +56,6 @@ let
|
||||||
echo -n "$nixosLabel" > $out/nixos-version
|
echo -n "$nixosLabel" > $out/nixos-version
|
||||||
echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system
|
echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system
|
||||||
|
|
||||||
mkdir $out/bin
|
|
||||||
export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive"
|
|
||||||
export distroId=${config.system.nixos.distroId};
|
|
||||||
substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration
|
|
||||||
chmod +x $out/bin/switch-to-configuration
|
|
||||||
${optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
|
|
||||||
if ! output=$($perl/bin/perl -c $out/bin/switch-to-configuration 2>&1); then
|
|
||||||
echo "switch-to-configuration syntax is not valid:"
|
|
||||||
echo "$output"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
''}
|
|
||||||
|
|
||||||
${config.system.systemBuilderCommands}
|
${config.system.systemBuilderCommands}
|
||||||
|
|
||||||
cp "$extraDependenciesPath" "$out/extra-dependencies"
|
cp "$extraDependenciesPath" "$out/extra-dependencies"
|
||||||
|
@ -93,7 +73,7 @@ let
|
||||||
# symlinks to the various parts of the built configuration (the
|
# symlinks to the various parts of the built configuration (the
|
||||||
# kernel, systemd units, init scripts, etc.) as well as a script
|
# kernel, systemd units, init scripts, etc.) as well as a script
|
||||||
# `switch-to-configuration' that activates the configuration and
|
# `switch-to-configuration' that activates the configuration and
|
||||||
# makes it bootable.
|
# makes it bootable. See `activatable-system.nix`.
|
||||||
baseSystem = pkgs.stdenvNoCC.mkDerivation ({
|
baseSystem = pkgs.stdenvNoCC.mkDerivation ({
|
||||||
name = "nixos-system-${config.system.name}-${config.system.nixos.label}";
|
name = "nixos-system-${config.system.name}-${config.system.nixos.label}";
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
|
@ -109,14 +89,9 @@ let
|
||||||
|
|
||||||
kernelParams = config.boot.kernelParams;
|
kernelParams = config.boot.kernelParams;
|
||||||
installBootLoader = config.system.build.installBootLoader;
|
installBootLoader = config.system.build.installBootLoader;
|
||||||
activationScript = config.system.activationScripts.script;
|
|
||||||
dryActivationScript = config.system.dryActivationScript;
|
|
||||||
nixosLabel = config.system.nixos.label;
|
nixosLabel = config.system.nixos.label;
|
||||||
|
|
||||||
inherit (config.system) extraDependencies;
|
inherit (config.system) extraDependencies;
|
||||||
|
|
||||||
# Needed by switch-to-configuration.
|
|
||||||
perl = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]);
|
|
||||||
} // config.system.systemBuilderArgs);
|
} // config.system.systemBuilderArgs);
|
||||||
|
|
||||||
# Handle assertions and warnings
|
# Handle assertions and warnings
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue