1{
2 config,
3 lib,
4 pkgs,
5 ...
6}: let
7 name = "webdav";
8 cfg = config.myNixOS.services.${name};
9
10 network = config.mySnippets.tailnet;
11 service = network.networkMap.${name};
12
13 dataDirectory = "/var/lib";
14in {
15 options.myNixOS.services.${name} = {
16 enable = lib.mkEnableOption "${name} server";
17 autoProxy = lib.mkOption {
18 default = true;
19 example = false;
20 description = "${name} auto proxy";
21 type = lib.types.bool;
22 };
23 };
24
25 config = lib.mkIf cfg.enable {
26 services = {
27 caddy.virtualHosts."${service.vHost}".extraConfig = lib.mkIf cfg.autoProxy ''
28 bind tailscale/${name}
29 encode zstd gzip
30 reverse_proxy ${service.hostName}:${toString service.port}
31 '';
32
33 webdav-server-rs = {
34 enable = true;
35 settings = {
36 server.listen = ["0.0.0.0:${toString service.port}" "[::]:${toString service.port}"];
37 accounts = {
38 auth-type = "htpasswd.default";
39 acct-type = "unix";
40 };
41 htpasswd.default = {
42 htpasswd = pkgs.writeText "htpasswd" ''
43 ayla:$2y$05$LD.VqJF.yVGsp.C3L6IJFO0SvYTeCKbGoGn70ZQaht4gxyEq2XbCS
44 '';
45 };
46 location = [
47 {
48 route = ["/*path"];
49 directory = "${dataDirectory}/webdav";
50 handler = "filesystem";
51 methods = ["webdav-rw"];
52 autoindex = true;
53 auth = "true";
54 }
55 ];
56 };
57 };
58 };
59
60 systemd.tmpfiles.rules = [
61 "d /var/lib/webdav 0755 webdav webdav - -"
62 ];
63 };
64}