Tangled infrastructure definitions in Nix

simplify flake.nix and dedupe #4

closed opened by anirudh.fi targeting master from push-oqkkllmzurup
Labels

None yet.

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

History

1 round 0 comments
sign up or login to add to the discussion
anirudh.fi submitted #0
1 commit
expand
simplify flake.nix and dedupe
expand 0 comments
closed without merging