From 0739d3c4c0288cd986483118890563a5ffb5469f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9clairevoyant?= <848000+eclairevoyant@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:33:55 -0400 Subject: [PATCH 1/7] nixos/davfs2: fix the warning that deprecates extraConfig --- nixos/modules/services/network-filesystems/davfs2.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/network-filesystems/davfs2.nix b/nixos/modules/services/network-filesystems/davfs2.nix index 90bb5ee5e66c..0bba62948e53 100644 --- a/nixos/modules/services/network-filesystems/davfs2.nix +++ b/nixos/modules/services/network-filesystems/davfs2.nix @@ -86,7 +86,7 @@ in config = mkIf cfg.enable { - warnings = lib.optional (cfg.extraConfig != null) '' + warnings = lib.optional (cfg.extraConfig != "") '' services.davfs2.extraConfig will be deprecated in future releases, please use the settings option now. ''; From caa0cbab281b20ab081c619d3de3d2ec2023585f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9clairevoyant?= <848000+eclairevoyant@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:36:23 -0400 Subject: [PATCH 2/7] nixos/davfs2: clarify warning --- nixos/modules/services/network-filesystems/davfs2.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/network-filesystems/davfs2.nix b/nixos/modules/services/network-filesystems/davfs2.nix index 0bba62948e53..586ee9a8dc39 100644 --- a/nixos/modules/services/network-filesystems/davfs2.nix +++ b/nixos/modules/services/network-filesystems/davfs2.nix @@ -87,7 +87,8 @@ in config = mkIf cfg.enable { warnings = lib.optional (cfg.extraConfig != "") '' - services.davfs2.extraConfig will be deprecated in future releases, please use the settings option now. + services.davfs2.extraConfig will be deprecated in future releases; + please use services.davfs2.settings instead. ''; environment.systemPackages = [ pkgs.davfs2 ]; From 6cbffaae4c1505719e8a1427f6bf846ddad17774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9clairevoyant?= <848000+eclairevoyant@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:41:30 -0400 Subject: [PATCH 3/7] nixos/davfs2: remove lib.mdDoc (no-op) --- nixos/modules/services/network-filesystems/davfs2.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/network-filesystems/davfs2.nix b/nixos/modules/services/network-filesystems/davfs2.nix index 586ee9a8dc39..0f45786a4be2 100644 --- a/nixos/modules/services/network-filesystems/davfs2.nix +++ b/nixos/modules/services/network-filesystems/davfs2.nix @@ -23,7 +23,7 @@ in enable = mkOption { type = types.bool; default = false; - description = lib.mdDoc '' + description = '' Whether to enable davfs2. ''; }; @@ -31,7 +31,7 @@ in davUser = mkOption { type = types.str; default = "davfs2"; - description = lib.mdDoc '' + description = '' When invoked by root the mount.davfs daemon will run as this user. Value must be given as name, not as numerical id. ''; @@ -40,7 +40,7 @@ in davGroup = mkOption { type = types.str; default = "davfs2"; - description = lib.mdDoc '' + description = '' The group of the running mount.davfs daemon. Ordinary users must be member of this group in order to mount a davfs2 file system. Value must be given as name, not as numerical id. @@ -55,7 +55,7 @@ in proxy foo.bar:8080 use_locks 0 ''; - description = lib.mdDoc '' + description = '' Extra lines appended to the configuration of davfs2. See {manpage}`davfs2.conf(5)` for available settings. @@ -77,7 +77,7 @@ in use_locks = 0; } ''; - description = lib.mdDoc '' + description = '' Extra settings appended to the configuration of davfs2. See {manpage}`davfs2.conf(5)` for available settings. '' ; From 0ac090f91af885eee5d10e6fb0c3acb82ff1350f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9clairevoyant?= <848000+eclairevoyant@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:45:48 -0400 Subject: [PATCH 4/7] nixos/davfs2: remove top-level `with lib;` --- .../services/network-filesystems/davfs2.nix | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/network-filesystems/davfs2.nix b/nixos/modules/services/network-filesystems/davfs2.nix index 0f45786a4be2..56302f2f22b6 100644 --- a/nixos/modules/services/network-filesystems/davfs2.nix +++ b/nixos/modules/services/network-filesystems/davfs2.nix @@ -1,35 +1,34 @@ { config, lib, pkgs, ... }: -with lib; - let toStr = value: if true == value then "yes" else if false == value then "no" else toString value; + inherit (lib.attrsets) mapAttrsToList optionalAttrs; + inherit (lib.lists) optional; + inherit (lib.modules) mkIf; + inherit (lib.options) literalExpression mkEnableOption mkOption; + inherit (lib.strings) concatLines; + inherit (lib.types) lines 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" '' - ${concatStringsSep "\n" settings} + ${concatLines settings} ${cfg.extraConfig} ''; in { options.services.davfs2 = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Whether to enable davfs2. - ''; - }; + enable = mkEnableOption "davfs2"; davUser = mkOption { - type = types.str; + type = str; default = "davfs2"; description = '' When invoked by root the mount.davfs daemon will run as this user. @@ -38,7 +37,7 @@ in }; davGroup = mkOption { - type = types.str; + type = str; default = "davfs2"; description = '' The group of the running mount.davfs daemon. Ordinary users must be @@ -48,7 +47,7 @@ in }; extraConfig = mkOption { - type = types.lines; + type = lines; default = ""; example = '' kernel_fs coda @@ -66,7 +65,7 @@ in }; settings = mkOption { - type = types.submodule { + type = submodule { freeformType = format.type; }; default = {}; @@ -86,7 +85,7 @@ in config = mkIf cfg.enable { - warnings = lib.optional (cfg.extraConfig != "") '' + warnings = optional (cfg.extraConfig != "") '' services.davfs2.extraConfig will be deprecated in future releases; please use services.davfs2.settings instead. ''; From bd4d34650cb58dc27014147698674f2add0aff24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9clairevoyant?= <848000+eclairevoyant@users.noreply.github.com> Date: Wed, 10 Apr 2024 01:19:21 -0400 Subject: [PATCH 5/7] nixos/davfs2: refresh extraConfig example --- nixos/modules/services/network-filesystems/davfs2.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/network-filesystems/davfs2.nix b/nixos/modules/services/network-filesystems/davfs2.nix index 56302f2f22b6..d53e2e3e2ed9 100644 --- a/nixos/modules/services/network-filesystems/davfs2.nix +++ b/nixos/modules/services/network-filesystems/davfs2.nix @@ -50,9 +50,14 @@ in type = lines; default = ""; example = '' - kernel_fs coda proxy foo.bar:8080 use_locks 0 + + [/media/dav] + use_locks 1 + + [/home/otto/mywebspace] + gui_optimize 1 ''; description = '' Extra lines appended to the configuration of davfs2. 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 6/7] 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") { From a60e4033cad693ccab024aa88f095b056594cc4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9clairevoyant?= <848000+eclairevoyant@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:08:08 -0400 Subject: [PATCH 7/7] nixos/davfs2: ensure extraConfig and settings are mutually exclusive --- .../services/network-filesystems/davfs2.nix | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/network-filesystems/davfs2.nix b/nixos/modules/services/network-filesystems/davfs2.nix index 2f616b076dff..23c04658031f 100644 --- a/nixos/modules/services/network-filesystems/davfs2.nix +++ b/nixos/modules/services/network-filesystems/davfs2.nix @@ -19,13 +19,15 @@ let 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} - ''; + configFile = pkgs.writeText "davfs2.conf" ( + if (cfg.settings != { }) then + (toINIWithGlobalSection { + mkSectionName = escapeString; + mkKeyValue = k: v: "${k} ${formatValue v}"; + } cfg.settings) + else + cfg.extraConfig + ); in { @@ -107,6 +109,16 @@ in config = mkIf cfg.enable { + assertions = [ + { + assertion = cfg.extraConfig != "" -> cfg.settings == { }; + message = '' + services.davfs2.extraConfig and services.davfs2.settings cannot be used together. + Please prefer using services.davfs2.settings. + ''; + } + ]; + warnings = optional (cfg.extraConfig != "") '' services.davfs2.extraConfig will be deprecated in future releases; please use services.davfs2.settings instead.