From 573877c1ac82c9a58181c7f8b777b86f599153e5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 17 Mar 2012 17:26:17 +0000 Subject: [PATCH] * Use boot.kernelModules everywhere instead of explicit calls to modprobe. * Move the implementation of boot.kernelModules from the udev job to the activation script. This prevents races with the udev job. * Drop references to the "capability" kernel module, which no longer exists. svn path=/nixos/trunk/; revision=33208 --- modules/config/power-management.nix | 2 +- modules/hardware/cpu/intel-microcode.nix | 23 +++++++++-------------- modules/services/audio/alsa.nix | 11 ++--------- modules/services/hardware/udev.nix | 11 +---------- modules/services/misc/autofs.nix | 15 +++------------ modules/services/networking/ddclient.nix | 9 ++------- modules/services/networking/dhclient.nix | 9 +++------ modules/services/networking/ntpd.nix | 8 +------- modules/services/networking/portmap.nix | 2 +- modules/services/networking/privoxy.nix | 8 ++------ modules/services/printing/cupsd.nix | 2 -- modules/services/security/tor.nix | 6 +----- modules/services/system/cgroups.nix | 8 ++++---- modules/services/system/uptimed.nix | 9 +-------- modules/system/boot/modprobe.nix | 5 +++++ 15 files changed, 36 insertions(+), 92 deletions(-) diff --git a/modules/config/power-management.nix b/modules/config/power-management.nix index ad54a5fa7484..c8e1a62749b8 100644 --- a/modules/config/power-management.nix +++ b/modules/config/power-management.nix @@ -88,7 +88,7 @@ in boot.kernelModules = [ "acpi_cpufreq" "cpufreq_performance" "cpufreq_powersave" "cpufreq_ondemand" - "p4_clockmod" "cpufreq_conservative" + "cpufreq_conservative" ]; powerManagement.cpuFreqGovernor = mkDefault "ondemand"; diff --git a/modules/hardware/cpu/intel-microcode.nix b/modules/hardware/cpu/intel-microcode.nix index 894676194a53..b8e97b4ca4ac 100644 --- a/modules/hardware/cpu/intel-microcode.nix +++ b/modules/hardware/cpu/intel-microcode.nix @@ -1,4 +1,6 @@ -{pkgs, config, ...}: +{ config, pkgs, ... }: + +with pkgs.lib; { @@ -6,11 +8,11 @@ options = { - hardware.cpu.intel.updateMicrocode = pkgs.lib.mkOption { + hardware.cpu.intel.updateMicrocode = mkOption { default = false; - type = pkgs.lib.types.bool; + type = types.bool; description = '' - Update the CPU microcode for intel processors. + Update the CPU microcode for Intel processors. ''; }; @@ -19,16 +21,9 @@ ###### implementation - config = pkgs.lib.mkIf config.hardware.cpu.intel.updateMicrocode { - hardware.firmware = [pkgs.microcodeIntel]; - jobs.microcode = { - name = "microcode"; - description = "load microcode"; - startOn = "started udev"; - exec = "modprobe microcode"; - path = [config.system.sbin.modprobe]; - task = true; - }; + config = mkIf config.hardware.cpu.intel.updateMicrocode { + hardware.firmware = [ pkgs.microcodeIntel ]; + boot.kernelModules = [ "microcode" ]; }; } diff --git a/modules/services/audio/alsa.nix b/modules/services/audio/alsa.nix index 7f313c36cb90..7d4cc100fd21 100644 --- a/modules/services/audio/alsa.nix +++ b/modules/services/audio/alsa.nix @@ -45,6 +45,8 @@ in environment.systemPackages = [ alsaUtils ]; + boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss"; + jobs.alsa = { startOn = "stopped udevtrigger"; @@ -52,15 +54,6 @@ in '' mkdir -m 0755 -p $(dirname ${soundState}) - # Load some additional modules. - ${optionalString config.sound.enableOSSEmulation - '' - for mod in snd_pcm_oss; do - ${config.system.sbin.modprobe}/sbin/modprobe $mod || true - done - '' - } - # Restore the sound state. ${alsaUtils}/sbin/alsactl -f ${soundState} restore || true ''; diff --git a/modules/services/hardware/udev.nix b/modules/services/hardware/udev.nix index 9a38c501411f..c4c348c7c25c 100644 --- a/modules/services/hardware/udev.nix +++ b/modules/services/hardware/udev.nix @@ -14,8 +14,6 @@ let destination = "/etc/udev/rules.d/10-local.rules"; }; - modprobe = config.system.sbin.modprobe; - nixosRules = '' # Miscellaneous devices. @@ -54,7 +52,7 @@ let # Fix some paths in the standard udev rules. Hacky. for i in $out/*.rules; do substituteInPlace $i \ - --replace \"/sbin/modprobe \"${modprobe}/sbin/modprobe \ + --replace \"/sbin/modprobe \"${config.system.sbin.modprobe}/sbin/modprobe \ --replace \"/sbin/mdadm \"${pkgs.mdadm}/sbin/mdadm \ --replace \"/sbin/blkid \"${pkgs.utillinux}/sbin/blkid \ --replace \"/bin/mount \"${pkgs.utillinux}/bin/mount @@ -232,13 +230,6 @@ in mkdir -p /var/lib/udev/rules.d touch /var/lib/udev/rules.d/70-persistent-cd.rules /var/lib/udev/rules.d/70-persistent-net.rules - # Do the loading of additional stage 2 kernel modules. - # Maybe this isn't the best place... - for i in ${toString config.boot.kernelModules}; do - echo "Loading kernel module $i..." - ${modprobe}/sbin/modprobe $i || true - done - mkdir -p /dev/.udev # !!! bug in udev? ''; diff --git a/modules/services/misc/autofs.nix b/modules/services/misc/autofs.nix index e55c213ed21a..50491c556e8a 100644 --- a/modules/services/misc/autofs.nix +++ b/modules/services/misc/autofs.nix @@ -50,11 +50,6 @@ in "; }; - kernelModules = mkOption { - default = ["fuse"]; - description="kernel modules to load"; - }; - timeout = mkOption { default = 600; description = "Set the global minimum timeout, in seconds, until directories are unmounted"; @@ -81,19 +76,15 @@ in source = pkgs.writeText "auto.master" cfg.autoMaster; }; + boot.kernelModules = [ "autofs4" ]; + jobs.autofs = { description = "Filesystem automounter"; startOn = "started network-interfaces"; stopOn = "stopping network-interfaces"; - environment = - { PATH = "${pkgs.nfsUtils}/sbin:${config.system.sbin.modprobe}/sbin:${pkgs.sshfsFuse}/sbin:${pkgs.sshfsFuse}/bin:$PATH"; - }; - - preStart = - pkgs.lib.concatMapStrings (module : "modprobe ${module} || true\n") - (["autofs4"] ++ cfg.kernelModules); + path = [ pkgs.nfsUtils pkgs.sshfsFuse ]; preStop = '' diff --git a/modules/services/networking/ddclient.nix b/modules/services/networking/ddclient.nix index a0523919ef45..62709a040a1f 100644 --- a/modules/services/networking/ddclient.nix +++ b/modules/services/networking/ddclient.nix @@ -10,8 +10,6 @@ let ddclientUser = "ddclient"; - modprobe = config.system.sbin.modprobe; - ddclientFlags = "-foreground -file ${ddclientCfg}"; ddclientCfg = pkgs.writeText "ddclient.conf" '' @@ -89,8 +87,7 @@ in web = mkOption { default = "web, web=checkip.dyndns.com/, web-skip='IP Address'" ; - description = '' - ''; + description = ""; }; }; @@ -101,6 +98,7 @@ in ###### implementation config = mkIf config.services.ddclient.enable { + environment.systemPackages = [ ddclient ]; users.extraUsers = singleton @@ -119,9 +117,6 @@ in '' mkdir -m 0755 -p ${stateDir} chown ${ddclientUser} ${stateDir} - - # Needed to run ddclient as an unprivileged user. - ${modprobe}/sbin/modprobe capability || true ''; exec = "${ddclient}/bin/ddclient ${ddclientFlags}"; diff --git a/modules/services/networking/dhclient.nix b/modules/services/networking/dhclient.nix index 2bc0b333a6fc..1e3434438997 100644 --- a/modules/services/networking/dhclient.nix +++ b/modules/services/networking/dhclient.nix @@ -44,18 +44,15 @@ in config = mkIf config.networking.useDHCP { + # dhclient barfs if /proc/net/if_inet6 doesn't exist. + boot.kernelModules = [ "ipv6" ]; + jobs.dhclient = { startOn = "started network-interfaces"; stopOn = "stopping network-interfaces"; path = [ dhcp ]; - preStart = - '' - # dhclient barfs if /proc/net/if_inet6 doesn't exist. - ${config.system.sbin.modprobe}/sbin/modprobe ipv6 || true - ''; - script = '' # Determine the interface on which to start dhclient. diff --git a/modules/services/networking/ntpd.nix b/modules/services/networking/ntpd.nix index d44aedc6e156..7d1db8df0663 100644 --- a/modules/services/networking/ntpd.nix +++ b/modules/services/networking/ntpd.nix @@ -10,16 +10,12 @@ let ntpUser = "ntp"; - servers = config.services.ntp.servers; - - modprobe = config.system.sbin.modprobe; - configFile = pkgs.writeText "ntp.conf" '' # Keep the drift file in ${stateDir}/ntp.drift. However, since we # chroot to ${stateDir}, we have to specify it as /ntp.drift. driftfile /ntp.drift - ${toString (map (server: "server " + server + " iburst\n") servers)} + ${toString (map (server: "server " + server + " iburst\n") config.services.ntp.servers)} ''; ntpFlags = "-c ${configFile} -u ${ntpUser}:nogroup -i ${stateDir}"; @@ -69,8 +65,6 @@ in home = stateDir; }; - boot.kernelModules = [ "capability" ]; - jobs.ntpd = { description = "NTP daemon"; diff --git a/modules/services/networking/portmap.nix b/modules/services/networking/portmap.nix index cde4bb6a9553..82712a866922 100644 --- a/modules/services/networking/portmap.nix +++ b/modules/services/networking/portmap.nix @@ -68,7 +68,7 @@ in jobs.portmap = { description = "ONC RPC portmap"; - startOn = "started network-interfaces"; + startOn = "startup"; stopOn = "never"; daemonType = "fork"; # needed during shutdown diff --git a/modules/services/networking/privoxy.nix b/modules/services/networking/privoxy.nix index 443328f67b0b..89c40c531579 100644 --- a/modules/services/networking/privoxy.nix +++ b/modules/services/networking/privoxy.nix @@ -10,8 +10,6 @@ let privoxyUser = "privoxy"; - modprobe = config.system.sbin.modprobe; - privoxyFlags = "--no-daemon --user ${privoxyUser} ${privoxyCfg}"; privoxyCfg = pkgs.writeText "privoxy.conf" '' @@ -68,12 +66,13 @@ in ###### implementation config = mkIf config.services.privoxy.enable { + environment.systemPackages = [ privoxy ]; users.extraUsers = singleton { name = privoxyUser; uid = config.ids.uids.privoxy; - description = "privoxy daemon user"; + description = "Privoxy daemon user"; home = stateDir; }; @@ -86,9 +85,6 @@ in '' mkdir -m 0755 -p ${stateDir} chown ${privoxyUser} ${stateDir} - - # Needed to run privoxy as an unprivileged user. - ${modprobe}/sbin/modprobe capability || true ''; exec = "${privoxy}/sbin/privoxy ${privoxyFlags}"; diff --git a/modules/services/printing/cupsd.nix b/modules/services/printing/cupsd.nix index 848537b9f0d6..50556a352bae 100644 --- a/modules/services/printing/cupsd.nix +++ b/modules/services/printing/cupsd.nix @@ -8,8 +8,6 @@ let logDir = "/var/log/cups"; - modprobe = config.system.sbin.modprobe; - cfg = config.services.printing; additionalBackends = pkgs.stdenv.mkDerivation { diff --git a/modules/services/security/tor.nix b/modules/services/security/tor.nix index 6582ba702537..6df4590b85bb 100644 --- a/modules/services/security/tor.nix +++ b/modules/services/security/tor.nix @@ -9,14 +9,13 @@ let stateDir = "/var/lib/tor"; privoxyDir = stateDir+"/privoxy"; - modprobe = config.system.sbin.modprobe; - cfg = config.services.tor; torUser = "tor"; opt = name: value: if value != "" then "${name} ${value}" else ""; optint = name: value: if value != 0 then "${name} ${toString value}" else ""; + in { @@ -251,9 +250,6 @@ in preStart = '' mkdir -m 0755 -p ${privoxyDir} chown ${torUser} ${privoxyDir} - - # Needed to run privoxy as an unprivileged user? - ${modprobe}/sbin/modprobe capability || true ''; exec = "${privoxy}/sbin/privoxy --no-daemon --user ${torUser} ${pkgs.writeText "torPrivoxy.conf" cfg.client.privoxy.config}"; }; }; diff --git a/modules/services/system/cgroups.nix b/modules/services/system/cgroups.nix index 08482643c3fa..199d12268ceb 100644 --- a/modules/services/system/cgroups.nix +++ b/modules/services/system/cgroups.nix @@ -96,6 +96,10 @@ in } ]; + # The daemon requires the userspace<->kernelspace netlink + # connector. + boot.kernelModules = [ "cn" ]; + jobs.cgroups = { startOn = "startup"; @@ -105,10 +109,6 @@ in preStart = '' - # The daemon requires the userspace<->kernelspace netlink - # connector. - ${config.system.sbin.modprobe}/sbin/modprobe cn || true - cgclear || true # Mount the cgroup hierarchies. Note: we refer to the diff --git a/modules/services/system/uptimed.nix b/modules/services/system/uptimed.nix index 51874cfc0e58..61eecd5c9ba8 100644 --- a/modules/services/system/uptimed.nix +++ b/modules/services/system/uptimed.nix @@ -10,10 +10,6 @@ let uptimedUser = "uptimed"; - modprobe = config.system.sbin.modprobe; - - uptimedFlags = ""; - in { @@ -59,15 +55,12 @@ in mkdir -m 0755 -p ${stateDir} chown ${uptimedUser} ${stateDir} - # Needed to run uptimed as an unprivileged user. - ${modprobe}/sbin/modprobe capability || true - if ! test -f ${stateDir}/bootid ; then ${uptimed}/sbin/uptimed -b fi ''; - exec = "${uptimed}/sbin/uptimed ${uptimedFlags}"; + exec = "${uptimed}/sbin/uptimed"; }; }; diff --git a/modules/system/boot/modprobe.nix b/modules/system/boot/modprobe.nix index ef3ed3bed94a..4dd866a43952 100644 --- a/modules/system/boot/modprobe.nix +++ b/modules/system/boot/modprobe.nix @@ -100,6 +100,11 @@ with pkgs.lib; # We need this when the kernel (or some module) auto-loads a # module. echo ${config.system.sbin.modprobe}/sbin/modprobe > /proc/sys/kernel/modprobe + + # Do the loading of additional stage 2 kernel modules. + for i in ${toString config.boot.kernelModules}; do + ${config.system.sbin.modprobe}/sbin/modprobe $i || true + done ''; };