From 3a17c2b30b72f48ed8ccc294ad94e6233d77402b Mon Sep 17 00:00:00 2001 From: Rickard Nilsson Date: Mon, 23 Sep 2013 22:56:05 +0200 Subject: [PATCH] Add option systemd.automounts, for definining automount units --- modules/system/boot/systemd-unit-options.nix | 24 +++++++++++++ modules/system/boot/systemd.nix | 36 +++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index be3fbd55674..e6e8d9eb3b0 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 21b3e5e80a0..35ae6a84024 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"