Nix flake configuration for my various machines (clients and homelab servers)
0

Configure Feed

Select the types of activity you want to include in your feed.

cleanup domains/hosts with constants

Parthiv Krishna (Aug 3, 2025, 1:43 AM -0700) 1983b35c fe133b61

+78 -48
+26 -3
lib/domains.nix
··· 1 - _: { 2 - mkPublicFqdn = constants: subdomain: "${subdomain}.${constants.domains.public}"; 1 + _: 2 + let 3 + # build FQDN with optional subdomain 4 + mkFqdn = 5 + baseDomain: subdomain: host: 6 + if subdomain == "" then 7 + if host == null then baseDomain else "${host}.${baseDomain}" 8 + else if host == null then 9 + "${subdomain}.${baseDomain}" 10 + else 11 + "${subdomain}.${host}.${baseDomain}"; 12 + 13 + mkPublicFqdn = constants: subdomain: mkFqdn constants.domains.public subdomain null; 3 14 4 15 mkInternalFqdn = 5 16 constants: subdomain: host: 6 - "${subdomain}.${host}.${constants.domains.internal}"; 17 + mkFqdn constants.domains.internal subdomain host; 18 + 19 + # add HTTPS prefix 20 + addHttps = domain: "https://${domain}"; 21 + in 22 + { 23 + inherit mkPublicFqdn mkInternalFqdn; 24 + 25 + mkPublicHttpsUrl = constants: subdomain: addHttps (mkPublicFqdn constants subdomain); 26 + 27 + mkInternalHttpsUrl = 28 + constants: subdomain: host: 29 + addHttps (mkInternalFqdn constants subdomain host); 7 30 }
+3 -7
lib/services.nix
··· 65 65 persistentDirectories ? [ ], 66 66 }: 67 67 let 68 - inherit (config.constants) domains publicServerHost; 68 + inherit (config.constants) publicServerHost; 69 69 myHostName = config.networking.hostName; 70 70 isTargetHost = myHostName == hostName; 71 71 isPublicServer = myHostName == publicServerHost; ··· 80 80 81 81 # fully qualified domain names 82 82 fqdn = { 83 - internal = 84 - if subdomain == "" then 85 - "${hostName}.${domains.internal}" 86 - else 87 - "${subdomain}.${hostName}.${domains.internal}"; 88 - public = if subdomain == "" then domains.public else "${subdomain}.${domains.public}"; 83 + internal = lib.custom.mkInternalFqdn config.constants subdomain hostName; 84 + public = lib.custom.mkPublicFqdn config.constants subdomain; 89 85 }; 90 86 virtualHostConfig = logName: { 91 87 logFormat = ''
+6
system/common/modules/constants.nix
··· 9 9 }; 10 10 mkStringConstant = mkConstant lib.types.str; 11 11 hosts = { 12 + icicle = mkStringConstant "icicle"; 12 13 midnight = mkStringConstant "midnight"; 13 14 nimbus = mkStringConstant "nimbus"; 14 15 }; ··· 16 17 { 17 18 options.constants = { 18 19 inherit hosts; 20 + 21 + servers = [ 22 + hosts.midnight 23 + hosts.nimbus 24 + ]; 19 25 20 26 publicServerHost = hosts.nimbus; 21 27
+2 -1
system/common/modules/selfhosted/actual.nix
··· 1 1 { config, lib, ... }: 2 2 let 3 + inherit (config.constants) hosts; 3 4 port = 5006; 4 5 in 5 6 lib.custom.mkSelfHostedService { 6 7 inherit config lib; 7 8 name = "actual"; 8 - hostName = "nimbus"; 9 + hostName = hosts.nimbus; 9 10 inherit port; 10 11 public = true; 11 12 protected = false;
+4 -3
system/common/modules/selfhosted/grafana.nix
··· 5 5 ... 6 6 }: 7 7 let 8 + inherit (config.constants) hosts; 8 9 subdomain = "stats"; 9 - domain = "${subdomain}.${config.constants.domains.public}"; 10 - autheliaDomain = "auth.${config.constants.domains.public}"; 10 + domain = lib.custom.mkPublicFqdn config.constants subdomain; 11 + autheliaDomain = lib.custom.mkPublicFqdn config.constants "auth"; 11 12 secretsRoot = "authelia/identity_providers/oidc/clients/grafana"; 12 13 13 14 # this version fixes GitSync issues. should be able to switch once 12.1.0 hits nixpkgs ··· 48 49 lib.custom.mkSelfHostedService { 49 50 inherit config lib; 50 51 name = "grafana"; 51 - hostName = "nimbus"; 52 + hostName = hosts.nimbus; 52 53 inherit port; 53 54 public = true; 54 55 protected = true;
+14 -15
system/common/modules/selfhosted/homepage.nix
··· 5 5 ... 6 6 }: 7 7 let 8 - inherit (config.constants) domains; 8 + inherit (config.constants) domains hosts; 9 9 port = 8082; 10 10 in 11 11 lib.custom.mkSelfHostedService { 12 12 inherit config lib; 13 13 name = "homepage"; 14 - hostName = "nimbus"; 14 + hostName = hosts.nimbus; 15 15 inherit port; 16 16 subdomain = ""; # on root domain 17 17 public = true; ··· 30 30 { 31 31 "Jellyfin: tv.${domains.public}" = { 32 32 description = "Movies and TV"; 33 - href = "https://tv.${domains.public}"; 33 + href = lib.custom.mkPublicHttpsUrl config.constants "tv"; 34 34 icon = "sh-jellyfin"; 35 - ping = "midnight.${domains.internal}"; 35 + ping = lib.custom.mkInternalFqdn config.constants "" hosts.midnight; 36 36 }; 37 37 } 38 38 ]; ··· 42 42 { 43 43 "Immich: photos.${domains.public}" = { 44 44 description = "Photo storage"; 45 - href = "https://photos.${domains.public}"; 45 + href = lib.custom.mkPublicHttpsUrl config.constants "photos"; 46 46 icon = "sh-immich"; 47 - ping = "midnight.${domains.internal}"; 47 + ping = lib.custom.mkInternalFqdn config.constants "" hosts.midnight; 48 48 }; 49 49 } 50 50 { 51 51 "OwnCloud: drive.${domains.public}" = { 52 52 description = "General storage"; 53 - href = "https://drive.${domains.public}"; 53 + href = lib.custom.mkPublicHttpsUrl config.constants "drive"; 54 54 icon = "sh-owncloud"; 55 - ping = "midnight.${domains.internal}"; 55 + ping = lib.custom.mkInternalFqdn config.constants "" hosts.midnight; 56 56 }; 57 57 } 58 58 ]; ··· 62 62 { 63 63 "Actual: actual.${domains.public}" = { 64 64 description = "Budgeting"; 65 - href = "https://actual.${domains.public}"; 65 + href = lib.custom.mkPublicHttpsUrl config.constants "actual"; 66 66 icon = "sh-actual-budget"; 67 - ping = "nimbus.${domains.internal}"; 67 + ping = lib.custom.mkInternalFqdn config.constants "" hosts.nimbus; 68 68 }; 69 69 } 70 70 { 71 71 "Mealie: food.${domains.public}" = { 72 72 description = "Recipies"; 73 - href = "https://food.${domains.public}"; 73 + href = lib.custom.mkPublicHttpsUrl config.constants "food"; 74 74 icon = "sh-mealie"; 75 - ping = "nimbus.${domains.internal}"; 75 + ping = lib.custom.mkInternalFqdn config.constants "" hosts.nimbus; 76 76 }; 77 77 } 78 78 ]; 79 79 } 80 80 { 81 81 "Network" = [ 82 - 83 82 { 84 83 "Grafana: stats.${domains.public}" = { 85 84 description = "Charts and metrics"; 86 - href = "https://stats.${domains.public}"; 85 + href = lib.custom.mkPublicHttpsUrl config.constants "stats"; 87 86 icon = "sh-grafana"; 88 - ping = "nimbus.${domains.internal}"; 87 + ping = lib.custom.mkInternalFqdn config.constants "" hosts.nimbus; 89 88 }; 90 89 } 91 90 ];
+2 -2
system/common/modules/selfhosted/immich.nix
··· 5 5 ... 6 6 }: 7 7 let 8 - inherit (config.constants) tieredCache; 8 + inherit (config.constants) hosts tieredCache; 9 9 in 10 10 lib.custom.mkSelfHostedService { 11 11 inherit config lib; 12 12 name = "immich"; 13 - hostName = "midnight"; 13 + hostName = hosts.midnight; 14 14 port = 2283; 15 15 subdomain = "photos"; 16 16 public = true;
+2 -2
system/common/modules/selfhosted/jellyfin.nix
··· 1 1 { config, lib, ... }: 2 2 let 3 - inherit (config.constants) tieredCache; 3 + inherit (config.constants) hosts tieredCache; 4 4 in 5 5 lib.custom.mkSelfHostedService { 6 6 inherit config lib; 7 7 name = "jellyfin"; 8 - hostName = "midnight"; 8 + hostName = hosts.midnight; 9 9 port = 8096; 10 10 subdomain = "tv"; 11 11 public = true;
+2 -1
system/common/modules/selfhosted/mealie.nix
··· 1 1 { config, lib, ... }: 2 2 let 3 + inherit (config.constants) hosts; 3 4 secretsRoot = "authelia/identity_providers/oidc/clients/mealie"; 4 5 port = 9000; 5 6 in 6 7 lib.custom.mkSelfHostedService { 7 8 inherit config lib; 8 9 name = "mealie"; 9 - hostName = "nimbus"; 10 + hostName = hosts.nimbus; 10 11 inherit port; 11 12 subdomain = "food"; 12 13 public = true;
+2 -2
system/common/modules/selfhosted/ocis.nix
··· 4 4 ... 5 5 }: 6 6 let 7 - inherit (config.constants) tieredCache; 7 + inherit (config.constants) hosts tieredCache; 8 8 port = 9200; 9 9 in 10 10 lib.custom.mkSelfHostedService { 11 11 inherit config lib; 12 12 name = "ocis"; 13 - hostName = "midnight"; 13 + hostName = hosts.midnight; 14 14 inherit port; 15 15 subdomain = "drive"; 16 16 public = true;
+2 -2
system/common/modules/selfhosted/ollama.nix
··· 1 1 { config, lib, ... }: 2 2 let 3 - inherit (config.constants) tieredCache; 3 + inherit (config.constants) hosts tieredCache; 4 4 in 5 5 lib.custom.mkSelfHostedService { 6 6 inherit ··· 8 8 lib 9 9 ; 10 10 name = "ollama"; 11 - hostName = "midnight"; 11 + hostName = hosts.midnight; 12 12 port = 11434; 13 13 public = false; 14 14 persistentDirectories = [ "/var/lib/private/ollama" ];
+3 -2
system/common/modules/selfhosted/prometheus/node.nix
··· 4 4 ... 5 5 }: 6 6 let 7 + inherit (config.constants) hosts; 7 8 port = 9101; 8 9 # shared service configuration for all node exporters 9 10 mkNodeExporterService = ··· 37 38 in 38 39 { 39 40 imports = [ 40 - (mkNodeExporterService "midnight") 41 - (mkNodeExporterService "nimbus") 41 + (mkNodeExporterService hosts.midnight) 42 + (mkNodeExporterService hosts.nimbus) 42 43 ]; 43 44 }
+2 -1
system/common/modules/selfhosted/prometheus/nut.nix
··· 5 5 ... 6 6 }: 7 7 let 8 + inherit (config.constants) hosts; 8 9 passwordName = "ups/password"; 9 10 passwordFile = config.sops.secrets.${passwordName}.path; 10 11 port = 9102; ··· 12 13 lib.custom.mkSelfHostedService { 13 14 inherit config lib; 14 15 name = "prometheus-nut"; 15 - hostName = "midnight"; 16 + hostName = hosts.midnight; 16 17 inherit port; 17 18 public = false; 18 19 protected = false;
+5 -4
system/common/modules/selfhosted/prometheus/server.nix
··· 1 1 { config, lib, ... }: 2 2 let 3 + inherit (config.constants) hosts; 3 4 port = 9092; 4 5 in 5 6 lib.custom.mkSelfHostedService { 6 7 inherit config lib; 7 8 name = "prometheus"; 8 - hostName = "nimbus"; 9 + hostName = hosts.nimbus; 9 10 inherit port; 10 11 public = false; 11 12 protected = false; ··· 26 27 job_name = "nut"; 27 28 static_configs = [ 28 29 { 29 - targets = [ "prometheus-nut.midnight.${config.constants.domains.internal}" ]; 30 + targets = [ (lib.custom.mkInternalFqdn config.constants "prometheus-nut" hosts.midnight) ]; 30 31 } 31 32 ]; 32 33 metrics_path = "/ups_metrics"; ··· 51 52 static_configs = [ 52 53 { 53 54 targets = [ 54 - "prometheus-node.midnight.${config.constants.domains.internal}" 55 - "prometheus-node.nimbus.${config.constants.domains.internal}" 55 + (lib.custom.mkInternalFqdn config.constants "prometheus-node" hosts.midnight) 56 + (lib.custom.mkInternalFqdn config.constants "prometheus-node" hosts.nimbus) 56 57 ]; 57 58 } 58 59 ];
+3 -3
system/common/modules/selfhosted/reverse-proxy/authelia.nix
··· 45 45 # service-specific rules are managed by lib.custom.mkSelfHostedService 46 46 # anyone can access the auth portal 47 47 { 48 - domain_regex = "${subdomain}.${config.constants.domains.public}"; 48 + domain_regex = lib.custom.mkPublicFqdn config.constants subdomain; 49 49 policy = "bypass"; 50 50 } 51 51 # admins and users can access all domains ··· 69 69 { 70 70 name = "sub0_session"; 71 71 domain = config.constants.domains.public; 72 - authelia_url = "https://${subdomain}.${config.constants.domains.public}"; 72 + authelia_url = lib.custom.mkPublicHttpsUrl config.constants subdomain; 73 73 inactivity = "1 week"; 74 74 expiration = "3 weeks"; 75 75 remember_me = "1 month"; ··· 231 231 # add authentication to caddy 232 232 caddy = 233 233 let 234 - fqdn = "${subdomain}.${config.constants.domains.public}"; 234 + fqdn = lib.custom.mkPublicFqdn config.constants subdomain; 235 235 in 236 236 { 237 237 extraConfig = ''