Skip to content

Commit e0412d6

Browse files
committed
feat: add boot.kernel.sysctl and boot.kernelModules
1 parent e6ab588 commit e0412d6

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

nix/modules/upstream/nixpkgs/default.nix

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
{
22
nixosModulesPath,
33
lib,
4+
pkgs,
5+
config,
46
...
57
}:
8+
let
9+
modulesTypeDesc = ''
10+
This can either be a list of modules, or an attrset. In an
11+
attrset, names that are set to `true` represent modules that will
12+
be included. Note that setting these names to `false` does not
13+
prevent the module from being loaded.
14+
'';
15+
kernelModulesConf = pkgs.writeText "nixos.conf" ''
16+
${lib.concatStringsSep "\n" config.boot.kernelModules}
17+
'';
18+
attrNamesToTrue = lib.types.coercedTo (lib.types.listOf lib.types.str) (
19+
enabledList: lib.genAttrs enabledList (_attrName: true)
20+
) (lib.types.attrsOf lib.types.bool);
21+
in
622
{
723
imports = [
824
./firewall.nix
@@ -20,6 +36,7 @@
2036
"/misc/ids.nix"
2137
"/security/acme/"
2238
"/services/web-servers/nginx/"
39+
"/config/sysctl.nix"
2340
# nix settings
2441
"/config/nix.nix"
2542
"/services/system/userborn.nix"
@@ -29,11 +46,25 @@
2946
options =
3047
# We need to ignore a bunch of options that are used in NixOS modules but
3148
# that don't apply to system-manager configs.
32-
# TODO: can we print an informational message for things like kernel modules
33-
# to inform users that they need to be enabled in the host system?
3449
{
3550
boot = lib.mkOption {
36-
type = lib.types.raw;
51+
type = lib.types.submodule {
52+
freeformType = lib.types.attrsOf lib.types.raw;
53+
options = {
54+
kernelModules = lib.mkOption {
55+
type = attrNamesToTrue;
56+
default = { };
57+
description = ''
58+
The set of kernel modules to be loaded in the second stage of
59+
the boot process.
60+
61+
${modulesTypeDesc}
62+
'';
63+
apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
64+
};
65+
};
66+
};
67+
default = { };
3768
};
3869

3970
# nixos/modules/services/system/userborn.nix still depends on activation scripts
@@ -64,4 +95,17 @@
6495
};
6596
};
6697
};
98+
99+
config = {
100+
# Create /etc/modules-load.d/system-manager.conf, which is read by
101+
# systemd-modules-load.service to load required kernel modules.
102+
environment.etc = lib.mkIf (config.boot.kernelModules != { }) {
103+
"modules-load.d/system-manager.conf".source = kernelModulesConf;
104+
};
105+
106+
# config/sysctl.nix assumes it can freely configure systemd-sysctl.service.
107+
# However, in our case, the service is managed by the host system,
108+
# so we default to enable = false; to avoid unintended interference.
109+
systemd.services.systemd-sysctl.enable = lib.mkDefault false;
110+
};
67111
}

0 commit comments

Comments
 (0)