是否可以在 NixOS 和 NixOps 中以声明的方式管理组?
我希望能够在 中创建新组configuration.nix
并向其中添加用户。我找不到任何可用选项来执行此操作,并且手动添加的组被新的 nixops 部署删除时出现问题。
我尝试过的方法
我尝试修改文件中服务创建的用户组configuration.nix
:
system.activationScripts = {
mediaGroup = ''
echo "Adding `media` group"
getent group media || groupadd media
'';
};
users.users.plex.extraGroups = [ "media" ];
users.users.radarr.extraGroups = [ "media" ];
users.users.sonarr.extraGroups = [ "media" ];
users.users.deluge.extraGroups = [ "media" ];
还可以通过修改服务 plex、radarr、sonarr 和 deluge 来采用附加组选项:
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.sonarr;
in
{
options = {
services.sonarr = {
openFirewall = mkOption {
type = types.bool;
default = false;
description = ''
Open ports in the firewall for the media server
'';
};
user = mkOption {
type = types.str;
default = "sonarr";
description = "User account under which sonarr runs.";
};
group = mkOption {
type = types.str;
default = "sonarr";
description = "Group under which sonarr runs.";
};
};
};
config = mkIf cfg.enable {
systemd.services.sonarr = pkgs.lib.mkForce {
description = "Sonarr";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart = ''
test -d /var/lib/sonarr/ || {
echo "Creating sonarr data directory in /var/lib/sonarr/"
mkdir -p /var/lib/sonarr/
}
chown -R ${cfg.user}:${cfg.group} /var/lib/sonarr/
chmod 0700 /var/lib/sonarr/
'';
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
PermissionsStartOnly = "true";
ExecStart = "${pkgs.sonarr}/bin/NzbDrone --no-browser";
Restart = "on-failure";
};
};
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ 8989 ];
};
users.users = mkIf (cfg.user == "sonarr") {
sonarr = pkgs.lib.mkForce {
uid = config.ids.uids.sonarr;
home = "/var/lib/sonarr";
group = cfg.group;
extraGroups = [ "media" ];
};
};
users.groups = mkIf (cfg.group == "sonarr") {
sonarr = pkgs.lib.mkForce {
gid = config.ids.gids.sonarr;
};
};
};
}
每次nixops deploy
我都会得到:
my_server...> activating the configuration...
my_server...> removing group ‘media’
my_server...> warning: user ‘media’ has unknown group ‘media’
my_server...> warning: user ‘plex’ has unknown group ‘media’
my_server...> warning: user ‘radarr’ has unknown group ‘media’
my_server...> warning: user ‘sonarr’ has unknown group ‘media’
如果我检查每个用户组,即使我手动将用户添加到组中,也会得到以下信息usermod
:
[root@my_server:/var/lib]# groups sonarr
sonarr : nogroup
语境
这些服务之间缺少共享组,导致权限问题,导致 sonarr 和 radarr 无法自动将文件从 deluge 复制到 plex 媒体位置。我认为这是它工作的唯一问题,我还配置了 deluge 服务以使用 of umask
,002
权限似乎是正确的。
[root@my_server:/var/lib/deluge/Downloads]# ls -l && cd MovieFolder && ls -l
drwxrwxr-- 2 deluge media 4096 Aug 26 11:39 MovieFolder
-rw-rw-r-- 1 deluge media 2420763104 Aug 26 11:08 TheMovie.mkv
还有来自 sonarr 和 radarr 的消息:
No files found are eligible for import in /var/lib/deluge/Downloads/MovieFolder
以下是一个示例日志消息:
18-8-26 12:47:51.3|Error|DownloadedEpisodesImportService|Import failed, path does not exist or is not accessible by Sonarr: /var/lib/deluge/Downloads/MovieFolder
答案1
media
您还需要定义该组。
首先明确定义它:
users.groups.media = {};
users.users.plex.extraGroups = [ "media" ];
或者立即将成员添加到群组:
users.groups.media.members = [ ... ];