From 10c54292909511e591b13ff7f1b5bf1a8e0c1cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9clairevoyant?= <848000+eclairevoyant@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:12:29 -0400 Subject: [PATCH] nixos/davfs2: fix settings option --- .../services/network-filesystems/davfs2.nix | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/nixos/modules/services/network-filesystems/davfs2.nix b/nixos/modules/services/network-filesystems/davfs2.nix index d53e2e3e2ed9..2f616b076dff 100644 --- a/nixos/modules/services/network-filesystems/davfs2.nix +++ b/nixos/modules/services/network-filesystems/davfs2.nix @@ -1,24 +1,29 @@ { config, lib, pkgs, ... }: let - toStr = value: - if true == value then "yes" - else if false == value then "no" - else toString value; - - inherit (lib.attrsets) mapAttrsToList optionalAttrs; + inherit (lib.attrsets) optionalAttrs; + inherit (lib.generators) toINIWithGlobalSection; inherit (lib.lists) optional; inherit (lib.modules) mkIf; inherit (lib.options) literalExpression mkEnableOption mkOption; - inherit (lib.strings) concatLines; - inherit (lib.types) lines str submodule; + inherit (lib.strings) escape; + inherit (lib.types) attrsOf bool int lines oneOf str submodule; cfg = config.services.davfs2; - format = pkgs.formats.toml { }; - configFile = let - settings = mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings; - in pkgs.writeText "davfs2.conf" '' - ${concatLines settings} + + escapeString = escape ["\"" "\\"]; + + formatValue = value: + if true == value then "1" + else if false == value then "0" + else if builtins.isString value then "\"${escapeString value}\"" + else toString value; + + configFile = pkgs.writeText "davfs2.conf" '' + ${toINIWithGlobalSection { + mkSectionName = escapeString; + mkKeyValue = k: v: "${k} ${formatValue v}"; + } cfg.settings} ${cfg.extraConfig} ''; in @@ -71,14 +76,26 @@ in settings = mkOption { type = submodule { - freeformType = format.type; + freeformType = let + valueTypes = [ bool int str ]; + in + attrsOf (attrsOf (oneOf (valueTypes ++ [ (attrsOf (oneOf valueTypes)) ] ))); }; - default = {}; + default = { }; example = literalExpression '' { - kernel_fs = "coda"; - proxy = "foo.bar:8080"; - use_locks = 0; + globalSection = { + proxy = "foo.bar:8080"; + use_locks = false; + }; + sections = { + "/media/dav" = { + use_locks = true; + }; + "/home/otto/mywebspace" = { + gui_optimize = true; + }; + }; } ''; description = '' @@ -99,8 +116,10 @@ in environment.etc."davfs2/davfs2.conf".source = configFile; services.davfs2.settings = { - dav_user = cfg.davUser; - dav_group = cfg.davGroup; + globalSection = { + dav_user = cfg.davUser; + dav_group = cfg.davGroup; + }; }; users.groups = optionalAttrs (cfg.davGroup == "davfs2") {