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
categories. The condition which are local to the current configuration
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
are <varname>mkOverride</varname>, <varname>mkDefault</varname>
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
are below it if the condition is evaluated to
false. <varname>mkAssert</varname> expects the condition to be evaluated
to true otherwise it raises an error message. <varname>mkAlways</varname>
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>
to true otherwise it raises an error message.</para>
<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)
@ -223,14 +218,6 @@ let
locatedb = "/var/cache/locatedb";
logfile = "/var/log/updatedb";
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
{
@ -260,9 +247,9 @@ in
};
};
config = mkCheck {
config = mkIf cfg.enable {
services.cron = {
enable = mkAlways cfg.enable;
enable = true;
systemCronJobs = "${cfg.period} root ${cmd}";
};
};

View File

@ -28,15 +28,11 @@ let cfg = config.hardware.pulseaudio; in
};
config = mkIf cfg.enable {
environment.systemPackages =
[ cfg.package ];
environment.etc = mkAlways (
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"
''
@ -45,9 +41,14 @@ let cfg = config.hardware.pulseaudio; in
daemon-binary=${cfg.package}/bin/pulseaudio
''}
'';
};
}
] ++ optionals cfg.enable
(mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
environment.etc =
[ # Write an /etc/asound.conf that causes all ALSA applications to
# be re-routed to the PulseAudio server through ALSA's Pulse
# plugin.
@ -80,12 +81,12 @@ let cfg = config.hardware.pulseaudio; in
{ target = "pulse/system.pa";
source = "${cfg.package}/etc/pulse/system.pa";
}
]);
];
# Allow PulseAudio to get realtime priority using rtkit.
security.rtkit.enable = true;
};
})
];
}

View File

@ -180,8 +180,17 @@ in
###### 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";
};
}
(mkIf config.services.samba.enable {
users.extraUsers = singleton
{ name = user;
description = "Samba service user";
@ -192,13 +201,6 @@ in
{ 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).
jobs.sambaControl =
@ -216,7 +218,7 @@ in
jobs.smbd = daemonJob "smbd" "-D";
jobs.winbindd = daemonJob "winbindd" "-D";
};
})
];
}