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