Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webdav-server-rs #146965

Merged
merged 4 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8967,12 +8967,6 @@
githubId = 8641;
name = "Pierre Carrier";
};
pengmeiyu = {
email = "[email protected]";
github = "pmeiyu";
githubId = 8529551;
name = "Peng Mei Yu";
};
penguwin = {
email = "[email protected]";
github = "penguwin";
Expand Down Expand Up @@ -9248,6 +9242,12 @@
githubId = 178496;
name = "Philipp Middendorf";
};
pmy = {
email = "[email protected]";
github = "pmeiyu";
githubId = 8529551;
name = "Peng Mei Yu";
};
pmyjavec = {
email = "[email protected]";
github = "pmyjavec";
Expand Down
2 changes: 2 additions & 0 deletions nixos/modules/misc/ids.nix
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ in
hqplayer = 319;
moonraker = 320;
distcc = 321;
webdav = 322;

# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!

Expand Down Expand Up @@ -656,6 +657,7 @@ in
hqplayer = 319;
moonraker = 320;
distcc = 321;
webdav = 322;

# When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@
./services/network-filesystems/diod.nix
./services/network-filesystems/u9fs.nix
./services/network-filesystems/webdav.nix
./services/network-filesystems/webdav-server-rs.nix
./services/network-filesystems/yandex-disk.nix
./services/network-filesystems/xtreemfs.nix
./services/network-filesystems/ceph.nix
Expand Down
144 changes: 144 additions & 0 deletions nixos/modules/services/network-filesystems/webdav-server-rs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{ config, lib, pkgs, ... }:

with lib;
let
cfg = config.services.webdav-server-rs;
format = pkgs.formats.toml { };
settings = recursiveUpdate
{
server.uid = config.users.users."${cfg.user}".uid;
server.gid = config.users.groups."${cfg.group}".gid;
aanderse marked this conversation as resolved.
Show resolved Hide resolved
}
cfg.settings;
in
{
options = {
services.webdav-server-rs = {
enable = mkEnableOption "WebDAV server";

user = mkOption {
type = types.str;
default = "webdav";
description = "User to run under when setuid is not enabled.";
};

group = mkOption {
type = types.str;
default = "webdav";
description = "Group to run under when setuid is not enabled.";
};

settings = mkOption {
type = format.type;
default = { };
description = ''
Attrset that is converted and passed as config file. Available
options can be found at
<link xlink:href="https://github.com/miquels/webdav-server-rs/blob/master/webdav-server.toml">here</link>.
'';
example = literalExpression ''
{
server.listen = [ "0.0.0.0:4918" "[::]:4918" ];
accounts = {
auth-type = "htpasswd.default";
acct-type = "unix";
};
htpasswd.default = {
htpasswd = "/etc/htpasswd";
};
location = [
{
route = [ "/public/*path" ];
directory = "/srv/public";
handler = "filesystem";
methods = [ "webdav-ro" ];
autoindex = true;
auth = "false";
}
{
route = [ "/user/:user/*path" ];
directory = "~";
handler = "filesystem";
methods = [ "webdav-rw" ];
autoindex = true;
auth = "true";
setuid = true;
}
];
}
'';
};

configFile = mkOption {
type = types.path;
default = format.generate "webdav-server.toml" settings;
defaultText = "Config file generated from services.webdav-server-rs.settings";
description = ''
Path to config file. If this option is set, it will override any
configuration done in services.webdav-server-rs.settings.
'';
example = "/etc/webdav-server.toml";
};
};
};

config = mkIf cfg.enable {
assertions = [
{
assertion = hasAttr cfg.user config.users.users && config.users.users."${cfg.user}".uid != null;
message = "users.users.${cfg.user} and users.users.${cfg.user}.uid must be defined.";
}
{
assertion = hasAttr cfg.group config.users.groups && config.users.groups."${cfg.group}".gid != null;
message = "users.groups.${cfg.group} and users.groups.${cfg.group}.gid must be defined.";
}
];

users.users = optionalAttrs (cfg.user == "webdav") {
webdav = {
description = "WebDAV user";
group = cfg.group;
uid = config.ids.uids.webdav;
};
};

users.groups = optionalAttrs (cfg.group == "webdav") {
webdav.gid = config.ids.gids.webdav;
};

systemd.services.webdav-server-rs = {
description = "WebDAV server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
aanderse marked this conversation as resolved.
Show resolved Hide resolved
ExecStart = "${pkgs.webdav-server-rs}/bin/webdav-server -c ${cfg.configFile}";

CapabilityBoundingSet = [
"CAP_SETUID"
"CAP_SETGID"
];

NoExecPaths = [ "/" ];
ExecPaths = [ "/nix/store" ];

# This program actively detects if it is running in root user account
# when it starts and uses root privilege to switch process uid to
# respective unix user when a user logs in. Maybe we can enable
# DynamicUser in the future when it's able to detect CAP_SETUID and
# CAP_SETGID capabilities.

NoNewPrivileges = true;
PrivateDevices = true;
PrivateTmp = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectSystem = true;
};
};
};

meta.maintainers = with maintainers; [ pmy ];
}
6 changes: 3 additions & 3 deletions nixos/modules/services/network-filesystems/webdav.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ in
users.users = mkIf (cfg.user == "webdav") {
webdav = {
description = "WebDAV daemon user";
isSystemUser = true;
group = cfg.group;
uid = config.ids.uids.webdav;
};
};

users.groups = mkIf (cfg.group == "webdav") {
webdav = { };
webdav.gid = config.ids.gids.webdav;
};

systemd.services.webdav = {
Expand All @@ -103,5 +103,5 @@ in
};
};

meta.maintainers = with maintainers; [ pengmeiyu ];
meta.maintainers = with maintainers; [ pmy ];
}
2 changes: 1 addition & 1 deletion pkgs/data/misc/rime-data/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ stdenv.mkDerivation {
# rime-cantonese
cc-by-40
];
maintainers = [ maintainers.pengmeiyu ];
maintainers = with maintainers; [ pmy ];
};
}
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/lm-sensors/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ stdenv.mkDerivation rec {
changelog = "https://raw.githubusercontent.com/lm-sensors/lm-sensors/V${dashedVersion}/CHANGES";
description = "Tools for reading hardware sensors";
license = with licenses; [ lgpl21Plus gpl2Plus ];
maintainers = with maintainers; [ pengmeiyu ];
maintainers = with maintainers; [ pmy ];
platforms = platforms.linux;
mainProgram = "sensors";
};
Expand Down
47 changes: 47 additions & 0 deletions pkgs/servers/webdav-server-rs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{ lib
, stdenv
, fetchFromGitHub
, rustPlatform
, libtirpc
, pam
, rpcsvc-proto
, enablePAM ? stdenv.isLinux
}:

rustPlatform.buildRustPackage rec {
pname = "webdav-server-rs";
# The v0.4.0 tag cannot build. So we use the 547602e commit.
pmeiyu marked this conversation as resolved.
Show resolved Hide resolved
version = "unstable-2021-08-16";

src = fetchFromGitHub {
owner = "miquels";
repo = pname;
rev = "547602e78783935b4ddd038fb795366c9c476bcc";
sha256 = "sha256-nTygUEjAUXD0mRTmjt8/UPVfZA4rP6oop1s/fI5mYeg=";
};

cargoHash = "sha256-TDDfGQig4i/DpsilTPqMQ1oT0mXK5DKlZmwsPPLrzFc=";

buildInputs = [ libtirpc ] ++ lib.optional enablePAM pam;
nativeBuildInputs = [ rpcsvc-proto ];

buildNoDefaultFeatures = true;
buildFeatures = [ "quota" ] ++ lib.optional enablePAM "pam";

postPatch = ''
substituteInPlace fs_quota/build.rs \
--replace '/usr/include/tirpc' '${libtirpc.dev}/include/tirpc'
'';

meta = with lib; {
description = "An implementation of WebDAV server in Rust";
longDescription = ''
webdav-server-rs is an implementation of WebDAV with full support for
RFC4918. It also supports local unix accounts, PAM authentication, and
quota.
'';
homepage = "https://github.com/miquels/webdav-server-rs";
license = licenses.asl20;
maintainers = with maintainers; [ pmy ];
};
}
2 changes: 1 addition & 1 deletion pkgs/servers/webdav/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ buildGoModule rec {
description = "Simple WebDAV server";
homepage = "https://github.com/hacdias/webdav";
license = licenses.mit;
maintainers = with maintainers; [ pengmeiyu ];
maintainers = with maintainers; [ pmy ];
};
}
2 changes: 1 addition & 1 deletion pkgs/tools/inputmethods/ibus-engines/ibus-rime/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ stdenv.mkDerivation rec {
homepage = "https://rime.im/";
license = licenses.gpl3Plus;
platforms = platforms.linux;
maintainers = with maintainers; [ pengmeiyu ];
maintainers = with maintainers; [ pmy ];
};
}
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21697,6 +21697,8 @@ with pkgs;

webdav = callPackage ../servers/webdav { };

webdav-server-rs = callPackage ../servers/webdav-server-rs { };

webmetro = callPackage ../servers/webmetro { };

wsdd = callPackage ../servers/wsdd { };
Expand Down