1 { config, lib, pkgs, ... }:
4 inherit (lib.attrsets) optionalAttrs;
5 inherit (lib.generators) toINIWithGlobalSection;
6 inherit (lib.lists) optional;
7 inherit (lib.modules) mkIf mkRemovedOptionModule;
8 inherit (lib.options) literalExpression mkEnableOption mkOption;
9 inherit (lib.strings) escape;
10 inherit (lib.types) attrsOf bool int lines oneOf str submodule;
12 cfg = config.services.davfs2;
14 escapeString = escape ["\"" "\\"];
17 if true == value then "1"
18 else if false == value then "0"
19 else if builtins.isString value then "\"${escapeString value}\""
22 configFile = pkgs.writeText "davfs2.conf" (
23 toINIWithGlobalSection {
24 mkSectionName = escapeString;
25 mkKeyValue = k: v: "${k} ${formatValue v}";
31 (mkRemovedOptionModule [ "services" "davfs2" "extraConfig" ] ''
32 The option extraConfig got removed, please migrate to
33 services.davfs2.settings instead.
37 options.services.davfs2 = {
38 enable = mkEnableOption "davfs2";
44 When invoked by root the mount.davfs daemon will run as this user.
45 Value must be given as name, not as numerical id.
53 The group of the running mount.davfs daemon. Ordinary users must be
54 member of this group in order to mount a davfs2 file system. Value must
55 be given as name, not as numerical id.
62 valueTypes = [ bool int str ];
64 attrsOf (attrsOf (oneOf (valueTypes ++ [ (attrsOf (oneOf valueTypes)) ] )));
67 example = literalExpression ''
70 proxy = "foo.bar:8080";
77 "/home/otto/mywebspace" = {
84 Extra settings appended to the configuration of davfs2.
85 See {manpage}`davfs2.conf(5)` for available settings.
90 config = mkIf cfg.enable {
92 environment.systemPackages = [ pkgs.davfs2 ];
93 environment.etc."davfs2/davfs2.conf".source = configFile;
95 services.davfs2.settings = {
97 dav_user = cfg.davUser;
98 dav_group = cfg.davGroup;
102 users.groups = optionalAttrs (cfg.davGroup == "davfs2") {
103 davfs2.gid = config.ids.gids.davfs2;
106 users.users = optionalAttrs (cfg.davUser == "davfs2") {
109 group = cfg.davGroup;
110 uid = config.ids.uids.davfs2;
111 description = "davfs2 user";
115 security.wrappers."mount.davfs" = {
116 program = "mount.davfs";
117 source = "${pkgs.davfs2}/bin/mount.davfs";
119 group = cfg.davGroup;
121 permissions = "u+rx,g+x";
124 security.wrappers."umount.davfs" = {
125 program = "umount.davfs";
126 source = "${pkgs.davfs2}/bin/umount.davfs";
128 group = cfg.davGroup;
130 permissions = "u+rx,g+x";