fixed postgres config for forgejo

This commit is contained in:
Leyla Becker 2025-01-02 17:22:05 -06:00
parent 9ecba48dcf
commit 8f59f8aeca
5 changed files with 55 additions and 52 deletions

View file

@ -69,6 +69,10 @@
enable = true;
subdomain = "media";
};
forgejo = {
enable = true;
subdomain = "git";
};
};
networking = {
hostId = "c51763d6";

View file

@ -2,7 +2,8 @@
imports = [
./network_storage
./reverse_proxy.nix
./jellyfin.nix
./postgres.nix
./jellyfin.nix
./forgejo.nix
];
}

View file

@ -17,6 +17,21 @@ in {
config =
lib.mkIf config.host.forgejo.enable
{
host = {
reverse_proxy.subdomains.${config.host.forgejo.subdomain} = {
target = "http://localhost:${toString forgejoPort}";
};
postgres = {
enable = true;
extraUsers = {
forgejo = {
isClient = true;
};
};
};
};
services.forgejo = {
enable = true;
database = {
type = "postgres";
@ -29,8 +44,6 @@ in {
HTTP_PORT = forgejoPort;
};
};
host.reverse_proxy.subdomains.${config.host.jellyfin.subdomain} = {
target = "http://localhost:${toString forgejoPort}";
};
};
}

View file

@ -34,11 +34,11 @@ in {
assertions = [
{
assertion = config.services.jellyfin.dataDir == jellyfin_data_directory;
description = "jellyfin data directory does not match persistence";
message = "jellyfin data directory does not match persistence";
}
{
assertion = config.services.jellyfin.cacheDir == jellyfin_cache_directory;
description = "jellyfin cache directory does not match persistence";
message = "jellyfin cache directory does not match persistence";
}
];

View file

@ -5,38 +5,29 @@
...
}: let
dataDir = "/var/lib/postgresql/15";
adminUsers = lib.lists.filter (user: user.isAdmin) (lib.attrsets.mapAttrsToList (_: user: user) config.host.postgres.extraUsers);
clientUsers = lib.lists.filter (user: user.isClient) (lib.attrsets.mapAttrsToList (_: user: user) config.host.postgres.extraUsers);
in {
options = {
host.postgres = {
enable = lib.mkEnableOption "enable postgres";
extraAdminUsers = lib.mkOption {
type = lib.types.attrsOf lib.types.submodule ({name, ...}: {
extraUsers = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule ({name, ...}: {
options = {
name = lib.mkOption {
type = lib.types.str;
default = name;
description = ''
What should this users name on the system be
'';
defaultText = lib.literalExpression "config.host.users.\${name}.name";
};
isAdmin = lib.mkOption {
type = lib.types.bool;
default = false;
};
isClient = lib.mkOption {
type = lib.types.bool;
default = false;
};
};
});
default = {};
};
extraDatabaseUsers = lib.mkOption {
type = lib.types.attrsOf lib.types.submodule ({name, ...}: {
options = {
name = lib.mkOption {
type = lib.types.str;
default = name;
description = ''
What should this users name on the system be
'';
defaultText = lib.literalExpression "config.host.users.\${name}.name";
};
};
});
}));
default = {};
};
};
@ -47,18 +38,12 @@ in {
services = {
postgresql = {
enable = true;
ensureUsers =
[
package = pkgs.postgresql_15;
ensureUsers = [
{
name = "postgres";
}
]
+ (lib.attrsets.mapAttrsToList (user: {
name = user.name;
ensureDBOwnership = true;
})
config.host.postgres.extraDatabaseUsers);
ensureDatabases = lib.attrsets.mapAttrsToList (user: user.name) config.host.postgres.extraDatabaseUsers;
];
identMap =
''
# ArbitraryMapName systemUser DBUser
@ -68,14 +53,14 @@ in {
superuser_map postgres postgres
''
+ (
lib.strings.concatLines (lib.attrsets.mapAttrsToList (user: "superuser_map ${user.name} postgres") config.host.postgres.extraAdminUsers)
lib.strings.concatLines (builtins.map (user: "superuser_map ${user.name} postgres") adminUsers)
)
+ ''
# Client Users
''
+ (
lib.strings.concatLines (lib.attrsets.mapAttrsToList (user: "superuser_map ${user.name} ${user.name}") config.host.postgres.extraDatabaseUsers)
lib.strings.concatLines (builtins.map (user: "superuser_map ${user.name} ${user.name}") clientUsers)
);
# configuration here lets users access the db that matches their name and lets user postgres access everything
authentication = pkgs.lib.mkOverride 10 ''
@ -91,7 +76,7 @@ in {
assertions = [
{
assertion = config.services.postgresql.dataDir == dataDir;
description = "postgres data directory does not match persistence";
message = "postgres data directory does not match persistence";
}
];
environment.persistence."/persist/system/root" = {