9 perlWrapped = pkgs.perl.withPackages (
17 options.system.switch = {
18 enable = lib.mkOption {
19 type = lib.types.bool;
22 Whether to include the capability to switch configurations.
24 Disabling this makes the system unable to be reconfigured via `nixos-rebuild`.
26 This is good for image based appliances where updates are handled
27 outside the image. Reducing features makes the image lighter and
32 enableNg = lib.mkOption {
33 type = lib.types.bool;
34 default = config.system.switch.enable;
35 defaultText = lib.literalExpression "config.system.switch.enable";
37 Whether to use `switch-to-configuration-ng`, the Rust-based
38 re-implementation of the original Perl `switch-to-configuration`.
43 config = lib.mkMerge [
44 (lib.mkIf (config.system.switch.enable && !config.system.switch.enableNg) {
47 The Perl implementation of switch-to-configuration will be deprecated
48 and removed in the 25.05 release of NixOS. Please migrate to the
49 newer implementation by removing `system.switch.enableNg = false`
50 from your configuration. If you are unable to migrate due to any
51 issues with the new implementation, please create an issue and tag
52 the maintainers of `switch-to-configuration-ng`.
56 system.activatableSystemBuilderCommands = ''
58 substitute ${./switch-to-configuration.pl} $out/bin/switch-to-configuration \
60 --subst-var-by toplevel ''${!toplevelVar} \
61 --subst-var-by coreutils "${pkgs.coreutils}" \
62 --subst-var-by distroId ${lib.escapeShellArg config.system.nixos.distroId} \
63 --subst-var-by installBootLoader ${lib.escapeShellArg config.system.build.installBootLoader} \
64 --subst-var-by preSwitchCheck ${lib.escapeShellArg config.system.preSwitchChecks.script} \
65 --subst-var-by localeArchive "${config.i18n.glibcLocales}/lib/locale/locale-archive" \
66 --subst-var-by perl "${perlWrapped}" \
67 --subst-var-by shell "${pkgs.bash}/bin/sh" \
68 --subst-var-by su "${pkgs.shadow.su}/bin/su" \
69 --subst-var-by systemd "${config.systemd.package}" \
70 --subst-var-by utillinux "${pkgs.util-linux}" \
73 chmod +x $out/bin/switch-to-configuration
74 ${lib.optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
75 if ! output=$(${perlWrapped}/bin/perl -c $out/bin/switch-to-configuration 2>&1); then
76 echo "switch-to-configuration syntax is not valid:"
83 (lib.mkIf config.system.switch.enableNg {
84 # Use a subshell so we can source makeWrapper's setup hook without
85 # affecting the rest of activatableSystemBuilderCommands.
86 system.activatableSystemBuilderCommands = ''
88 source ${pkgs.buildPackages.makeWrapper}/nix-support/setup-hook
91 ln -sf ${lib.getExe pkgs.switch-to-configuration-ng} $out/bin/switch-to-configuration
92 wrapProgram $out/bin/switch-to-configuration \
94 --set TOPLEVEL ''${!toplevelVar} \
95 --set DISTRO_ID ${lib.escapeShellArg config.system.nixos.distroId} \
96 --set INSTALL_BOOTLOADER ${lib.escapeShellArg config.system.build.installBootLoader} \
97 --set PRE_SWITCH_CHECK ${lib.escapeShellArg config.system.preSwitchChecks.script} \
98 --set LOCALE_ARCHIVE ${config.i18n.glibcLocales}/lib/locale/locale-archive \
99 --set SYSTEMD ${config.systemd.package}