Tangled infrastructure definitions in Nix

simplify flake.nix and dedupe

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>

anirudh.fi d0201927 060881d4

verified
Changed files
+74 -76
+74 -76
flake.nix
··· 1 1 { 2 2 description = "nix infra for tangled"; 3 + 3 4 inputs = { 4 5 nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; 5 6 tangled.url = "git+https://tangled.org/tangled.org/core"; ··· 16 17 }; 17 18 }; 18 19 19 - outputs = 20 - { nixpkgs, disko, colmena, nixery-flake, tangled, ... }: 21 - { 22 - nixosConfigurations.nixery = nixpkgs.lib.nixosSystem { 23 - system = "x86_64-linux"; 24 - modules = [ 25 - disko.nixosModules.disko 26 - tangled.nixosModules.spindle 27 - ./hosts/nixery/configuration.nix 28 - ]; 29 - }; 30 - nixosConfigurations.pds = nixpkgs.lib.nixosSystem { 31 - system = "x86_64-linux"; 32 - specialArgs = { 33 - commonArgs = import ./common/ssh.nix; 34 - }; 35 - modules = [ 36 - disko.nixosModules.disko 37 - ./hosts/pds/configuration.nix 38 - ]; 39 - }; 40 - nixosConfigurations.appview = nixpkgs.lib.nixosSystem { 41 - system = "x86_64-linux"; 42 - specialArgs = { 43 - commonArgs = import ./common/ssh.nix; 44 - }; 45 - modules = [ 46 - disko.nixosModules.disko 47 - ./hosts/appview/configuration.nix 48 - ]; 49 - }; 20 + outputs = { nixpkgs, disko, colmena, nixery-flake, tangled, ... }: 21 + let 22 + system = "x86_64-linux"; 23 + commonArgs = import ./common/ssh.nix; 50 24 51 - colmenaHive = colmena.lib.makeHive { 52 - meta = { 53 - nixpkgs = nixpkgs.legacyPackages.x86_64-linux; 54 - specialArgs = { 55 - nixery-pkgs = import nixery-flake.outPath { 56 - pkgs = import nixpkgs { system = "x86_64-linux"; }; 57 - }; 58 - tangled-pkgs = tangled.packages.x86_64-linux; 59 - commonArgs = import ./common/ssh.nix; 60 - }; 25 + colmenaHive = colmena.lib.makeHive { 26 + meta = { 27 + nixpkgs = nixpkgs.legacyPackages.x86_64-linux; 28 + specialArgs = { 29 + nixery-pkgs = import nixery-flake.outPath { 30 + pkgs = import nixpkgs { system = "x86_64-linux"; }; 31 + }; 32 + tangled-pkgs = tangled.packages.x86_64-linux; 33 + commonArgs = import ./common/ssh.nix; 34 + }; 35 + # Helper function to create nixosConfiguration 36 + mkHost = hostname: extraModules: 37 + nixpkgs.lib.nixosSystem { 38 + inherit system; 39 + specialArgs = { inherit commonArgs; }; 40 + modules = [ 41 + disko.nixosModules.disko 42 + ./hosts/${hostname}/configuration.nix 43 + ] ++ extraModules; 61 44 }; 62 45 63 - defaults = { pkgs, ... }: { 64 - environment.systemPackages = [ 65 - pkgs.curl 66 - ]; 67 - }; 68 - appview = { pkgs, ... }: { 46 + # Helper function to create colmena host 47 + mkColmenaHost = hostname: targetHost: extraModules: 48 + { 69 49 deployment = { 70 - targetHost = "alpha.tangled.sh"; 50 + inherit targetHost; 71 51 targetPort = 22; 72 52 targetUser = "tangler"; 73 53 buildOnTarget = true; 74 54 }; 75 - nixpkgs.system = "x86_64-linux"; 55 + nixpkgs.system = system; 56 + time.timeZone = "Europe/Helsinki"; 76 57 imports = [ 77 58 disko.nixosModules.disko 59 + ./hosts/${hostname}/configuration.nix 60 + ] ++ extraModules; 61 + }; 62 + 63 + # Host configurations 64 + hosts = { 65 + appview = { 66 + modules = [ 78 67 tangled.nixosModules.appview 79 - ./hosts/appview/configuration.nix 80 68 ./hosts/appview/services/appview.nix 81 69 ./hosts/appview/services/nginx-alpha.nix 82 70 ]; 83 - time.timeZone = "Europe/Helsinki"; 71 + target = "alpha.tangled.sh"; 84 72 }; 85 - pds = { pkgs, ... }: { 86 - deployment = { 87 - targetHost = "tngl.sh"; 88 - targetPort = 22; 89 - targetUser = "tangler"; 90 - buildOnTarget = true; 91 - }; 92 - nixpkgs.system = "x86_64-linux"; 93 73 94 - imports = [ 95 - disko.nixosModules.disko 96 - ./hosts/pds/configuration.nix 74 + pds = { 75 + modules = [ 97 76 ./hosts/pds/services/nginx.nix 98 77 ./hosts/pds/services/pds.nix 99 78 ]; 100 - time.timeZone = "Europe/Helsinki"; 79 + target = "tngl.sh"; 101 80 }; 102 81 103 - nixery = { pkgs, ... }: { 104 - deployment = { 105 - targetHost = "nixery.tangled.sh"; 106 - targetPort = 22; 107 - targetUser = "tangler"; 108 - buildOnTarget = true; 109 - }; 110 - nixpkgs.system = "x86_64-linux"; 111 - 112 - imports = [ 113 - disko.nixosModules.disko 82 + nixery = { 83 + modules = [ 114 84 tangled.nixosModules.spindle 115 - ./hosts/nixery/configuration.nix 116 85 ./hosts/nixery/services/nginx.nix 117 86 ./hosts/nixery/services/openbao/openbao.nix 118 87 ./hosts/nixery/services/openbao/proxy.nix 119 88 ./hosts/nixery/services/nixery.nix 120 89 ]; 121 - time.timeZone = "Europe/Helsinki"; 90 + target = "nixery.tangled.sh"; 91 + }; 92 + }; 93 + in 94 + { 95 + # nixos-anywhere and nixos-rebuild use these 96 + nixosConfigurations = { 97 + appview = mkHost "appview" hosts.appview.modules; 98 + pds = mkHost "pds" hosts.pds.modules; 99 + nixery = mkHost "nixery" hosts.nixery.modules; 100 + }; 101 + 102 + # colmena uses this 103 + colmenaHive = colmena.lib.makeHive { 104 + meta = { 105 + nixpkgs = nixpkgs.legacyPackages.${system}; 106 + specialArgs = { 107 + inherit commonArgs; 108 + nixery-pkgs = import nixery-flake.outPath { 109 + pkgs = import nixpkgs { inherit system; }; 110 + }; 111 + }; 122 112 }; 113 + 114 + defaults = { pkgs, ... }: { 115 + environment.systemPackages = [ pkgs.curl ]; 116 + }; 117 + 118 + appview = mkColmenaHost "appview" hosts.appview.target hosts.appview.modules; 119 + pds = mkColmenaHost "pds" hosts.pds.target hosts.pds.modules; 120 + nixery = mkColmenaHost "nixery" hosts.nixery.target hosts.nixery.modules; 123 121 }; 124 122 }; 125 123 }