diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 5d075d1aa299..9eca0b8d65f2 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -684,6 +684,7 @@ ./services/network-filesystems/tahoe.nix ./services/network-filesystems/diod.nix ./services/network-filesystems/u9fs.nix + ./services/network-filesystems/webdav.nix ./services/network-filesystems/yandex-disk.nix ./services/network-filesystems/xtreemfs.nix ./services/network-filesystems/ceph.nix diff --git a/nixos/modules/services/network-filesystems/webdav.nix b/nixos/modules/services/network-filesystems/webdav.nix new file mode 100644 index 000000000000..4086a0f5d562 --- /dev/null +++ b/nixos/modules/services/network-filesystems/webdav.nix @@ -0,0 +1,107 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + cfg = config.services.webdav; + format = pkgs.formats.yaml { }; +in +{ + options = { + services.webdav = { + enable = mkEnableOption "WebDAV server"; + + user = mkOption { + type = types.str; + default = "webdav"; + description = "User account under which WebDAV runs."; + }; + + group = mkOption { + type = types.str; + default = "webdav"; + description = "Group under which WebDAV runs."; + }; + + settings = mkOption { + type = format.type; + default = { }; + description = '' + Attrset that is converted and passed as config file. Available options + can be found at + here. + + This program supports reading username and password configuration + from environment variables, so it's strongly recommended to store + username and password in a separate + EnvironmentFile. + This prevents adding secrets to the world-readable Nix store. + ''; + example = literalExpression '' + { + address = "0.0.0.0"; + port = 8080; + scope = "/srv/public"; + modify = true; + auth = true; + users = [ + { + username = "{env}ENV_USERNAME"; + password = "{env}ENV_PASSWORD"; + } + ]; + } + ''; + }; + + configFile = mkOption { + type = types.path; + default = format.generate "webdav.yaml" cfg.settings; + defaultText = "Config file generated from services.webdav.settings"; + description = '' + Path to config file. If this option is set, it will override any + configuration done in options.services.webdav.settings. + ''; + example = "/etc/webdav/config.yaml"; + }; + + environmentFile = mkOption { + type = types.nullOr types.path; + default = null; + description = '' + Environment file as defined in + systemd.exec5 + . + ''; + }; + }; + }; + + config = mkIf cfg.enable { + users.users = mkIf (cfg.user == "webdav") { + webdav = { + description = "WebDAV daemon user"; + isSystemUser = true; + group = cfg.group; + }; + }; + + users.groups = mkIf (cfg.group == "webdav") { + webdav = { }; + }; + + systemd.services.webdav = { + description = "WebDAV server"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${pkgs.webdav}/bin/webdav -c ${cfg.configFile}"; + Restart = "on-failure"; + User = cfg.user; + Group = cfg.group; + EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]; + }; + }; + }; + + meta.maintainers = with maintainers; [ pengmeiyu ]; +} diff --git a/pkgs/servers/webdav/default.nix b/pkgs/servers/webdav/default.nix new file mode 100644 index 000000000000..2e6a6a891ecf --- /dev/null +++ b/pkgs/servers/webdav/default.nix @@ -0,0 +1,22 @@ +{ lib, stdenv, fetchFromGitHub, buildGoModule }: + +buildGoModule rec { + pname = "webdav"; + version = "4.1.1"; + + src = fetchFromGitHub { + owner = "hacdias"; + repo = "webdav"; + rev = "v${version}"; + sha256 = "0jnh1bhc98vcx2vm6hmgak6zwfc0rx898qcdjcca5y9dni4120aq"; + }; + + vendorSha256 = "19nhz6z8h4fxpy4gjx7zz69si499jak7qj9yb17x32lar5m88gvb"; + + meta = with lib; { + description = "Simple WebDAV server"; + homepage = "https://github.com/hacdias/webdav"; + license = licenses.mit; + maintainers = with maintainers; [ pengmeiyu ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f7260012f524..50e7d82d6e8c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -21619,6 +21619,8 @@ with pkgs; wallabag = callPackage ../servers/web-apps/wallabag { }; + webdav = callPackage ../servers/webdav { }; + webmetro = callPackage ../servers/webmetro { }; wsdd = callPackage ../servers/wsdd { };