Get rid of the last uses of mkAlways

mkAlways is an insane function, mkMerge is much saner.
This commit is contained in:
Eelco Dolstra 2012-11-30 15:07:39 +01:00
parent 9eb81d2578
commit 7435db4f89
3 changed files with 96 additions and 106 deletions

View File

@ -150,7 +150,7 @@ $ nixos-rebuild switch -I <replaceable>/my/sources</replaceable>
definitions. This conditional values can be distinguished in two definitions. This conditional values can be distinguished in two
categories. The condition which are local to the current configuration categories. The condition which are local to the current configuration
and conditions which are dependent on others configurations. Local and conditions which are dependent on others configurations. Local
properties are <varname>mkIf</varname>, <varname>mkAlways</varname> properties are <varname>mkIf</varname>
and <varname>mkAssert</varname>. Global properties and <varname>mkAssert</varname>. Global properties
are <varname>mkOverride</varname>, <varname>mkDefault</varname> are <varname>mkOverride</varname>, <varname>mkDefault</varname>
and <varname>mkOrder</varname>.</para> and <varname>mkOrder</varname>.</para>
@ -158,12 +158,7 @@ $ nixos-rebuild switch -I <replaceable>/my/sources</replaceable>
<para><varname>mkIf</varname> is used to remove the option definitions which <para><varname>mkIf</varname> is used to remove the option definitions which
are below it if the condition is evaluated to are below it if the condition is evaluated to
false. <varname>mkAssert</varname> expects the condition to be evaluated false. <varname>mkAssert</varname> expects the condition to be evaluated
to true otherwise it raises an error message. <varname>mkAlways</varname> to true otherwise it raises an error message.</para>
is used to ignore all the <varname>mkIf</varname>
and <varname>mkAssert</varname> which have been made
previously. <varname>mkAlways</varname> and <varname>mkAssert</varname>
are often used together to set an option value and to ensure that it has
not been masked by another one.</para>
<para><varname>mkOverride</varname> is used to mask previous definitions if <para><varname>mkOverride</varname> is used to mask previous definitions if
the current value has a lower mask number. The mask value is 100 (default) the current value has a lower mask number. The mask value is 100 (default)
@ -223,14 +218,6 @@ let
locatedb = "/var/cache/locatedb"; locatedb = "/var/cache/locatedb";
logfile = "/var/log/updatedb"; logfile = "/var/log/updatedb";
cmd =''root updatedb --localuser=nobody --output=${locatedb} > ${logfile}''; cmd =''root updatedb --localuser=nobody --output=${locatedb} > ${logfile}'';
mkCheck = x:
mkIf cfg.enable (
mkAssert config.services.cron.enable ''
The cron daemon is not enabled, required by services.locate.enable.
''
x
)
in in
{ {
@ -260,9 +247,9 @@ in
}; };
}; };
config = mkCheck { config = mkIf cfg.enable {
services.cron = { services.cron = {
enable = mkAlways cfg.enable; enable = true;
systemCronJobs = "${cfg.period} root ${cmd}"; systemCronJobs = "${cfg.period} root ${cmd}";
}; };
}; };

View File

@ -28,64 +28,65 @@ let cfg = config.hardware.pulseaudio; in
}; };
config = mkIf cfg.enable { config = mkMerge
[ # Create pulse/client.conf even if PulseAudio is disabled so
# that we can disable the autospawn feature in programs that
# are built with PulseAudio support (like KDE).
{ environment.etc = singleton
{ target = "pulse/client.conf";
source = pkgs.writeText "client.conf"
''
autospawn=${if cfg.enable then "yes" else "no"}
${optionalString cfg.enable ''
daemon-binary=${cfg.package}/bin/pulseaudio
''}
'';
};
}
environment.systemPackages = (mkIf cfg.enable {
[ cfg.package ];
environment.etc = mkAlways ( environment.systemPackages = [ cfg.package ];
[ # Create pulse/client.conf even if PulseAudio is disabled so
# that we can disable the autospawn feature in programs that
# are built with PulseAudio support (like KDE).
{ target = "pulse/client.conf";
source = pkgs.writeText "client.conf"
''
autospawn=${if cfg.enable then "yes" else "no"}
${optionalString cfg.enable ''
daemon-binary=${cfg.package}/bin/pulseaudio
''}
'';
}
] ++ optionals cfg.enable environment.etc =
[ # Write an /etc/asound.conf that causes all ALSA applications to [ # Write an /etc/asound.conf that causes all ALSA applications to
# be re-routed to the PulseAudio server through ALSA's Pulse # be re-routed to the PulseAudio server through ALSA's Pulse
# plugin. # plugin.
{ target = "asound.conf"; { target = "asound.conf";
source = pkgs.writeText "asound.conf" source = pkgs.writeText "asound.conf"
'' ''
pcm_type.pulse { pcm_type.pulse {
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so
} }
pcm.!default { pcm.!default {
type pulse type pulse
hint.description "Default Audio Device (via PulseAudio)" hint.description "Default Audio Device (via PulseAudio)"
} }
ctl_type.pulse { ctl_type.pulse {
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so
} }
ctl.!default { ctl.!default {
type pulse type pulse
} }
''; '';
} }
{ target = "pulse/default.pa"; { target = "pulse/default.pa";
source = "${cfg.package}/etc/pulse/default.pa"; source = "${cfg.package}/etc/pulse/default.pa";
} }
{ target = "pulse/system.pa"; { target = "pulse/system.pa";
source = "${cfg.package}/etc/pulse/system.pa"; source = "${cfg.package}/etc/pulse/system.pa";
} }
];
]); # Allow PulseAudio to get realtime priority using rtkit.
security.rtkit.enable = true;
# Allow PulseAudio to get realtime priority using rtkit. })
security.rtkit.enable = true; ];
};
} }

View File

@ -154,23 +154,23 @@ in
defaultShare = { defaultShare = {
enable = mkOption { enable = mkOption {
description = "Whether to share /home/smbd as 'default'."; description = "Whether to share /home/smbd as 'default'.";
default = false; default = false;
}; };
writeable = mkOption { writeable = mkOption {
description = "Whether to allow write access to default share."; description = "Whether to allow write access to default share.";
default = false; default = false;
}; };
guest = mkOption { guest = mkOption {
description = "Whether to allow guest access to default share."; description = "Whether to allow guest access to default share.";
default = true; default = true;
}; };
}; };
securityType = mkOption { securityType = mkOption {
description = "Samba security type"; description = "Samba security type";
default = "user"; default = "user";
example = "share"; example = "share";
}; };
}; };
@ -180,43 +180,45 @@ in
###### implementation ###### implementation
config = mkIf config.services.samba.enable { config = mkMerge
[ { # Always provide a smb.conf to shut up programs like smbclient and smbspool.
environment.etc = singleton
{ source =
if cfg.enable then configFile
else pkgs.writeText "smb-dummy.conf" "# Samba is disabled.";
target = "samba/smb.conf";
};
}
users.extraUsers = singleton (mkIf config.services.samba.enable {
{ name = user; users.extraUsers = singleton
description = "Samba service user"; { name = user;
group = group; description = "Samba service user";
}; group = group;
};
users.extraGroups = singleton users.extraGroups = singleton
{ name = group; { name = group;
}; };
# always provide a smb.conf to shut up programs like smbclient and smbspool.
environment.etc = mkAlways (singleton
{ source =
if cfg.enable then configFile
else pkgs.writeText "smb-dummy.conf" "# Samba is disabled.";
target = "samba/smb.conf";
});
# Dummy job to start the real Samba daemons (nmbd, smbd, winbindd). # Dummy job to start the real Samba daemons (nmbd, smbd, winbindd).
jobs.sambaControl = jobs.sambaControl =
{ name = "samba"; { name = "samba";
description = "Samba server"; description = "Samba server";
startOn = "started network-interfaces"; startOn = "started network-interfaces";
stopOn = "stopping network-interfaces"; stopOn = "stopping network-interfaces";
preStart = setupScript; preStart = setupScript;
}; };
jobs.nmbd = daemonJob "nmbd" "-D"; jobs.nmbd = daemonJob "nmbd" "-D";
jobs.smbd = daemonJob "smbd" "-D"; jobs.smbd = daemonJob "smbd" "-D";
jobs.winbindd = daemonJob "winbindd" "-D"; jobs.winbindd = daemonJob "winbindd" "-D";
})
}; ];
} }