1{ config, lib, pkgs, ... }: 2 3with lib; 4let 5 cfg = config.services.webdav; 6 format = pkgs.formats.yaml { }; 7in 8{ 9 options = { 10 services.webdav = { 11 enable = mkEnableOption (lib.mdDoc "WebDAV server"); 12 13 user = mkOption { 14 type = types.str; 15 default = "webdav"; 16 description = lib.mdDoc "User account under which WebDAV runs."; 17 }; 18 19 group = mkOption { 20 type = types.str; 21 default = "webdav"; 22 description = lib.mdDoc "Group under which WebDAV runs."; 23 }; 24 25 settings = mkOption { 26 type = format.type; 27 default = { }; 28 description = lib.mdDoc '' 29 Attrset that is converted and passed as config file. Available options 30 can be found at 31 [here](https://github.com/hacdias/webdav). 32 33 This program supports reading username and password configuration 34 from environment variables, so it's strongly recommended to store 35 username and password in a separate 36 [EnvironmentFile](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#EnvironmentFile=). 37 This prevents adding secrets to the world-readable Nix store. 38 ''; 39 example = literalExpression '' 40 { 41 address = "0.0.0.0"; 42 port = 8080; 43 scope = "/srv/public"; 44 modify = true; 45 auth = true; 46 users = [ 47 { 48 username = "{env}ENV_USERNAME"; 49 password = "{env}ENV_PASSWORD"; 50 } 51 ]; 52 } 53 ''; 54 }; 55 56 configFile = mkOption { 57 type = types.path; 58 default = format.generate "webdav.yaml" cfg.settings; 59 defaultText = "Config file generated from services.webdav.settings"; 60 description = lib.mdDoc '' 61 Path to config file. If this option is set, it will override any 62 configuration done in options.services.webdav.settings. 63 ''; 64 example = "/etc/webdav/config.yaml"; 65 }; 66 67 environmentFile = mkOption { 68 type = types.nullOr types.path; 69 default = null; 70 description = lib.mdDoc '' 71 Environment file as defined in {manpage}`systemd.exec(5)`. 72 ''; 73 }; 74 }; 75 }; 76 77 config = mkIf cfg.enable { 78 users.users = mkIf (cfg.user == "webdav") { 79 webdav = { 80 description = "WebDAV daemon user"; 81 group = cfg.group; 82 uid = config.ids.uids.webdav; 83 }; 84 }; 85 86 users.groups = mkIf (cfg.group == "webdav") { 87 webdav.gid = config.ids.gids.webdav; 88 }; 89 90 systemd.services.webdav = { 91 description = "WebDAV server"; 92 after = [ "network.target" ]; 93 wantedBy = [ "multi-user.target" ]; 94 serviceConfig = { 95 ExecStart = "${pkgs.webdav}/bin/webdav -c ${cfg.configFile}"; 96 Restart = "on-failure"; 97 User = cfg.user; 98 Group = cfg.group; 99 EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]; 100 }; 101 }; 102 }; 103 104 meta.maintainers = with maintainers; [ pmy ]; 105}