2017-12-10 01:55:05 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2024-04-08 23:12:29 +00:00
|
|
|
inherit (lib.attrsets) optionalAttrs;
|
|
|
|
inherit (lib.generators) toINIWithGlobalSection;
|
2024-04-08 22:45:48 +00:00
|
|
|
inherit (lib.lists) optional;
|
2024-06-20 11:58:55 +00:00
|
|
|
inherit (lib.modules) mkIf mkRemovedOptionModule;
|
2024-04-08 22:45:48 +00:00
|
|
|
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
2024-04-08 23:12:29 +00:00
|
|
|
inherit (lib.strings) escape;
|
|
|
|
inherit (lib.types) attrsOf bool int lines oneOf str submodule;
|
2024-04-08 22:45:48 +00:00
|
|
|
|
2017-12-10 01:55:05 +00:00
|
|
|
cfg = config.services.davfs2;
|
2024-04-08 23:12:29 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-04-11 20:08:08 +00:00
|
|
|
configFile = pkgs.writeText "davfs2.conf" (
|
2024-06-03 09:18:59 +00:00
|
|
|
toINIWithGlobalSection {
|
|
|
|
mkSectionName = escapeString;
|
|
|
|
mkKeyValue = k: v: "${k} ${formatValue v}";
|
|
|
|
} cfg.settings);
|
2017-12-10 01:55:05 +00:00
|
|
|
in
|
|
|
|
{
|
2024-03-18 21:01:29 +00:00
|
|
|
|
2024-06-20 11:58:55 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "davfs2" "extraConfig" ] ''
|
|
|
|
The option extraConfig got removed, please migrate to
|
|
|
|
services.davfs2.settings instead.
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
|
2017-12-10 01:55:05 +00:00
|
|
|
options.services.davfs2 = {
|
2024-04-08 22:45:48 +00:00
|
|
|
enable = mkEnableOption "davfs2";
|
2017-12-10 01:55:05 +00:00
|
|
|
|
|
|
|
davUser = mkOption {
|
2024-04-08 22:45:48 +00:00
|
|
|
type = str;
|
2017-12-10 01:55:05 +00:00
|
|
|
default = "davfs2";
|
2024-04-08 22:41:30 +00:00
|
|
|
description = ''
|
2017-12-10 01:55:05 +00:00
|
|
|
When invoked by root the mount.davfs daemon will run as this user.
|
|
|
|
Value must be given as name, not as numerical id.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
davGroup = mkOption {
|
2024-04-08 22:45:48 +00:00
|
|
|
type = str;
|
2017-12-10 01:55:05 +00:00
|
|
|
default = "davfs2";
|
2024-04-08 22:41:30 +00:00
|
|
|
description = ''
|
2017-12-10 01:55:05 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-03-18 21:01:29 +00:00
|
|
|
settings = mkOption {
|
2024-04-08 22:45:48 +00:00
|
|
|
type = submodule {
|
2024-04-08 23:12:29 +00:00
|
|
|
freeformType = let
|
|
|
|
valueTypes = [ bool int str ];
|
|
|
|
in
|
|
|
|
attrsOf (attrsOf (oneOf (valueTypes ++ [ (attrsOf (oneOf valueTypes)) ] )));
|
2024-03-18 21:01:29 +00:00
|
|
|
};
|
2024-04-08 23:12:29 +00:00
|
|
|
default = { };
|
2024-03-18 21:01:29 +00:00
|
|
|
example = literalExpression ''
|
|
|
|
{
|
2024-04-08 23:12:29 +00:00
|
|
|
globalSection = {
|
|
|
|
proxy = "foo.bar:8080";
|
|
|
|
use_locks = false;
|
|
|
|
};
|
|
|
|
sections = {
|
|
|
|
"/media/dav" = {
|
|
|
|
use_locks = true;
|
|
|
|
};
|
|
|
|
"/home/otto/mywebspace" = {
|
|
|
|
gui_optimize = true;
|
|
|
|
};
|
|
|
|
};
|
2024-03-18 21:01:29 +00:00
|
|
|
}
|
|
|
|
'';
|
2024-04-08 22:41:30 +00:00
|
|
|
description = ''
|
2024-03-18 21:01:29 +00:00
|
|
|
Extra settings appended to the configuration of davfs2.
|
|
|
|
See {manpage}`davfs2.conf(5)` for available settings.
|
2017-12-10 01:55:05 +00:00
|
|
|
'' ;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-03-18 21:01:29 +00:00
|
|
|
|
2017-12-10 01:55:05 +00:00
|
|
|
environment.systemPackages = [ pkgs.davfs2 ];
|
2024-03-18 21:01:29 +00:00
|
|
|
environment.etc."davfs2/davfs2.conf".source = configFile;
|
|
|
|
|
|
|
|
services.davfs2.settings = {
|
2024-04-08 23:12:29 +00:00
|
|
|
globalSection = {
|
|
|
|
dav_user = cfg.davUser;
|
|
|
|
dav_group = cfg.davGroup;
|
|
|
|
};
|
2024-03-18 21:01:29 +00:00
|
|
|
};
|
2017-12-10 01:55:05 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups = optionalAttrs (cfg.davGroup == "davfs2") {
|
|
|
|
davfs2.gid = config.ids.gids.davfs2;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users = optionalAttrs (cfg.davUser == "davfs2") {
|
|
|
|
davfs2 = {
|
|
|
|
createHome = false;
|
|
|
|
group = cfg.davGroup;
|
|
|
|
uid = config.ids.uids.davfs2;
|
|
|
|
description = "davfs2 user";
|
|
|
|
};
|
|
|
|
};
|
2017-12-10 01:55:05 +00:00
|
|
|
|
2021-05-10 13:54:52 +00:00
|
|
|
security.wrappers."mount.davfs" = {
|
|
|
|
program = "mount.davfs";
|
|
|
|
source = "${pkgs.davfs2}/bin/mount.davfs";
|
|
|
|
owner = "root";
|
|
|
|
group = cfg.davGroup;
|
|
|
|
setuid = true;
|
|
|
|
permissions = "u+rx,g+x";
|
|
|
|
};
|
|
|
|
|
|
|
|
security.wrappers."umount.davfs" = {
|
|
|
|
program = "umount.davfs";
|
|
|
|
source = "${pkgs.davfs2}/bin/umount.davfs";
|
|
|
|
owner = "root";
|
|
|
|
group = cfg.davGroup;
|
|
|
|
setuid = true;
|
|
|
|
permissions = "u+rx,g+x";
|
|
|
|
};
|
|
|
|
|
2017-12-10 01:55:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|