nixos/davfs2: fix settings option

This commit is contained in:
éclairevoyant 2024-04-08 19:12:29 -04:00
parent bd4d34650c
commit 10c5429290
No known key found for this signature in database
GPG Key ID: E3813AEAA02DB54B

View File

@ -1,24 +1,29 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
toStr = value: inherit (lib.attrsets) optionalAttrs;
if true == value then "yes" inherit (lib.generators) toINIWithGlobalSection;
else if false == value then "no"
else toString value;
inherit (lib.attrsets) mapAttrsToList optionalAttrs;
inherit (lib.lists) optional; inherit (lib.lists) optional;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.options) literalExpression mkEnableOption mkOption;
inherit (lib.strings) concatLines; inherit (lib.strings) escape;
inherit (lib.types) lines str submodule; inherit (lib.types) attrsOf bool int lines oneOf str submodule;
cfg = config.services.davfs2; cfg = config.services.davfs2;
format = pkgs.formats.toml { };
configFile = let escapeString = escape ["\"" "\\"];
settings = mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings;
in pkgs.writeText "davfs2.conf" '' formatValue = value:
${concatLines settings} 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} ${cfg.extraConfig}
''; '';
in in
@ -71,14 +76,26 @@ in
settings = mkOption { settings = mkOption {
type = submodule { type = submodule {
freeformType = format.type; freeformType = let
valueTypes = [ bool int str ];
in
attrsOf (attrsOf (oneOf (valueTypes ++ [ (attrsOf (oneOf valueTypes)) ] )));
}; };
default = {}; default = { };
example = literalExpression '' example = literalExpression ''
{ {
kernel_fs = "coda"; globalSection = {
proxy = "foo.bar:8080"; proxy = "foo.bar:8080";
use_locks = 0; use_locks = false;
};
sections = {
"/media/dav" = {
use_locks = true;
};
"/home/otto/mywebspace" = {
gui_optimize = true;
};
};
} }
''; '';
description = '' description = ''
@ -99,8 +116,10 @@ in
environment.etc."davfs2/davfs2.conf".source = configFile; environment.etc."davfs2/davfs2.conf".source = configFile;
services.davfs2.settings = { services.davfs2.settings = {
dav_user = cfg.davUser; globalSection = {
dav_group = cfg.davGroup; dav_user = cfg.davUser;
dav_group = cfg.davGroup;
};
}; };
users.groups = optionalAttrs (cfg.davGroup == "davfs2") { users.groups = optionalAttrs (cfg.davGroup == "davfs2") {