summary refs log tree commit diff
diff options
context:
space:
mode:
authorRickard Nilsson <rickynils@gmail.com>2013-09-23 22:56:05 +0200
committerRickard Nilsson <rickynils@gmail.com>2013-09-23 23:16:45 +0200
commit3a17c2b30b72f48ed8ccc294ad94e6233d77402b (patch)
tree8dfb94e4e9c316fd04d45a023fe1c642cacf5385
parent9df40867b98ff21af499cb423fd758e351188e6b (diff)
downloadnixlib-3a17c2b30b72f48ed8ccc294ad94e6233d77402b.tar
nixlib-3a17c2b30b72f48ed8ccc294ad94e6233d77402b.tar.gz
nixlib-3a17c2b30b72f48ed8ccc294ad94e6233d77402b.tar.bz2
nixlib-3a17c2b30b72f48ed8ccc294ad94e6233d77402b.tar.lz
nixlib-3a17c2b30b72f48ed8ccc294ad94e6233d77402b.tar.xz
nixlib-3a17c2b30b72f48ed8ccc294ad94e6233d77402b.tar.zst
nixlib-3a17c2b30b72f48ed8ccc294ad94e6233d77402b.zip
Add option systemd.automounts, for definining automount units
-rw-r--r--modules/system/boot/systemd-unit-options.nix24
-rw-r--r--modules/system/boot/systemd.nix36
2 files changed, 59 insertions, 1 deletions
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
+        <literal>[Automount]</literal> section of the unit.  See
+        <citerefentry><refentrytitle>systemd.automount</refentrytitle>
+        <manvolnum>5</manvolnum></citerefentry> 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"