Add option systemd.automounts, for definining automount units

This commit is contained in:
Rickard Nilsson 2013-09-23 22:56:05 +02:00
parent 9df40867b9
commit 3a17c2b30b
2 changed files with 59 additions and 1 deletions

@ -323,4 +323,28 @@ rec {
}; };
}; };
automountOptions = unitOptions // {
where = mkOption {
example = "/mnt";
type = types.uniq types.string;
description = ''
Absolute path of a directory of the mount point.
Will be created if it doesn't exist. (Mandatory)
'';
};
automountConfig = mkOption {
default = {};
example = { DirectoryMode = "0775"; };
type = types.attrs;
description = ''
Each attribute in this set specifies an option in the
<literal>[Automount]</literal> section of the unit. See
<citerefentry><refentrytitle>systemd.automount</refentrytitle>
<manvolnum>5</manvolnum></citerefentry> for details.
'';
};
};
} }

@ -185,6 +185,14 @@ let
}; };
}; };
automountConfig = { name, config, ... }: {
config = {
automountConfig =
{ Where = config.where;
};
};
};
toOption = x: toOption = x:
if x == true then "true" if x == true then "true"
else if x == false then "false" else if x == false then "false"
@ -291,6 +299,18 @@ let
''; '';
}; };
automountToUnit = name: def:
{ inherit (def) wantedBy requiredBy enable;
text =
''
[Unit]
${attrsToSection def.unitConfig}
[Automount]
${attrsToSection def.automountConfig}
'';
};
nixosUnits = mapAttrsToList makeUnit cfg.units; nixosUnits = mapAttrsToList makeUnit cfg.units;
units = pkgs.runCommand "units" { preferLocalBuild = true; } units = pkgs.runCommand "units" { preferLocalBuild = true; }
@ -440,6 +460,17 @@ in
''; '';
}; };
systemd.automounts = mkOption {
default = [];
type = types.listOf types.optionSet;
options = [ automountOptions unitConfig automountConfig ];
description = ''
Definition of systemd automount units.
This is a list instead of an attrSet, because systemd mandates the names to be derived from
the 'where' attribute.
'';
};
systemd.defaultUnit = mkOption { systemd.defaultUnit = mkOption {
default = "multi-user.target"; default = "multi-user.target";
type = types.uniq types.string; type = types.uniq types.string;
@ -579,7 +610,10 @@ in
// mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.timers // mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.timers
// listToAttrs (map // listToAttrs (map
(v: let n = escapeSystemdPath v.where; (v: let n = escapeSystemdPath v.where;
in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts); in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts)
// listToAttrs (map
(v: let n = escapeSystemdPath v.where;
in nameValuePair "${n}.automount" (automountToUnit n v)) cfg.automounts);
system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled [ system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled [
"CGROUPS" "AUTOFS4_FS" "DEVTMPFS" "CGROUPS" "AUTOFS4_FS" "DEVTMPFS"