From ad586e6bebef46d3a2e61751b5e028dd261556b3 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 1 Sep 2022 14:43:59 +0200 Subject: [PATCH] formats.systemd: init INI-style systemd config file format --- pkgs/pkgs-lib/formats.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index 3cbda3a7ebdd..950547c4f001 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -142,6 +142,20 @@ rec { }; + # As defined by systemd.syntax(7) + # + # null does not set any value, which allows for RFC42 modules to specify + # optional config options. + systemd = let + mkValueString = lib.generators.mkValueStringDefault {}; + mkKeyValue = k: v: + if v == null then "# ${k} is unset" + else "${k} = ${mkValueString v}"; + in ini { + listsAsDuplicateKeys = true; + inherit mkKeyValue; + }; + keyValue = { # Represents lists as duplicate keys listsAsDuplicateKeys ? false,