-
Notifications
You must be signed in to change notification settings - Fork 4
/
davfs.nix
100 lines (87 loc) · 2.86 KB
/
davfs.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ config, pkgs, lib, ... }:
let
cfg = config.shb.davfs;
shblib = pkgs.callPackage ../../lib {};
in
{
options.shb.davfs = {
mounts = lib.mkOption {
description = "List of mounts.";
default = [];
type = lib.types.listOf (lib.types.submodule {
options = {
remoteUrl = lib.mkOption {
type = lib.types.str;
description = "Webdav endpoint to connect to.";
example = "https://my.domain.com/dav";
};
mountPoint = lib.mkOption {
type = lib.types.str;
description = "Mount point to mount the webdav endpoint on.";
example = "/mnt";
};
username = lib.mkOption {
type = lib.types.str;
description = "Username to connect to the webdav endpoint.";
};
passwordFile = lib.mkOption {
type = lib.types.str;
description = "Password to connect to the webdav endpoint.";
};
uid = lib.mkOption {
type = lib.types.nullOr lib.types.int;
description = "User owner of the mount point.";
example = 1000;
default = null;
};
gid = lib.mkOption {
type = lib.types.nullOr lib.types.int;
description = "Group owner of the mount point.";
example = 1000;
default = null;
};
fileMode = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "File creation mode";
example = "0664";
default = null;
};
directoryMode = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Directory creation mode";
example = "2775";
default = null;
};
automount = lib.mkOption {
type = lib.types.bool;
description = "Create a systemd automount unit";
default = true;
};
};
});
};
};
config = {
services.davfs2.enable = builtins.length cfg.mounts > 0;
systemd.mounts =
let
mkMountCfg = c: {
enable = true;
description = "Webdav mount point";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
what = c.remoteUrl;
where = c.mountPoint;
options = lib.concatStringsSep "," (
(lib.optional (!(isNull c.uid)) "uid=${toString c.uid}")
++ (lib.optional (!(isNull c.gid)) "gid=${toString c.uid}")
++ (lib.optional (!(isNull c.fileMode)) "file_mode=${toString c.fileMode}")
++ (lib.optional (!(isNull c.directoryMode)) "dir_mode=${toString c.directoryMode}")
);
type = "davfs";
mountConfig.TimeoutSec = 15;
};
in
map mkMountCfg cfg.mounts;
};
}