From e9c71d971f7ec6379284ac58b3ea236996fb7b39 Mon Sep 17 00:00:00 2001 From: nikstur Date: Tue, 29 Jul 2025 13:27:28 +0200 Subject: [PATCH] nixos/filesystem: remove mount-pstore Ever since fb49d81b2541bd06fbaef6f516906381e7356947 we set CONFIG_PSTORE=y in the config because we set CONIFG_ACPI_APEI=y in the kernel. This means we always have pstore built right into the kernel. systemd thus always mounts `/sys/fs/pstore` which makes our custom unit superfluous and redudant. --- nixos/modules/tasks/filesystems.nix | 39 ----------------------------- nixos/tests/all-tests.nix | 1 + nixos/tests/systemd-pstore.nix | 14 +++++++++++ 3 files changed, 15 insertions(+), 39 deletions(-) create mode 100644 nixos/tests/systemd-pstore.nix diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index 0cf83ca62d44..5e52591a560b 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -509,45 +509,6 @@ in ]; }; - systemd.services = { - # Mount /sys/fs/pstore for evacuating panic logs and crashdumps from persistent storage onto the disk using systemd-pstore. - # This cannot be done with the other special filesystems because the pstore module (which creates the mount point) is not loaded then. - "mount-pstore" = { - serviceConfig = { - Type = "oneshot"; - # skip on kernels without the pstore module - ExecCondition = "${pkgs.kmod}/bin/modprobe -b pstore"; - ExecStart = pkgs.writeShellScript "mount-pstore.sh" '' - set -eu - # if the pstore module is builtin it will have mounted the persistent store automatically. it may also be already mounted for other reasons. - ${pkgs.util-linux}/bin/mountpoint -q /sys/fs/pstore || ${pkgs.util-linux}/bin/mount -t pstore -o nosuid,noexec,nodev pstore /sys/fs/pstore - # wait up to 1.5 seconds for the backend to be registered and the files to appear. a systemd path unit cannot detect this happening; and succeeding after a restart would not start dependent units. - TRIES=15 - while [ "$(cat /sys/module/pstore/parameters/backend)" = "(null)" ]; do - if (( $TRIES )); then - sleep 0.1 - TRIES=$((TRIES-1)) - else - echo "Persistent Storage backend was not registered in time." >&2 - break - fi - done - ''; - RemainAfterExit = true; - }; - unitConfig = { - ConditionVirtualization = "!container"; - DefaultDependencies = false; # needed to prevent a cycle - }; - before = [ - "systemd-pstore.service" - "shutdown.target" - ]; - conflicts = [ "shutdown.target" ]; - wantedBy = [ "systemd-pstore.service" ]; - }; - }; - systemd.tmpfiles.rules = [ "d /run/keys 0750 root ${toString config.ids.gids.keys}" "z /run/keys 0750 root ${toString config.ids.gids.keys}" diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a2dcd4c7ffd7..567d438ef897 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1437,6 +1437,7 @@ in systemd-nspawn-configfile = runTest ./systemd-nspawn-configfile.nix; systemd-oomd = runTest ./systemd-oomd.nix; systemd-portabled = runTest ./systemd-portabled.nix; + systemd-pstore = runTest ./systemd-pstore.nix; systemd-repart = handleTest ./systemd-repart.nix { }; systemd-resolved = runTest ./systemd-resolved.nix; systemd-ssh-proxy = runTest ./systemd-ssh-proxy.nix; diff --git a/nixos/tests/systemd-pstore.nix b/nixos/tests/systemd-pstore.nix new file mode 100644 index 000000000000..7eeb7209e4a4 --- /dev/null +++ b/nixos/tests/systemd-pstore.nix @@ -0,0 +1,14 @@ +{ + name = "systemd-pstore"; + + nodes.machine = { }; + + testScript = '' + with subtest("pstore API fs is mounted"): + machine.succeed("stat /sys/fs/pstore") + + with subtest("systemd-pstore.service doesn't run because nothing crashed"): + output = machine.execute("systemctl status systemd-pstore.service", check_return=False)[1] + t.assertIn("condition unmet", output) + ''; +}