refactor: abstract app user creation via custom options
This commit is contained in:
parent
1403b1f9c0
commit
d742671460
7 changed files with 52 additions and 36 deletions
|
|
@ -95,22 +95,17 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
# Create a user for each app.
|
# Create a user for each app.
|
||||||
users.users = let
|
homelab.appUsers = let
|
||||||
mkUser = uid: {
|
mkUser = uid: {
|
||||||
uid = lib.mkForce uid;
|
inherit uid;
|
||||||
isSystemUser = true;
|
|
||||||
group = config.users.groups.media.name;
|
group = config.users.groups.media.name;
|
||||||
home = "/var/empty";
|
|
||||||
shell = null;
|
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
bazarr = lib.mkIf cfg.bazarr.enable (mkUser 3003);
|
bazarr = lib.mkIf cfg.bazarr.enable (mkUser 3003);
|
||||||
prowlarr = lib.mkIf cfg.prowlarr.enable (mkUser 3004);
|
prowlarr = lib.mkIf cfg.prowlarr.enable (mkUser 3004);
|
||||||
qbittorrent = lib.mkIf cfg.qbittorrent.enable (mkUser 3005) // {
|
qbittorrent = lib.mkIf cfg.qbittorrent.enable ((mkUser 3005) // {
|
||||||
extraGroups = [
|
extraGroups = [ config.users.groups.apps.name ];
|
||||||
config.users.groups.apps.name
|
});
|
||||||
];
|
|
||||||
};
|
|
||||||
radarr = lib.mkIf cfg.radarr.enable (mkUser 3006);
|
radarr = lib.mkIf cfg.radarr.enable (mkUser 3006);
|
||||||
sonarr = lib.mkIf cfg.sonarr.enable (mkUser 3007);
|
sonarr = lib.mkIf cfg.sonarr.enable (mkUser 3007);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,9 @@ in {
|
||||||
virtualisation.containers.enable = true;
|
virtualisation.containers.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.calibre = {
|
homelab.appUsers.calibre = {
|
||||||
uid = lib.mkForce 3010;
|
uid = 3010;
|
||||||
isSystemUser = true;
|
|
||||||
group = config.users.groups.media.name;
|
group = config.users.groups.media.name;
|
||||||
home = "/var/empty";
|
|
||||||
shell = null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
homelab.nfsMounts."${books}" = {
|
homelab.nfsMounts."${books}" = {
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,8 @@ in {
|
||||||
virtualisation.containers.enable = true;
|
virtualisation.containers.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.gitea = {
|
homelab.appUsers.gitea = {
|
||||||
uid = lib.mkForce UID;
|
uid = UID;
|
||||||
isSystemUser = true;
|
|
||||||
group = config.users.groups.apps.name;
|
|
||||||
home = "/var/empty";
|
|
||||||
shell = null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Use filesystem mounts because rootless containers otherwise don't have access to the mount path (nested in docker directories).
|
# Use filesystem mounts because rootless containers otherwise don't have access to the mount path (nested in docker directories).
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,8 @@ in {
|
||||||
virtualisation.containers.enable = true;
|
virtualisation.containers.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.homepage = {
|
homelab.appUsers.homepage = {
|
||||||
uid = lib.mkForce 3018;
|
uid = 3018;
|
||||||
isSystemUser = true;
|
|
||||||
group = config.users.groups.apps.name;
|
|
||||||
home = "/var/empty";
|
|
||||||
shell = null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
homelab.nfsMounts."${homepage-config}" = {
|
homelab.nfsMounts."${homepage-config}" = {
|
||||||
|
|
|
||||||
|
|
@ -36,15 +36,9 @@ in {
|
||||||
"/srv/photo" = mkMount "192.168.0.11:/mnt/BIG/MEDIA/PHOTO/ARCHIVE";
|
"/srv/photo" = mkMount "192.168.0.11:/mnt/BIG/MEDIA/PHOTO/ARCHIVE";
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.jellyfin = {
|
homelab.appUsers.jellyfin = {
|
||||||
uid = lib.mkForce UID;
|
uid = UID;
|
||||||
isSystemUser = true;
|
extraGroups = [ config.users.groups.media.name ];
|
||||||
group = config.users.groups.apps.name;
|
|
||||||
extraGroups = [
|
|
||||||
config.users.groups.media.name
|
|
||||||
];
|
|
||||||
home = "/var/empty";
|
|
||||||
shell = null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Make sure the Docker network exists.
|
# Make sure the Docker network exists.
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
./docker.nix
|
./docker.nix
|
||||||
./monitoring.nix
|
./monitoring.nix
|
||||||
./nfs.nix
|
./nfs.nix
|
||||||
|
./users.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
|
||||||
37
modules/common/users.nix
Normal file
37
modules/common/users.nix
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
options.homelab.appUsers = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (lib.types.submodule {
|
||||||
|
options = {
|
||||||
|
uid = lib.mkOption {
|
||||||
|
type = lib.types.int;
|
||||||
|
description = "The user ID for the app user";
|
||||||
|
};
|
||||||
|
group = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = config.users.groups.apps.name;
|
||||||
|
description = "The primary group for the app user";
|
||||||
|
};
|
||||||
|
extraGroups = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [];
|
||||||
|
description = "Extra groups for the app user";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = {};
|
||||||
|
description = "App users to automatically create with standard homelab options";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
users.users = lib.mapAttrs (name: cfg: {
|
||||||
|
uid = lib.mkForce cfg.uid;
|
||||||
|
isSystemUser = true;
|
||||||
|
group = cfg.group;
|
||||||
|
extraGroups = cfg.extraGroups;
|
||||||
|
home = "/var/empty";
|
||||||
|
shell = null;
|
||||||
|
}) config.homelab.appUsers;
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue