diff options
author | ajs124 <ajs124@users.noreply.github.com> | 2021-12-08 15:07:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-08 15:07:28 +0000 |
commit | eee45bb295b9e4550e778982136f5b8aa1ab37fc (patch) | |
tree | 717d84c48d49615acc43a3a0b2e33442572f339a /nixos/modules | |
parent | 8010ff0d543d21fe639efd17f5ecb6e3e3ee9534 (diff) | |
parent | 851495a752f9f631cf47637df1d6e7a301920ba4 (diff) | |
download | nixpkgs-eee45bb295b9e4550e778982136f5b8aa1ab37fc.tar nixpkgs-eee45bb295b9e4550e778982136f5b8aa1ab37fc.tar.gz nixpkgs-eee45bb295b9e4550e778982136f5b8aa1ab37fc.tar.bz2 nixpkgs-eee45bb295b9e4550e778982136f5b8aa1ab37fc.tar.lz nixpkgs-eee45bb295b9e4550e778982136f5b8aa1ab37fc.tar.xz nixpkgs-eee45bb295b9e4550e778982136f5b8aa1ab37fc.tar.zst nixpkgs-eee45bb295b9e4550e778982136f5b8aa1ab37fc.zip |
Merge pull request #146815 from ElvishJerricco/systemd-utils-expressions
Move systemd-lib.nix and systemd-unit-options.nix into utils
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/misc/extra-arguments.nix | 4 | ||||
-rw-r--r-- | nixos/modules/security/systemd-confinement.nix | 6 | ||||
-rw-r--r-- | nixos/modules/services/backup/restic.nix | 4 | ||||
-rw-r--r-- | nixos/modules/system/boot/networkd.nix | 6 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd-lib.nix | 237 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd-nspawn.nix | 6 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd-unit-options.nix | 536 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd.nix | 4 |
8 files changed, 14 insertions, 789 deletions
diff --git a/nixos/modules/misc/extra-arguments.nix b/nixos/modules/misc/extra-arguments.nix index 8716e3d9fef..48891b44049 100644 --- a/nixos/modules/misc/extra-arguments.nix +++ b/nixos/modules/misc/extra-arguments.nix @@ -1,7 +1,7 @@ -{ pkgs, ... }: +{ lib, config, pkgs, ... }: { _module.args = { - utils = import ../../lib/utils.nix pkgs; + utils = import ../../lib/utils.nix { inherit lib config pkgs; }; }; } diff --git a/nixos/modules/security/systemd-confinement.nix b/nixos/modules/security/systemd-confinement.nix index d859c45c74f..0e3ec5af323 100644 --- a/nixos/modules/security/systemd-confinement.nix +++ b/nixos/modules/security/systemd-confinement.nix @@ -1,11 +1,9 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, utils, ... }: let toplevelConfig = config; inherit (lib) types; - inherit (import ../system/boot/systemd-lib.nix { - inherit config pkgs lib; - }) mkPathSafeName; + inherit (utils.systemdUtils.lib) mkPathSafeName; in { options.systemd.services = lib.mkOption { type = types.attrsOf (types.submodule ({ name, config, ... }: { diff --git a/nixos/modules/services/backup/restic.nix b/nixos/modules/services/backup/restic.nix index 67fef55614b..8ff8e31864b 100644 --- a/nixos/modules/services/backup/restic.nix +++ b/nixos/modules/services/backup/restic.nix @@ -1,10 +1,10 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, utils, ... }: with lib; let # Type for a valid systemd unit option. Needed for correctly passing "timerConfig" to "systemd.timers" - unitOption = (import ../../system/boot/systemd-unit-options.nix { inherit config lib; }).unitOption; + inherit (utils.systemdUtils.unitOptions) unitOption; in { options.services.restic.backups = mkOption { diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index 5c074672b99..83654b88dbd 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -1,8 +1,8 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, utils, ... }: +with utils.systemdUtils.unitOptions; +with utils.systemdUtils.lib; with lib; -with import ./systemd-unit-options.nix { inherit config lib; }; -with import ./systemd-lib.nix { inherit config lib pkgs; }; let diff --git a/nixos/modules/system/boot/systemd-lib.nix b/nixos/modules/system/boot/systemd-lib.nix deleted file mode 100644 index 6c4d27018ee..00000000000 --- a/nixos/modules/system/boot/systemd-lib.nix +++ /dev/null @@ -1,237 +0,0 @@ -{ config, lib, pkgs }: - -with lib; - -let - cfg = config.systemd; - lndir = "${pkgs.buildPackages.xorg.lndir}/bin/lndir"; -in rec { - - shellEscape = s: (replaceChars [ "\\" ] [ "\\\\" ] s); - - mkPathSafeName = lib.replaceChars ["@" ":" "\\" "[" "]"] ["-" "-" "-" "" ""]; - - makeUnit = name: unit: - if unit.enable then - pkgs.runCommand "unit-${mkPathSafeName name}" - { preferLocalBuild = true; - allowSubstitutes = false; - inherit (unit) text; - } - '' - mkdir -p $out - echo -n "$text" > $out/${shellEscape name} - '' - else - pkgs.runCommand "unit-${mkPathSafeName name}-disabled" - { preferLocalBuild = true; - allowSubstitutes = false; - } - '' - mkdir -p $out - ln -s /dev/null $out/${shellEscape name} - ''; - - boolValues = [true false "yes" "no"]; - - digits = map toString (range 0 9); - - isByteFormat = s: - let - l = reverseList (stringToCharacters s); - suffix = head l; - nums = tail l; - in elem suffix (["K" "M" "G" "T"] ++ digits) - && all (num: elem num digits) nums; - - assertByteFormat = name: group: attr: - optional (attr ? ${name} && ! isByteFormat attr.${name}) - "Systemd ${group} field `${name}' must be in byte format [0-9]+[KMGT]."; - - hexChars = stringToCharacters "0123456789abcdefABCDEF"; - - isMacAddress = s: stringLength s == 17 - && flip all (splitString ":" s) (bytes: - all (byte: elem byte hexChars) (stringToCharacters bytes) - ); - - assertMacAddress = name: group: attr: - optional (attr ? ${name} && ! isMacAddress attr.${name}) - "Systemd ${group} field `${name}' must be a valid mac address."; - - isPort = i: i >= 0 && i <= 65535; - - assertPort = name: group: attr: - optional (attr ? ${name} && ! isPort attr.${name}) - "Error on the systemd ${group} field `${name}': ${attr.name} is not a valid port number."; - - assertValueOneOf = name: values: group: attr: - optional (attr ? ${name} && !elem attr.${name} values) - "Systemd ${group} field `${name}' cannot have value `${toString attr.${name}}'."; - - assertHasField = name: group: attr: - optional (!(attr ? ${name})) - "Systemd ${group} field `${name}' must exist."; - - assertRange = name: min: max: group: attr: - optional (attr ? ${name} && !(min <= attr.${name} && max >= attr.${name})) - "Systemd ${group} field `${name}' is outside the range [${toString min},${toString max}]"; - - assertMinimum = name: min: group: attr: - optional (attr ? ${name} && attr.${name} < min) - "Systemd ${group} field `${name}' must be greater than or equal to ${toString min}"; - - assertOnlyFields = fields: group: attr: - let badFields = filter (name: ! elem name fields) (attrNames attr); in - optional (badFields != [ ]) - "Systemd ${group} has extra fields [${concatStringsSep " " badFields}]."; - - assertInt = name: group: attr: - optional (attr ? ${name} && !isInt attr.${name}) - "Systemd ${group} field `${name}' is not an integer"; - - checkUnitConfig = group: checks: attrs: let - # We're applied at the top-level type (attrsOf unitOption), so the actual - # unit options might contain attributes from mkOverride and mkIf that we need to - # convert into single values before checking them. - defs = mapAttrs (const (v: - if v._type or "" == "override" then v.content - else if v._type or "" == "if" then v.content - else v - )) attrs; - errors = concatMap (c: c group defs) checks; - in if errors == [] then true - else builtins.trace (concatStringsSep "\n" errors) false; - - toOption = x: - if x == true then "true" - else if x == false then "false" - else toString x; - - attrsToSection = as: - concatStrings (concatLists (mapAttrsToList (name: value: - map (x: '' - ${name}=${toOption x} - '') - (if isList value then value else [value])) - as)); - - generateUnits = generateUnits' true; - - generateUnits' = allowCollisions: type: units: upstreamUnits: upstreamWants: - pkgs.runCommand "${type}-units" - { preferLocalBuild = true; - allowSubstitutes = false; - } '' - mkdir -p $out - - # Copy the upstream systemd units we're interested in. - for i in ${toString upstreamUnits}; do - fn=${cfg.package}/example/systemd/${type}/$i - if ! [ -e $fn ]; then echo "missing $fn"; false; fi - if [ -L $fn ]; then - target="$(readlink "$fn")" - if [ ''${target:0:3} = ../ ]; then - ln -s "$(readlink -f "$fn")" $out/ - else - cp -pd $fn $out/ - fi - else - ln -s $fn $out/ - fi - done - - # Copy .wants links, but only those that point to units that - # we're interested in. - for i in ${toString upstreamWants}; do - fn=${cfg.package}/example/systemd/${type}/$i - if ! [ -e $fn ]; then echo "missing $fn"; false; fi - x=$out/$(basename $fn) - mkdir $x - for i in $fn/*; do - y=$x/$(basename $i) - cp -pd $i $y - if ! [ -e $y ]; then rm $y; fi - done - done - - # Symlink all units provided listed in systemd.packages. - packages="${toString cfg.packages}" - - # Filter duplicate directories - declare -A unique_packages - for k in $packages ; do unique_packages[$k]=1 ; done - - for i in ''${!unique_packages[@]}; do - for fn in $i/etc/systemd/${type}/* $i/lib/systemd/${type}/*; do - if ! [[ "$fn" =~ .wants$ ]]; then - if [[ -d "$fn" ]]; then - targetDir="$out/$(basename "$fn")" - mkdir -p "$targetDir" - ${lndir} "$fn" "$targetDir" - else - ln -s $fn $out/ - fi - fi - done - done - - # Symlink all units defined by systemd.units. If these are also - # provided by systemd or systemd.packages, then add them as - # <unit-name>.d/overrides.conf, which makes them extend the - # upstream unit. - for i in ${toString (mapAttrsToList (n: v: v.unit) units)}; do - fn=$(basename $i/*) - if [ -e $out/$fn ]; then - if [ "$(readlink -f $i/$fn)" = /dev/null ]; then - ln -sfn /dev/null $out/$fn - else - ${if allowCollisions then '' - mkdir -p $out/$fn.d - ln -s $i/$fn $out/$fn.d/overrides.conf - '' else '' - echo "Found multiple derivations configuring $fn!" - exit 1 - ''} - fi - else - ln -fs $i/$fn $out/ - fi - done - - # Create service aliases from aliases option. - ${concatStrings (mapAttrsToList (name: unit: - concatMapStrings (name2: '' - ln -sfn '${name}' $out/'${name2}' - '') unit.aliases) units)} - - # Create .wants and .requires symlinks from the wantedBy and - # requiredBy options. - ${concatStrings (mapAttrsToList (name: unit: - concatMapStrings (name2: '' - mkdir -p $out/'${name2}.wants' - ln -sfn '../${name}' $out/'${name2}.wants'/ - '') unit.wantedBy) units)} - - ${concatStrings (mapAttrsToList (name: unit: - concatMapStrings (name2: '' - mkdir -p $out/'${name2}.requires' - ln -sfn '../${name}' $out/'${name2}.requires'/ - '') unit.requiredBy) units)} - - ${optionalString (type == "system") '' - # Stupid misc. symlinks. - ln -s ${cfg.defaultUnit} $out/default.target - ln -s ${cfg.ctrlAltDelUnit} $out/ctrl-alt-del.target - ln -s rescue.target $out/kbrequest.target - - mkdir -p $out/getty.target.wants/ - ln -s ../autovt@tty1.service $out/getty.target.wants/ - - ln -s ../local-fs.target ../remote-fs.target \ - ../nss-lookup.target ../nss-user-lookup.target ../swap.target \ - $out/multi-user.target.wants/ - ''} - ''; # */ - -} diff --git a/nixos/modules/system/boot/systemd-nspawn.nix b/nixos/modules/system/boot/systemd-nspawn.nix index b450d77429b..02d2660add8 100644 --- a/nixos/modules/system/boot/systemd-nspawn.nix +++ b/nixos/modules/system/boot/systemd-nspawn.nix @@ -1,8 +1,8 @@ -{ config, lib , pkgs, ...}: +{ config, lib, pkgs, utils, ...}: +with utils.systemdUtils.unitOptions; +with utils.systemdUtils.lib; with lib; -with import ./systemd-unit-options.nix { inherit config lib; }; -with import ./systemd-lib.nix { inherit config lib pkgs; }; let cfg = config.systemd.nspawn; diff --git a/nixos/modules/system/boot/systemd-unit-options.nix b/nixos/modules/system/boot/systemd-unit-options.nix deleted file mode 100644 index 4154389b2ce..00000000000 --- a/nixos/modules/system/boot/systemd-unit-options.nix +++ /dev/null @@ -1,536 +0,0 @@ -{ config, lib }: - -with lib; -with import ./systemd-lib.nix { inherit config lib pkgs; }; - -let - checkService = checkUnitConfig "Service" [ - (assertValueOneOf "Type" [ - "exec" "simple" "forking" "oneshot" "dbus" "notify" "idle" - ]) - (assertValueOneOf "Restart" [ - "no" "on-success" "on-failure" "on-abnormal" "on-abort" "always" - ]) - ]; - -in rec { - - unitOption = mkOptionType { - name = "systemd option"; - merge = loc: defs: - let - defs' = filterOverrides defs; - defs'' = getValues defs'; - in - if isList (head defs'') - then concatLists defs'' - else mergeEqualOption loc defs'; - }; - - sharedOptions = { - - enable = mkOption { - default = true; - type = types.bool; - description = '' - If set to false, this unit will be a symlink to - /dev/null. This is primarily useful to prevent specific - template instances - (e.g. <literal>serial-getty@ttyS0</literal>) from being - started. Note that <literal>enable=true</literal> does not - make a unit start by default at boot; if you want that, see - <literal>wantedBy</literal>. - ''; - }; - - requiredBy = mkOption { - default = []; - type = types.listOf types.str; - description = '' - Units that require (i.e. depend on and need to go down with) - this unit. The discussion under <literal>wantedBy</literal> - applies here as well: inverse <literal>.requires</literal> - symlinks are established. - ''; - }; - - wantedBy = mkOption { - default = []; - type = types.listOf types.str; - description = '' - Units that want (i.e. depend on) this unit. The standard way - to make a unit start by default at boot is to set this option - to <literal>[ "multi-user.target" ]</literal>. That's despite - the fact that the systemd.unit(5) manpage says this option - goes in the <literal>[Install]</literal> section that controls - the behaviour of <literal>systemctl enable</literal>. Since - such a process is stateful and thus contrary to the design of - NixOS, setting this option instead causes the equivalent - inverse <literal>.wants</literal> symlink to be present, - establishing the same desired relationship in a stateless way. - ''; - }; - - aliases = mkOption { - default = []; - type = types.listOf types.str; - description = "Aliases of that unit."; - }; - - }; - - concreteUnitOptions = sharedOptions // { - - text = mkOption { - type = types.nullOr types.str; - default = null; - description = "Text of this systemd unit."; - }; - - unit = mkOption { - internal = true; - description = "The generated unit."; - }; - - }; - - commonUnitOptions = sharedOptions // { - - description = mkOption { - default = ""; - type = types.str; - description = "Description of this unit used in systemd messages and progress indicators."; - }; - - documentation = mkOption { - default = []; - type = types.listOf types.str; - description = "A list of URIs referencing documentation for this unit or its configuration."; - }; - - requires = mkOption { - default = []; - type = types.listOf types.str; - description = '' - Start the specified units when this unit is started, and stop - this unit when the specified units are stopped or fail. - ''; - }; - - wants = mkOption { - default = []; - type = types.listOf types.str; - description = '' - Start the specified units when this unit is started. - ''; - }; - - after = mkOption { - default = []; - type = types.listOf types.str; - description = '' - If the specified units are started at the same time as - this unit, delay this unit until they have started. - ''; - }; - - before = mkOption { - default = []; - type = types.listOf types.str; - description = '' - If the specified units are started at the same time as - this unit, delay them until this unit has started. - ''; - }; - - bindsTo = mkOption { - default = []; - type = types.listOf types.str; - description = '' - Like ‘requires’, but in addition, if the specified units - unexpectedly disappear, this unit will be stopped as well. - ''; - }; - - partOf = mkOption { - default = []; - type = types.listOf types.str; - description = '' - If the specified units are stopped or restarted, then this - unit is stopped or restarted as well. - ''; - }; - - conflicts = mkOption { - default = []; - type = types.listOf types.str; - description = '' - If the specified units are started, then this unit is stopped - and vice versa. - ''; - }; - - requisite = mkOption { - default = []; - type = types.listOf types.str; - description = '' - Similar to requires. However if the units listed are not started, - they will not be started and the transaction will fail. - ''; - }; - - unitConfig = mkOption { - default = {}; - example = { RequiresMountsFor = "/data"; }; - type = types.attrsOf unitOption; - description = '' - Each attribute in this set specifies an option in the - <literal>[Unit]</literal> section of the unit. See - <citerefentry><refentrytitle>systemd.unit</refentrytitle> - <manvolnum>5</manvolnum></citerefentry> for details. - ''; - }; - - restartTriggers = mkOption { - default = []; - type = types.listOf types.unspecified; - description = '' - An arbitrary list of items such as derivations. If any item - in the list changes between reconfigurations, the service will - be restarted. - ''; - }; - - onFailure = mkOption { - default = []; - type = types.listOf types.str; - description = '' - A list of one or more units that are activated when - this unit enters the "failed" state. - ''; - }; - - startLimitBurst = mkOption { - type = types.int; - description = '' - Configure unit start rate limiting. Units which are started - more than startLimitBurst times within an interval time - interval are not permitted to start any more. - ''; - }; - - startLimitIntervalSec = mkOption { - type = types.int; - description = '' - Configure unit start rate limiting. Units which are started - more than startLimitBurst times within an interval time - interval are not permitted to start any more. - ''; - }; - - }; - - - serviceOptions = commonUnitOptions // { - - environment = mkOption { - default = {}; - type = with types; attrsOf (nullOr (oneOf [ str path package ])); - example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; }; - description = "Environment variables passed to the service's processes."; - }; - - path = mkOption { - default = []; - type = with types; listOf (oneOf [ package str ]); - description = '' - Packages added to the service's <envar>PATH</envar> - environment variable. Both the <filename>bin</filename> - and <filename>sbin</filename> subdirectories of each - package are added. - ''; - }; - - serviceConfig = mkOption { - default = {}; - example = - { RestartSec = 5; - }; - type = types.addCheck (types.attrsOf unitOption) checkService; - description = '' - Each attribute in this set specifies an option in the - <literal>[Service]</literal> section of the unit. See - <citerefentry><refentrytitle>systemd.service</refentrytitle> - <manvolnum>5</manvolnum></citerefentry> for details. - ''; - }; - - script = mkOption { - type = types.lines; - default = ""; - description = "Shell commands executed as the service's main process."; - }; - - scriptArgs = mkOption { - type = types.str; - default = ""; - description = "Arguments passed to the main process script."; - }; - - preStart = mkOption { - type = types.lines; - default = ""; - description = '' - Shell commands executed before the service's main process - is started. - ''; - }; - - postStart = mkOption { - type = types.lines; - default = ""; - description = '' - Shell commands executed after the service's main process - is started. - ''; - }; - - reload = mkOption { - type = types.lines; - default = ""; - description = '' - Shell commands executed when the service's main process - is reloaded. - ''; - }; - - preStop = mkOption { - type = types.lines; - default = ""; - description = '' - Shell commands executed to stop the service. - ''; - }; - - postStop = mkOption { - type = types.lines; - default = ""; - description = '' - Shell commands executed after the service's main process - has exited. - ''; - }; - - restartIfChanged = mkOption { - type = types.bool; - default = true; - description = '' - Whether the service should be restarted during a NixOS - configuration switch if its definition has changed. - ''; - }; - - reloadIfChanged = mkOption { - type = types.bool; - default = false; - description = '' - Whether the service should be reloaded during a NixOS - configuration switch if its definition has changed. If - enabled, the value of <option>restartIfChanged</option> is - ignored. - ''; - }; - - stopIfChanged = mkOption { - type = types.bool; - default = true; - description = '' - If set, a changed unit is restarted by calling - <command>systemctl stop</command> in the old configuration, - then <command>systemctl start</command> in the new one. - Otherwise, it is restarted in a single step using - <command>systemctl restart</command> in the new configuration. - The latter is less correct because it runs the - <literal>ExecStop</literal> commands from the new - configuration. - ''; - }; - - startAt = mkOption { - type = with types; either str (listOf str); - default = []; - example = "Sun 14:00:00"; - description = '' - Automatically start this unit at the given date/time, which - must be in the format described in - <citerefentry><refentrytitle>systemd.time</refentrytitle> - <manvolnum>7</manvolnum></citerefentry>. This is equivalent - to adding a corresponding timer unit with - <option>OnCalendar</option> set to the value given here. - ''; - apply = v: if isList v then v else [ v ]; - }; - - }; - - - socketOptions = commonUnitOptions // { - - listenStreams = mkOption { - default = []; - type = types.listOf types.str; - example = [ "0.0.0.0:993" "/run/my-socket" ]; - description = '' - For each item in this list, a <literal>ListenStream</literal> - option in the <literal>[Socket]</literal> section will be created. - ''; - }; - - listenDatagrams = mkOption { - default = []; - type = types.listOf types.str; - example = [ "0.0.0.0:993" "/run/my-socket" ]; - description = '' - For each item in this list, a <literal>ListenDatagram</literal> - option in the <literal>[Socket]</literal> section will be created. - ''; - }; - - socketConfig = mkOption { - default = {}; - example = { ListenStream = "/run/my-socket"; }; - type = types.attrsOf unitOption; - description = '' - Each attribute in this set specifies an option in the - <literal>[Socket]</literal> section of the unit. See - <citerefentry><refentrytitle>systemd.socket</refentrytitle> - <manvolnum>5</manvolnum></citerefentry> for details. - ''; - }; - - }; - - - timerOptions = commonUnitOptions // { - - timerConfig = mkOption { - default = {}; - example = { OnCalendar = "Sun 14:00:00"; Unit = "foo.service"; }; - type = types.attrsOf unitOption; - description = '' - Each attribute in this set specifies an option in the - <literal>[Timer]</literal> section of the unit. See - <citerefentry><refentrytitle>systemd.timer</refentrytitle> - <manvolnum>5</manvolnum></citerefentry> and - <citerefentry><refentrytitle>systemd.time</refentrytitle> - <manvolnum>7</manvolnum></citerefentry> for details. - ''; - }; - - }; - - - pathOptions = commonUnitOptions // { - - pathConfig = mkOption { - default = {}; - example = { PathChanged = "/some/path"; Unit = "changedpath.service"; }; - type = types.attrsOf unitOption; - description = '' - Each attribute in this set specifies an option in the - <literal>[Path]</literal> section of the unit. See - <citerefentry><refentrytitle>systemd.path</refentrytitle> - <manvolnum>5</manvolnum></citerefentry> for details. - ''; - }; - - }; - - - mountOptions = commonUnitOptions // { - - what = mkOption { - example = "/dev/sda1"; - type = types.str; - description = "Absolute path of device node, file or other resource. (Mandatory)"; - }; - - where = mkOption { - example = "/mnt"; - type = types.str; - description = '' - Absolute path of a directory of the mount point. - Will be created if it doesn't exist. (Mandatory) - ''; - }; - - type = mkOption { - default = ""; - example = "ext4"; - type = types.str; - description = "File system type."; - }; - - options = mkOption { - default = ""; - example = "noatime"; - type = types.commas; - description = "Options used to mount the file system."; - }; - - mountConfig = mkOption { - default = {}; - example = { DirectoryMode = "0775"; }; - type = types.attrsOf unitOption; - description = '' - Each attribute in this set specifies an option in the - <literal>[Mount]</literal> section of the unit. See - <citerefentry><refentrytitle>systemd.mount</refentrytitle> - <manvolnum>5</manvolnum></citerefentry> for details. - ''; - }; - }; - - automountOptions = commonUnitOptions // { - - where = mkOption { - example = "/mnt"; - type = types.str; - 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.attrsOf unitOption; - 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. - ''; - }; - }; - - targetOptions = commonUnitOptions; - - sliceOptions = commonUnitOptions // { - - sliceConfig = mkOption { - default = {}; - example = { MemoryMax = "2G"; }; - type = types.attrsOf unitOption; - description = '' - Each attribute in this set specifies an option in the - <literal>[Slice]</literal> section of the unit. See - <citerefentry><refentrytitle>systemd.slice</refentrytitle> - <manvolnum>5</manvolnum></citerefentry> for details. - ''; - }; - - }; - -} diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 6e0ee437d91..ec5dea075bb 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -1,9 +1,9 @@ { config, lib, pkgs, utils, ... }: with utils; +with systemdUtils.unitOptions; +with systemdUtils.lib; with lib; -with import ./systemd-unit-options.nix { inherit config lib; }; -with import ./systemd-lib.nix { inherit config lib pkgs; }; let |