Merge pull request #168774 from helsinki-systems/feat/systemd-shutdown

nixos/systemd: Properly shut down the system
This commit is contained in:
Florian Klink 2022-04-18 09:52:07 +02:00 committed by GitHub
commit 52e346d6dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 0 deletions

View File

@ -1238,6 +1238,14 @@
<literal>systemd.nspawn.&lt;name&gt;.execConfig.PrivateUsers = false</literal>
</para>
</listitem>
<listitem>
<para>
<literal>systemd-shutdown</literal> is now properly linked on
shutdown to unmount all filesystems and device mapper devices
cleanly. This can be disabled using
<literal>boot.systemd.shutdown.enable</literal>.
</para>
</listitem>
<listitem>
<para>
The Tor SOCKS proxy is now actually disabled if

View File

@ -492,6 +492,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- `systemd-nspawn@.service` settings have been reverted to the default systemd behaviour. User namespaces are now activated by default. If you want to keep running nspawn containers without user namespaces you need to set `systemd.nspawn.<name>.execConfig.PrivateUsers = false`
- `systemd-shutdown` is now properly linked on shutdown to unmount all filesystems and device mapper devices cleanly. This can be disabled using `boot.systemd.shutdown.enable`.
- The Tor SOCKS proxy is now actually disabled if `services.tor.client.enable` is set to `false` (the default). If you are using this functionality but didn't change the setting or set it to `false`, you now need to set it to `true`.
- The terraform 0.12 compatibility has been removed and the `terraform.withPlugins` and `terraform-providers.mkProvider` implementations simplified. Providers now need to be stored under

View File

@ -1183,6 +1183,7 @@
./system/boot/systemd/journald.nix
./system/boot/systemd/logind.nix
./system/boot/systemd/nspawn.nix
./system/boot/systemd/shutdown.nix
./system/boot/systemd/tmpfiles.nix
./system/boot/systemd/user.nix
./system/boot/systemd/initrd.nix

View File

@ -0,0 +1,32 @@
{ config, lib, ... }: let
cfg = config.boot.systemd.shutdown;
in {
options.boot.systemd.shutdown = {
enable = lib.mkEnableOption "pivoting back to an initramfs for shutdown" // { default = true; };
};
config = lib.mkIf cfg.enable {
systemd.services.generate-shutdown-ramfs = {
description = "Generate shutdown ramfs";
before = [ "shutdown.target" ];
unitConfig = {
DefaultDependencies = false;
ConditionFileIsExecutable = [
"!/run/initramfs/shutdown"
"/run/current-system/systemd/lib/systemd/systemd-shutdown"
];
};
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /run/initramfs
if ! mountpoint -q /run/initramfs; then
mount -t tmpfs tmpfs /run/initramfs
fi
cp /run/current-system/systemd/lib/systemd/systemd-shutdown /run/initramfs/shutdown
'';
};
};
}

View File

@ -524,6 +524,7 @@ in
systemd-confinement = handleTest ./systemd-confinement.nix {};
systemd-cryptenroll = handleTest ./systemd-cryptenroll.nix {};
systemd-escaping = handleTest ./systemd-escaping.nix {};
systemd-initrd-shutdown = handleTest ./systemd-shutdown.nix { systemdStage1 = true; };
systemd-initrd-simple = handleTest ./systemd-initrd-simple.nix {};
systemd-initrd-swraid = handleTest ./systemd-initrd-swraid.nix {};
systemd-journal = handleTest ./systemd-journal.nix {};
@ -534,6 +535,7 @@ in
systemd-networkd-ipv6-prefix-delegation = handleTest ./systemd-networkd-ipv6-prefix-delegation.nix {};
systemd-networkd-vrf = handleTest ./systemd-networkd-vrf.nix {};
systemd-nspawn = handleTest ./systemd-nspawn.nix {};
systemd-shutdown = handleTest ./systemd-shutdown.nix {};
systemd-timesyncd = handleTest ./systemd-timesyncd.nix {};
systemd-misc = handleTest ./systemd-misc.nix {};
taskserver = handleTest ./taskserver.nix {};

View File

@ -0,0 +1,21 @@
import ./make-test-python.nix ({ pkgs, systemdStage1 ? false, ...} : {
name = "systemd-shutdown";
meta = with pkgs.lib.maintainers; {
maintainers = [ das_j ];
};
nodes.machine = {
imports = [ ../modules/profiles/minimal.nix ];
boot.initrd.systemd.enable = systemdStage1;
};
testScript = ''
machine.wait_for_unit("multi-user.target")
# .shutdown() would wait for the machine to power off
machine.succeed("systemctl poweroff")
# Message printed by systemd-shutdown
machine.wait_for_console_text("All filesystems, swaps, loop devices, MD devices and DM devices detached.")
# Don't try to sync filesystems
machine.booted = False
'';
})