Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/lock-kernel-modules: use udevadm settle #138001

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions nixos/modules/security/lock-kernel-modules.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, ... }:
{ config, pkgs, lib, ... }:

with lib;

Expand All @@ -13,7 +13,7 @@ with lib;
default = false;
description = ''
Disable kernel module loading once the system is fully initialised.
Module loading is disabled until the next reboot. Problems caused
Module loading is disabled until the next reboot. Problems caused
by delayed module loading can be fixed by adding the module(s) in
question to <option>boot.kernelModules</option>.
'';
Expand All @@ -29,20 +29,30 @@ with lib;
else [ x.fsType ]
else []) config.system.build.fileSystems;

systemd.services.disable-kernel-module-loading = rec {
systemd.services.disable-kernel-module-loading = {
description = "Disable kernel module loading";

wants = [ "systemd-udevd.service" ];
wantedBy = [ config.systemd.defaultUnit ];

after = [ "systemd-udev-settle.service" "firewall.service" "systemd-modules-load.service" ] ++ wantedBy;
before = [ config.systemd.defaultUnit ];
after =
[ "firewall.service"
"systemd-modules-load.service"
];

unitConfig.ConditionPathIsReadWrite = "/proc/sys/kernel";

serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "/bin/sh -c 'echo -n 1 >/proc/sys/kernel/modules_disabled'";
};
serviceConfig =
{ Type = "oneshot";
RemainAfterExit = true;
TimeoutSec = 180;
};

script = ''
${pkgs.udev}/bin/udevadm settle
echo -n 1 >/proc/sys/kernel/modules_disabled
'';
};
};
}