diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix
index be3fbd556741..e6e8d9eb3b01 100644
--- a/modules/system/boot/systemd-unit-options.nix
+++ b/modules/system/boot/systemd-unit-options.nix
@@ -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
+ [Automount] section of the unit. See
+ systemd.automount
+ 5 for details.
+ '';
+ };
+ };
+
}
diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix
index 21b3e5e80a03..35ae6a84024c 100644
--- a/modules/system/boot/systemd.nix
+++ b/modules/system/boot/systemd.nix
@@ -185,6 +185,14 @@ let
};
};
+ automountConfig = { name, config, ... }: {
+ config = {
+ automountConfig =
+ { Where = config.where;
+ };
+ };
+ };
+
toOption = x:
if x == true then "true"
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;
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 {
default = "multi-user.target";
type = types.uniq types.string;
@@ -579,7 +610,10 @@ in
// mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.timers
// listToAttrs (map
(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 [
"CGROUPS" "AUTOFS4_FS" "DEVTMPFS"