Tangled infrastructure definitions in Nix
1{
2 description = "nix infra for tangled";
3
4 inputs = {
5 nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
6 tangled.url = "git+https://tangled.org/tangled.org/core";
7 colmena.url = "github:zhaofengli/colmena/release-0.4.x";
8 disko = {
9 url = "github:nix-community/disko";
10 inputs.nixpkgs.follows = "nixpkgs";
11 };
12 nixery-flake = {
13 type = "github";
14 owner = "tazjin";
15 repo = "nixery";
16 flake = false;
17 };
18 };
19
20 outputs = { nixpkgs, disko, colmena, nixery-flake, tangled, ... }:
21 let
22 system = "x86_64-linux";
23 commonArgs = import ./common/ssh.nix;
24
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;
44 };
45
46 # Helper function to create colmena host
47 mkColmenaHost = hostname: targetHost: targetPort: extraModules:
48 {
49 deployment = {
50 inherit targetHost;
51 inherit targetPort;
52 targetUser = "tangler";
53 buildOnTarget = true;
54 };
55 nixpkgs.system = system;
56 time.timeZone = "Europe/Helsinki";
57 imports = [
58 disko.nixosModules.disko
59 ./hosts/${hostname}/configuration.nix
60 ] ++ extraModules;
61 };
62
63 # Host configurations
64 hosts = {
65 appview = {
66 modules = [
67 tangled.nixosModules.appview
68 ./hosts/appview/services/appview.nix
69 ./hosts/appview/services/nginx.nix
70 ];
71 target = "95.111.205.38";
72 };
73
74 pds = {
75 modules = [
76 ./hosts/pds/services/nginx.nix
77 ./hosts/pds/services/pds.nix
78 ];
79 target = "tngl.sh";
80 };
81
82 nixery = {
83 modules = [
84 tangled.nixosModules.spindle
85 ./hosts/nixery/services/nginx.nix
86 ./hosts/nixery/services/openbao/openbao.nix
87 ./hosts/nixery/services/openbao/proxy.nix
88 ./hosts/nixery/services/nixery.nix
89 ];
90 target = "nixery.tangled.sh";
91 };
92
93 spindle = {
94 modules = [
95 tangled.nixosModules.spindle
96 ./hosts/spindle/services/openbao/openbao.nix
97 ./hosts/spindle/services/openbao/proxy.nix
98 ./hosts/spindle/services/spindle.nix
99 ./hosts/spindle/services/nginx.nix
100 ];
101 target = "spindle.alpha.tangled.sh";
102 };
103
104 knot1 = {
105 modules = [
106 tangled.nixosModules.knot
107 ./hosts/knot1/services/knot.nix
108 ./hosts/knot1/services/nginx.nix
109 ];
110 target = "knot1.alpha.tangled.sh";
111 };
112 };
113 in
114 {
115 # nixos-anywhere and nixos-rebuild use these
116 nixosConfigurations = {
117 appview = mkHost "appview" hosts.appview.modules;
118 pds = mkHost "pds" hosts.pds.modules;
119 nixery = mkHost "nixery" hosts.nixery.modules;
120 spindle = mkHost "spindle" hosts.spindle.modules;
121 knot1 = mkHost "knot1" hosts.knot1.modules;
122 };
123
124 # colmena uses this
125 colmenaHive = colmena.lib.makeHive {
126 meta = {
127 nixpkgs = nixpkgs.legacyPackages.${system};
128 specialArgs = {
129 inherit commonArgs;
130 nixery-pkgs = import nixery-flake.outPath {
131 pkgs = import nixpkgs { inherit system; };
132 };
133 };
134 };
135
136 defaults = { pkgs, ... }: {
137 environment.systemPackages = [ pkgs.curl ];
138 };
139
140 appview = mkColmenaHost "appview" hosts.appview.target 2222 hosts.appview.modules;
141 pds = mkColmenaHost "pds" hosts.pds.target 22 hosts.pds.modules;
142 nixery = mkColmenaHost "nixery" hosts.nixery.target 22 hosts.nixery.modules;
143 spindle = mkColmenaHost "spindle" hosts.spindle.target 22 hosts.spindle.modules;
144 knot1 = mkColmenaHost "knot1" hosts.knot1.target 22 hosts.knot1.modules;
145 };
146 };
147}