diff options
author | Robert Hensing <robert@roberthensing.nl> | 2023-06-10 15:08:38 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2023-06-10 19:15:00 +0200 |
commit | 61d43dee5f1ca98be582ccc5dcde04015adb8f8f (patch) | |
tree | a5d59b24ddcb8b813a129e3436dac91b50bac814 /nixos/modules/system/activation | |
parent | 493b08c4108750685fd95b928745d0e583636788 (diff) |
nixos: Extract module for activation script inclusion into toplevel
Allows omission of this functionality through disabledModules, e.g. for image building.
Diffstat (limited to 'nixos/modules/system/activation')
-rw-r--r-- | nixos/modules/system/activation/activatable-system.nix | 47 | ||||
-rw-r--r-- | nixos/modules/system/activation/top-level.nix | 27 |
2 files changed, 48 insertions, 26 deletions
diff --git a/nixos/modules/system/activation/activatable-system.nix b/nixos/modules/system/activation/activatable-system.nix new file mode 100644 index 0000000000000..69014331c2a0c --- /dev/null +++ b/nixos/modules/system/activation/activatable-system.nix @@ -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 + ''} + ''; + }; +} diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix index c4427149d9c91..4973d61da13ea 100644 --- a/nixos/modules/system/activation/top-level.nix +++ b/nixos/modules/system/activation/top-level.nix @@ -36,13 +36,6 @@ let 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 '' cp ${config.system.build.bootStage2} $out/prepare-root substituteInPlace $out/prepare-root --subst-var-by systemConfig $out @@ -63,19 +56,6 @@ let echo -n "$nixosLabel" > $out/nixos-version 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} cp "$extraDependenciesPath" "$out/extra-dependencies" @@ -93,7 +73,7 @@ let # symlinks to the various parts of the built configuration (the # kernel, systemd units, init scripts, etc.) as well as a script # `switch-to-configuration' that activates the configuration and - # makes it bootable. + # makes it bootable. See `activatable-system.nix`. baseSystem = pkgs.stdenvNoCC.mkDerivation ({ name = "nixos-system-${config.system.name}-${config.system.nixos.label}"; preferLocalBuild = true; @@ -109,14 +89,9 @@ let kernelParams = config.boot.kernelParams; installBootLoader = config.system.build.installBootLoader; - activationScript = config.system.activationScripts.script; - dryActivationScript = config.system.dryActivationScript; nixosLabel = config.system.nixos.label; inherit (config.system) extraDependencies; - - # Needed by switch-to-configuration. - perl = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]); } // config.system.systemBuilderArgs); # Handle assertions and warnings |