···
{ config, lib, pkgs, ... }:
5
-
if true == value then "yes"
6
-
else if false == value then "no"
9
-
inherit (lib.attrsets) mapAttrsToList optionalAttrs;
4
+
inherit (lib.attrsets) optionalAttrs;
5
+
inherit (lib.generators) toINIWithGlobalSection;
inherit (lib.lists) optional;
inherit (lib.modules) mkIf;
inherit (lib.options) literalExpression mkEnableOption mkOption;
13
-
inherit (lib.strings) concatLines;
14
-
inherit (lib.types) lines str submodule;
9
+
inherit (lib.strings) escape;
10
+
inherit (lib.types) attrsOf bool int lines oneOf str submodule;
cfg = config.services.davfs2;
17
-
format = pkgs.formats.toml { };
19
-
settings = mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings;
20
-
in pkgs.writeText "davfs2.conf" ''
21
-
${concatLines settings}
14
+
escapeString = escape ["\"" "\\"];
16
+
formatValue = value:
17
+
if true == value then "1"
18
+
else if false == value then "0"
19
+
else if builtins.isString value then "\"${escapeString value}\""
20
+
else toString value;
22
+
configFile = pkgs.writeText "davfs2.conf" ''
23
+
${toINIWithGlobalSection {
24
+
mkSectionName = escapeString;
25
+
mkKeyValue = k: v: "${k} ${formatValue v}";
···
74
-
freeformType = format.type;
80
+
valueTypes = [ bool int str ];
82
+
attrsOf (attrsOf (oneOf (valueTypes ++ [ (attrsOf (oneOf valueTypes)) ] )));
example = literalExpression ''
80
-
proxy = "foo.bar:8080";
88
+
proxy = "foo.bar:8080";
95
+
"/home/otto/mywebspace" = {
96
+
gui_optimize = true;
···
environment.etc."davfs2/davfs2.conf".source = configFile;
services.davfs2.settings = {
102
-
dav_user = cfg.davUser;
103
-
dav_group = cfg.davGroup;
120
+
dav_user = cfg.davUser;
121
+
dav_group = cfg.davGroup;
users.groups = optionalAttrs (cfg.davGroup == "davfs2") {