nixos/services.webdav-server-rs: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-28 21:19:00 +02:00 committed by Jörg Thalheim
parent 43235a1a61
commit e71c09b8f8

View File

@ -1,10 +1,8 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.webdav-server-rs; cfg = config.services.webdav-server-rs;
format = pkgs.formats.toml { }; format = pkgs.formats.toml { };
settings = recursiveUpdate settings = lib.recursiveUpdate
{ {
server.uid = config.users.users."${cfg.user}".uid; server.uid = config.users.users."${cfg.user}".uid;
server.gid = config.users.groups."${cfg.group}".gid; server.gid = config.users.groups."${cfg.group}".gid;
@ -14,27 +12,27 @@ in
{ {
options = { options = {
services.webdav-server-rs = { services.webdav-server-rs = {
enable = mkEnableOption "WebDAV server"; enable = lib.mkEnableOption "WebDAV server";
user = mkOption { user = lib.mkOption {
type = types.str; type = lib.types.str;
default = "webdav"; default = "webdav";
description = "User to run under when setuid is not enabled."; description = "User to run under when setuid is not enabled.";
}; };
group = mkOption { group = lib.mkOption {
type = types.str; type = lib.types.str;
default = "webdav"; default = "webdav";
description = "Group to run under when setuid is not enabled."; description = "Group to run under when setuid is not enabled.";
}; };
debug = mkOption { debug = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Enable debug mode."; description = "Enable debug mode.";
}; };
settings = mkOption { settings = lib.mkOption {
type = format.type; type = format.type;
default = { }; default = { };
description = '' description = ''
@ -42,7 +40,7 @@ in
options can be found at options can be found at
[here](https://github.com/miquels/webdav-server-rs/blob/master/webdav-server.toml). [here](https://github.com/miquels/webdav-server-rs/blob/master/webdav-server.toml).
''; '';
example = literalExpression '' example = lib.literalExpression ''
{ {
server.listen = [ "0.0.0.0:4918" "[::]:4918" ]; server.listen = [ "0.0.0.0:4918" "[::]:4918" ];
accounts = { accounts = {
@ -75,8 +73,8 @@ in
''; '';
}; };
configFile = mkOption { configFile = lib.mkOption {
type = types.path; type = lib.types.path;
default = format.generate "webdav-server.toml" settings; default = format.generate "webdav-server.toml" settings;
defaultText = "Config file generated from services.webdav-server-rs.settings"; defaultText = "Config file generated from services.webdav-server-rs.settings";
description = '' description = ''
@ -88,19 +86,19 @@ in
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = hasAttr cfg.user config.users.users && config.users.users."${cfg.user}".uid != null; assertion = lib.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."; 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; assertion = lib.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."; message = "users.groups.${cfg.group} and users.groups.${cfg.group}.gid must be defined.";
} }
]; ];
users.users = optionalAttrs (cfg.user == "webdav") { users.users = lib.optionalAttrs (cfg.user == "webdav") {
webdav = { webdav = {
description = "WebDAV user"; description = "WebDAV user";
group = cfg.group; group = cfg.group;
@ -108,7 +106,7 @@ in
}; };
}; };
users.groups = optionalAttrs (cfg.group == "webdav") { users.groups = lib.optionalAttrs (cfg.group == "webdav") {
webdav.gid = config.ids.gids.webdav; webdav.gid = config.ids.gids.webdav;
}; };
@ -146,5 +144,5 @@ in
}; };
}; };
meta.maintainers = with maintainers; [ pmy ]; meta.maintainers = with lib.maintainers; [ pmy ];
} }