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