Rewrite switch-to-configuration in Perl
This will make it more efficient to do systemd dependency graph processing (if necessary).
This commit is contained in:
parent
d4fec178fd
commit
0fc68a3d1d
57
modules/system/activation/switch-to-configuration.pl
Normal file
57
modules/system/activation/switch-to-configuration.pl
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#! @perl@
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use File::Slurp;
|
||||||
|
|
||||||
|
my $action = shift @ARGV;
|
||||||
|
|
||||||
|
if (!defined $action || ($action ne "switch" && $action ne "boot" && $action ne "test")) {
|
||||||
|
print STDERR <<EOF;
|
||||||
|
Usage: $0 [switch|boot|test]
|
||||||
|
|
||||||
|
switch: make the configuration the boot default and activate now
|
||||||
|
boot: make the configuration the boot default
|
||||||
|
test: activate the configuration, but don\'t make it the boot default
|
||||||
|
EOF
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
die "This is not a NixOS installation (/etc/NIXOS is missing)!\n" unless -f "/etc/NIXOS";
|
||||||
|
|
||||||
|
# Install or update the bootloader.
|
||||||
|
#system("@installBootLoader@ @out@") == 0 or exit 1 if $action eq "switch" || $action eq "boot";
|
||||||
|
exit 0 if $action eq "boot";
|
||||||
|
|
||||||
|
# Check if we can activate the new configuration.
|
||||||
|
my $oldVersion = read_file("/run/current-system/init-interface-version", err_mode => 'quiet') // "";
|
||||||
|
my $newVersion = read_file("@out@/init-interface-version");
|
||||||
|
|
||||||
|
if ($newVersion ne $oldVersion) {
|
||||||
|
print STDERR <<EOF;
|
||||||
|
Warning: the new NixOS configuration has an ‘init’ that is
|
||||||
|
incompatible with the current configuration. The new configuration
|
||||||
|
won\'t take effect until you reboot the system.
|
||||||
|
EOF
|
||||||
|
exit 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ignore SIGHUP so that we're not killed if we're running on (say)
|
||||||
|
# virtual console 1 and we restart the "tty1" unit.
|
||||||
|
$SIG{PIPE} = "IGNORE";
|
||||||
|
|
||||||
|
# Activate the new configuration (i.e., update /etc, make accounts,
|
||||||
|
# and so on).
|
||||||
|
my $res = 0;
|
||||||
|
print STDERR "activating the configuration...\n";
|
||||||
|
system("@out@/activate", "@out@") == 0 or $res = 2;
|
||||||
|
|
||||||
|
# FIXME: Re-exec systemd if necessary.
|
||||||
|
|
||||||
|
# Make systemd reload its units.
|
||||||
|
system("@systemd@/bin/systemctl", "daemon-reload") == 0 or $res = 3;
|
||||||
|
|
||||||
|
# Signal dbus to reload its configuration.
|
||||||
|
system("@systemd@/bin/systemctl", "reload", "dbus.service");
|
||||||
|
|
||||||
|
exit $res;
|
@ -1,59 +0,0 @@
|
|||||||
#! @shell@
|
|
||||||
|
|
||||||
set -e
|
|
||||||
export PATH=/empty
|
|
||||||
for i in @path@; do PATH=$PATH:$i/bin:$i/sbin; done
|
|
||||||
action="$1"
|
|
||||||
|
|
||||||
if ! test -e /etc/NIXOS; then
|
|
||||||
echo "This is not a NixOS installation (/etc/NIXOS) is missing!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -z "$action"; then
|
|
||||||
cat <<EOF
|
|
||||||
Usage: $0 [switch|boot|test]
|
|
||||||
|
|
||||||
switch: make the configuration the boot default and activate now
|
|
||||||
boot: make the configuration the boot default
|
|
||||||
test: activate the configuration, but don't make it the boot default
|
|
||||||
EOF
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install or update the bootloader.
|
|
||||||
if [ "$action" = "switch" -o "$action" = "boot" ]; then
|
|
||||||
@installBootLoader@ @out@
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Activate the new configuration.
|
|
||||||
if [ "$action" != switch -a "$action" != test ]; then exit 0; fi
|
|
||||||
|
|
||||||
oldVersion="$(cat /run/current-system/init-interface-version 2> /dev/null || echo "")"
|
|
||||||
newVersion="$(cat @out@/init-interface-version)"
|
|
||||||
|
|
||||||
if [ "$oldVersion" != "$newVersion" ]; then
|
|
||||||
cat <<EOF
|
|
||||||
Warning: the new NixOS configuration has an ‘init’ that is
|
|
||||||
incompatible with the current configuration. The new configuration
|
|
||||||
won't take effect until you reboot the system.
|
|
||||||
EOF
|
|
||||||
exit 100 # denotes "reboot required" to Charon
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ignore SIGHUP so that we're not killed if we're running on (say)
|
|
||||||
# virtual console 1 and we restart the "tty1" job.
|
|
||||||
trap "" SIGHUP
|
|
||||||
|
|
||||||
# Activate the new configuration (i.e., update /etc, make accounts,
|
|
||||||
# and so on).
|
|
||||||
echo "activating the configuration..."
|
|
||||||
@out@/activate @out@
|
|
||||||
|
|
||||||
# FIXME: Re-exec systemd if necessary.
|
|
||||||
|
|
||||||
# Make systemd reload its jobs.
|
|
||||||
systemctl daemon-reload
|
|
||||||
|
|
||||||
# Signal dbus to reload its configuration.
|
|
||||||
systemctl reload dbus.service || true
|
|
@ -114,7 +114,7 @@ let
|
|||||||
|
|
||||||
ln -s ${config.system.build.etc}/etc $out/etc
|
ln -s ${config.system.build.etc}/etc $out/etc
|
||||||
ln -s ${config.system.path} $out/sw
|
ln -s ${config.system.path} $out/sw
|
||||||
ln -s ${pkgs.systemd} $out/systemd
|
ln -s "$systemd" $out/systemd
|
||||||
ln -s ${config.hardware.firmware} $out/firmware
|
ln -s ${config.hardware.firmware} $out/firmware
|
||||||
|
|
||||||
echo -n "$kernelParams" > $out/kernel-params
|
echo -n "$kernelParams" > $out/kernel-params
|
||||||
@ -130,7 +130,7 @@ let
|
|||||||
done
|
done
|
||||||
|
|
||||||
mkdir $out/bin
|
mkdir $out/bin
|
||||||
substituteAll ${./switch-to-configuration.sh} $out/bin/switch-to-configuration
|
substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration
|
||||||
chmod +x $out/bin/switch-to-configuration
|
chmod +x $out/bin/switch-to-configuration
|
||||||
|
|
||||||
${config.system.extraSystemBuilderCmds}
|
${config.system.extraSystemBuilderCmds}
|
||||||
@ -146,6 +146,9 @@ let
|
|||||||
name = "nixos-${config.system.nixosVersion}";
|
name = "nixos-${config.system.nixosVersion}";
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
buildCommand = systemBuilder;
|
buildCommand = systemBuilder;
|
||||||
|
|
||||||
|
inherit (pkgs) systemd;
|
||||||
|
|
||||||
inherit children;
|
inherit children;
|
||||||
kernelParams =
|
kernelParams =
|
||||||
config.boot.kernelParams ++ config.boot.extraKernelParams;
|
config.boot.kernelParams ++ config.boot.extraKernelParams;
|
||||||
@ -164,17 +167,10 @@ let
|
|||||||
# to the activation script.
|
# to the activation script.
|
||||||
noRestartIfChanged = attrValues (mapAttrs (n: v: if v.restartIfChanged then [] else ["[${v.name}]=1"]) config.jobs);
|
noRestartIfChanged = attrValues (mapAttrs (n: v: if v.restartIfChanged then [] else ["[${v.name}]=1"]) config.jobs);
|
||||||
|
|
||||||
# Most of these are needed by grub-install.
|
|
||||||
path =
|
|
||||||
[ pkgs.coreutils
|
|
||||||
pkgs.gnused
|
|
||||||
pkgs.gnugrep
|
|
||||||
pkgs.findutils
|
|
||||||
pkgs.diffutils
|
|
||||||
pkgs.systemd
|
|
||||||
];
|
|
||||||
|
|
||||||
configurationName = config.boot.loader.grub.configurationName;
|
configurationName = config.boot.loader.grub.configurationName;
|
||||||
|
|
||||||
|
# Needed by switch-to-configuration.
|
||||||
|
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user