Merge pull request #302689 from eclairevoyant/davfs2-fix
nixos/davfs2: fix rfc42 conversion, make settings and extraConfig mutually exclusive, and other cleanup
This commit is contained in:
commit
b008f50607
|
@ -1,46 +1,52 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
toStr = value:
|
inherit (lib.attrsets) optionalAttrs;
|
||||||
if true == value then "yes"
|
inherit (lib.generators) toINIWithGlobalSection;
|
||||||
else if false == value then "no"
|
inherit (lib.lists) optional;
|
||||||
else toString value;
|
inherit (lib.modules) mkIf;
|
||||||
|
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
||||||
|
inherit (lib.strings) escape;
|
||||||
|
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:
|
||||||
${concatStringsSep "\n" settings}
|
if true == value then "1"
|
||||||
${cfg.extraConfig}
|
else if false == value then "0"
|
||||||
'';
|
else if builtins.isString value then "\"${escapeString value}\""
|
||||||
|
else toString value;
|
||||||
|
|
||||||
|
configFile = pkgs.writeText "davfs2.conf" (
|
||||||
|
if (cfg.settings != { }) then
|
||||||
|
(toINIWithGlobalSection {
|
||||||
|
mkSectionName = escapeString;
|
||||||
|
mkKeyValue = k: v: "${k} ${formatValue v}";
|
||||||
|
} cfg.settings)
|
||||||
|
else
|
||||||
|
cfg.extraConfig
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
||||||
options.services.davfs2 = {
|
options.services.davfs2 = {
|
||||||
enable = mkOption {
|
enable = mkEnableOption "davfs2";
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = lib.mdDoc ''
|
|
||||||
Whether to enable davfs2.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
davUser = mkOption {
|
davUser = mkOption {
|
||||||
type = types.str;
|
type = str;
|
||||||
default = "davfs2";
|
default = "davfs2";
|
||||||
description = lib.mdDoc ''
|
description = ''
|
||||||
When invoked by root the mount.davfs daemon will run as this user.
|
When invoked by root the mount.davfs daemon will run as this user.
|
||||||
Value must be given as name, not as numerical id.
|
Value must be given as name, not as numerical id.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
davGroup = mkOption {
|
davGroup = mkOption {
|
||||||
type = types.str;
|
type = str;
|
||||||
default = "davfs2";
|
default = "davfs2";
|
||||||
description = lib.mdDoc ''
|
description = ''
|
||||||
The group of the running mount.davfs daemon. Ordinary users must be
|
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
|
member of this group in order to mount a davfs2 file system. Value must
|
||||||
be given as name, not as numerical id.
|
be given as name, not as numerical id.
|
||||||
|
@ -48,14 +54,19 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
extraConfig = mkOption {
|
||||||
type = types.lines;
|
type = lines;
|
||||||
default = "";
|
default = "";
|
||||||
example = ''
|
example = ''
|
||||||
kernel_fs coda
|
|
||||||
proxy foo.bar:8080
|
proxy foo.bar:8080
|
||||||
use_locks 0
|
use_locks 0
|
||||||
|
|
||||||
|
[/media/dav]
|
||||||
|
use_locks 1
|
||||||
|
|
||||||
|
[/home/otto/mywebspace]
|
||||||
|
gui_optimize 1
|
||||||
'';
|
'';
|
||||||
description = lib.mdDoc ''
|
description = ''
|
||||||
Extra lines appended to the configuration of davfs2.
|
Extra lines appended to the configuration of davfs2.
|
||||||
See {manpage}`davfs2.conf(5)` for available settings.
|
See {manpage}`davfs2.conf(5)` for available settings.
|
||||||
|
|
||||||
|
@ -66,18 +77,30 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
type = types.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 = lib.mdDoc ''
|
description = ''
|
||||||
Extra settings appended to the configuration of davfs2.
|
Extra settings appended to the configuration of davfs2.
|
||||||
See {manpage}`davfs2.conf(5)` for available settings.
|
See {manpage}`davfs2.conf(5)` for available settings.
|
||||||
'' ;
|
'' ;
|
||||||
|
@ -86,16 +109,29 @@ in
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
warnings = lib.optional (cfg.extraConfig != null) ''
|
assertions = [
|
||||||
services.davfs2.extraConfig will be deprecated in future releases, please use the settings option now.
|
{
|
||||||
|
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.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.davfs2 ];
|
environment.systemPackages = [ pkgs.davfs2 ];
|
||||||
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") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user