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,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 =
[ cfg.package ];
(mkIf cfg.enable {
environment.etc = mkAlways (
[ # 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
''}
'';
}
environment.systemPackages = [ cfg.package ];
] ++ optionals cfg.enable
[ # Write an /etc/asound.conf that causes all ALSA applications to
# be re-routed to the PulseAudio server through ALSA's Pulse
# plugin.
{ target = "asound.conf";
source = pkgs.writeText "asound.conf"
''
pcm_type.pulse {
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so
}
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.
{ target = "asound.conf";
source = pkgs.writeText "asound.conf"
''
pcm_type.pulse {
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_pcm_pulse.so
}
pcm.!default {
type pulse
hint.description "Default Audio Device (via PulseAudio)"
}
pcm.!default {
type pulse
hint.description "Default Audio Device (via PulseAudio)"
}
ctl_type.pulse {
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so
}
ctl_type.pulse {
lib ${pkgs.alsaPlugins}/lib/alsa-lib/libasound_module_ctl_pulse.so
}
ctl.!default {
type pulse
}
'';
}
ctl.!default {
type pulse
}
'';
}
{ target = "pulse/default.pa";
source = "${cfg.package}/etc/pulse/default.pa";
}
{ target = "pulse/default.pa";
source = "${cfg.package}/etc/pulse/default.pa";
}
{ target = "pulse/system.pa";
source = "${cfg.package}/etc/pulse/system.pa";
}
{ target = "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 = {
enable = mkOption {
description = "Whether to share /home/smbd as 'default'.";
default = false;
};
description = "Whether to share /home/smbd as 'default'.";
default = false;
};
writeable = mkOption {
description = "Whether to allow write access to default share.";
default = false;
};
description = "Whether to allow write access to default share.";
default = false;
};
guest = mkOption {
description = "Whether to allow guest access to default share.";
default = true;
};
description = "Whether to allow guest access to default share.";
default = true;
};
};
securityType = mkOption {
description = "Samba security type";
default = "user";
example = "share";
default = "user";
example = "share";
};
};
@ -180,43 +180,45 @@ 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";
};
}
users.extraUsers = singleton
{ name = user;
description = "Samba service user";
group = group;
};
(mkIf config.services.samba.enable {
users.extraUsers = singleton
{ name = user;
description = "Samba service user";
group = group;
};
users.extraGroups = singleton
{ name = group;
};
users.extraGroups = singleton
{ 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 =
{ name = "samba";
description = "Samba server";
# Dummy job to start the real Samba daemons (nmbd, smbd, winbindd).
jobs.sambaControl =
{ name = "samba";
description = "Samba server";
startOn = "started network-interfaces";
stopOn = "stopping network-interfaces";
startOn = "started 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";
})
];
}