Skip to content

Commit 86089ea

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

1 file changed

Lines changed: 50 additions & 4 deletions

File tree

nix/modules/upstream/nixpkgs/default.nix

Lines changed: 50 additions & 4 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,27 @@
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
{
35-
boot = lib.mkOption {
36-
type = lib.types.raw;
50+
boot = {
51+
kernelModules = lib.mkOption {
52+
type = attrNamesToTrue;
53+
default = { };
54+
description = ''
55+
The set of kernel modules to be loaded in the second stage of
56+
the boot process.
57+
58+
${modulesTypeDesc}
59+
'';
60+
apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
61+
};
62+
63+
kernelPackages = lib.mkOption {
64+
type = lib.types.raw;
65+
default = {
66+
kernel.version = "stub";
67+
};
68+
description = "Stub kernel packages for compatibility; not actively used in system-manager.";
69+
};
3770
};
3871

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

0 commit comments

Comments
 (0)