1{ config, lib, pkgs, ... }: 2 3with lib; 4 5{ 6 7 ###### interface 8 9 options = { 10 11 system.sbin.modprobe = mkOption { 12 internal = true; 13 default = pkgs.stdenv.mkDerivation { 14 name = "modprobe"; 15 buildCommand = '' 16 mkdir -p $out/bin 17 for i in ${pkgs.kmod}/sbin/*; do 18 name=$(basename $i) 19 echo "$text" > $out/bin/$name 20 echo 'exec '$i' "$@"' >> $out/bin/$name 21 chmod +x $out/bin/$name 22 done 23 ln -s bin $out/sbin 24 ''; 25 text = 26 '' 27 #! ${pkgs.stdenv.shell} 28 export MODULE_DIR=/run/current-system/kernel-modules/lib/modules 29 30 # Fall back to the kernel modules used at boot time if the 31 # modules in the current configuration don't match the 32 # running kernel. 33 if [ ! -d "$MODULE_DIR/$(${pkgs.coreutils}/bin/uname -r)" ]; then 34 MODULE_DIR=/run/booted-system/kernel-modules/lib/modules/ 35 fi 36 37 ''; 38 meta.priority = 4; 39 }; 40 description = '' 41 Wrapper around modprobe that sets the path to the modules 42 tree. 43 ''; 44 }; 45 46 boot.blacklistedKernelModules = mkOption { 47 type = types.listOf types.str; 48 default = []; 49 example = [ "cirrusfb" "i2c_piix4" ]; 50 description = '' 51 List of names of kernel modules that should not be loaded 52 automatically by the hardware probing code. 53 ''; 54 }; 55 56 boot.extraModprobeConfig = mkOption { 57 default = ""; 58 example = 59 '' 60 options parport_pc io=0x378 irq=7 dma=1 61 ''; 62 description = '' 63 Any additional configuration to be appended to the generated 64 <filename>modprobe.conf</filename>. This is typically used to 65 specify module options. See 66 <citerefentry><refentrytitle>modprobe.conf</refentrytitle> 67 <manvolnum>5</manvolnum></citerefentry> for details. 68 ''; 69 type = types.lines; 70 }; 71 72 }; 73 74 75 ###### implementation 76 77 config = mkIf (!config.boot.isContainer) { 78 79 environment.etc."modprobe.d/ubuntu.conf".source = "${pkgs.kmod-blacklist-ubuntu}/modprobe.conf"; 80 81 environment.etc."modprobe.d/nixos.conf".text = 82 '' 83 ${flip concatMapStrings config.boot.blacklistedKernelModules (name: '' 84 blacklist ${name} 85 '')} 86 ${config.boot.extraModprobeConfig} 87 ''; 88 environment.etc."modprobe.d/debian.conf".source = pkgs.kmod-debian-aliases; 89 90 environment.systemPackages = [ config.system.sbin.modprobe pkgs.kmod ]; 91 92 system.activationScripts.modprobe = 93 '' 94 # Allow the kernel to find our wrapped modprobe (which searches 95 # in the right location in the Nix store for kernel modules). 96 # We need this when the kernel (or some module) auto-loads a 97 # module. 98 echo ${config.system.sbin.modprobe}/sbin/modprobe > /proc/sys/kernel/modprobe 99 ''; 100 101 environment.sessionVariables.MODULE_DIR = "/run/current-system/kernel-modules/lib/modules"; 102 103 }; 104 105}