1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.davfs2;
7 cfgFile = pkgs.writeText "davfs2.conf" ''
8 dav_user ${cfg.davUser}
9 dav_group ${cfg.davGroup}
10 ${cfg.extraConfig}
11 '';
12in
13{
14 options.services.davfs2 = {
15 enable = mkOption {
16 type = types.bool;
17 default = false;
18 description = ''
19 Whether to enable davfs2.
20 '';
21 };
22
23 davUser = mkOption {
24 type = types.string;
25 default = "davfs2";
26 description = ''
27 When invoked by root the mount.davfs daemon will run as this user.
28 Value must be given as name, not as numerical id.
29 '';
30 };
31
32 davGroup = mkOption {
33 type = types.string;
34 default = "davfs2";
35 description = ''
36 The group of the running mount.davfs daemon. Ordinary users must be
37 member of this group in order to mount a davfs2 file system. Value must
38 be given as name, not as numerical id.
39 '';
40 };
41
42 extraConfig = mkOption {
43 type = types.lines;
44 default = "";
45 example = ''
46 kernel_fs coda
47 proxy foo.bar:8080
48 use_locks 0
49 '';
50 description = ''
51 Extra lines appended to the configuration of davfs2.
52 '' ;
53 };
54 };
55
56 config = mkIf cfg.enable {
57 environment.systemPackages = [ pkgs.davfs2 ];
58 environment.etc."davfs2/davfs2.conf".source = cfgFile;
59
60 users.groups = optionalAttrs (cfg.davGroup == "davfs2") (singleton {
61 name = "davfs2";
62 gid = config.ids.gids.davfs2;
63 });
64
65 users.users = optionalAttrs (cfg.davUser == "davfs2") (singleton {
66 name = "davfs2";
67 createHome = false;
68 group = cfg.davGroup;
69 uid = config.ids.uids.davfs2;
70 description = "davfs2 user";
71 });
72 };
73
74}