1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11
12 # A list of attrnames is coerced into an attrset of bools by
13 # setting the values to true.
14 attrNamesToTrue = types.coercedTo (types.listOf types.str) (
15 enabledList: lib.genAttrs enabledList (_attrName: true)
16 ) (types.attrsOf types.bool);
17
18in
19
20{
21
22 ###### interface
23
24 options = {
25 boot.modprobeConfig.enable =
26 mkEnableOption "modprobe config. This is useful for systems like containers which do not require a kernel"
27 // {
28 default = true;
29 };
30
31 boot.modprobeConfig.useUbuntuModuleBlacklist =
32 mkEnableOption "Ubuntu distro's module blacklist"
33 // {
34 default = true;
35 };
36
37 boot.blacklistedKernelModules = mkOption {
38 type = attrNamesToTrue;
39 default = { };
40 example = [
41 "cirrusfb"
42 "i2c_piix4"
43 ];
44 description = ''
45 Set of names of kernel modules that should not be loaded
46 automatically by the hardware probing code. This can either be
47 a list of modules or an attrset. In an attrset, names that are
48 set to `true` represent modules that will be blacklisted.
49 '';
50 apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
51 };
52
53 boot.extraModprobeConfig = mkOption {
54 default = "";
55 example = ''
56 options parport_pc io=0x378 irq=7 dma=1
57 '';
58 description = ''
59 Any additional configuration to be appended to the generated
60 {file}`modprobe.conf`. This is typically used to
61 specify module options. See
62 {manpage}`modprobe.d(5)` for details.
63 '';
64 type = types.lines;
65 };
66
67 };
68
69 ###### implementation
70
71 config = mkIf config.boot.modprobeConfig.enable {
72
73 environment.etc."modprobe.d/ubuntu.conf" =
74 mkIf config.boot.modprobeConfig.useUbuntuModuleBlacklist
75 {
76 source = "${pkgs.kmod-blacklist-ubuntu}/modprobe.conf";
77 };
78
79 environment.etc."modprobe.d/nixos.conf".text = ''
80 ${flip concatMapStrings config.boot.blacklistedKernelModules (name: ''
81 blacklist ${name}
82 '')}
83 ${config.boot.extraModprobeConfig}
84 '';
85 environment.etc."modprobe.d/debian.conf".source = pkgs.kmod-debian-aliases;
86
87 environment.etc."modprobe.d/systemd.conf".source =
88 "${config.systemd.package}/lib/modprobe.d/systemd.conf";
89
90 environment.systemPackages = [ pkgs.kmod ];
91
92 system.activationScripts.modprobe = stringAfter [ "specialfs" ] ''
93 # Allow the kernel to find our wrapped modprobe (which searches
94 # in the right location in the Nix store for kernel modules).
95 # We need this when the kernel (or some module) auto-loads a
96 # module.
97 echo ${pkgs.kmod}/bin/modprobe > /proc/sys/kernel/modprobe
98 '';
99
100 };
101
102}