From 5214e85695ae2aa7dca3a2d8040a7b746efd8979 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Mon, 10 Nov 2025 10:00:55 +0200 Subject: [PATCH] simplify flake.nix and dedupe Change-Id: tonvkontwmovmpkqkotzsklnywvomutl Signed-off-by: Anirudh Oppiliappan --- flake.nix | 139 +++++++++++++++++++++++++----------------------------- 1 file changed, 64 insertions(+), 75 deletions(-) diff --git a/flake.nix b/flake.nix index c41012b..b270b77 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,6 @@ { description = "nix infra for tangled"; + inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; tangled.url = "git+https://tangled.org/@tangled.org/core"; @@ -16,109 +17,97 @@ }; }; - outputs = - { nixpkgs, disko, colmena, nixery-flake, tangled, ... }: - { - nixosConfigurations.nixery = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - disko.nixosModules.disko - tangled.nixosModules.spindle - ./hosts/nixery/configuration.nix - ]; - }; - nixosConfigurations.pds = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = { - commonArgs = import ./common/ssh.nix; - }; - modules = [ - disko.nixosModules.disko - ./hosts/pds/configuration.nix - ]; - }; - nixosConfigurations.appview = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = { - commonArgs = import ./common/ssh.nix; - }; - modules = [ - disko.nixosModules.disko - ./hosts/appview/configuration.nix - ]; - }; + outputs = { nixpkgs, disko, colmena, nixery-flake, tangled, ... }: + let + system = "x86_64-linux"; + commonArgs = import ./common/ssh.nix; - colmenaHive = colmena.lib.makeHive { - meta = { - nixpkgs = nixpkgs.legacyPackages.x86_64-linux; - specialArgs = { - nixery-pkgs = import nixery-flake.outPath { - pkgs = import nixpkgs { system = "x86_64-linux"; }; - }; - commonArgs = import ./common/ssh.nix; - }; + # Helper function to create nixosConfiguration + mkHost = hostname: extraModules: + nixpkgs.lib.nixosSystem { + inherit system; + specialArgs = { inherit commonArgs; }; + modules = [ + disko.nixosModules.disko + ./hosts/${hostname}/configuration.nix + ] ++ extraModules; }; - defaults = { pkgs, ... }: { - environment.systemPackages = [ - pkgs.curl - ]; - }; - appview = { pkgs, ... }: { + # Helper function to create colmena host + mkColmenaHost = hostname: targetHost: extraModules: + { deployment = { - targetHost = "alpha.tangled.sh"; + inherit targetHost; targetPort = 22; targetUser = "tangler"; buildOnTarget = true; }; - nixpkgs.system = "x86_64-linux"; + nixpkgs.system = system; + time.timeZone = "Europe/Helsinki"; imports = [ disko.nixosModules.disko + ./hosts/${hostname}/configuration.nix + ] ++ extraModules; + }; + + # Host configurations + hosts = { + appview = { + modules = [ tangled.nixosModules.appview - ./hosts/appview/configuration.nix ./hosts/appview/services/appview.nix ./hosts/appview/services/nginx-alpha.nix ]; - time.timeZone = "Europe/Helsinki"; + target = "alpha.tangled.sh"; }; - pds = { pkgs, ... }: { - deployment = { - targetHost = "tngl.sh"; - targetPort = 22; - targetUser = "tangler"; - buildOnTarget = true; - }; - nixpkgs.system = "x86_64-linux"; - imports = [ - disko.nixosModules.disko - ./hosts/pds/configuration.nix + pds = { + modules = [ ./hosts/pds/services/nginx.nix ./hosts/pds/services/pds.nix ]; - time.timeZone = "Europe/Helsinki"; + target = "tngl.sh"; }; - nixery = { pkgs, ... }: { - deployment = { - targetHost = "nixery.tangled.sh"; - targetPort = 22; - targetUser = "tangler"; - buildOnTarget = true; - }; - nixpkgs.system = "x86_64-linux"; - - imports = [ - disko.nixosModules.disko + nixery = { + modules = [ tangled.nixosModules.spindle - ./hosts/nixery/configuration.nix ./hosts/nixery/services/nginx.nix ./hosts/nixery/services/openbao/openbao.nix ./hosts/nixery/services/openbao/proxy.nix ./hosts/nixery/services/nixery.nix ]; - time.timeZone = "Europe/Helsinki"; + target = "nixery.tangled.sh"; + }; + }; + in + { + # nixos-anywhere and nixos-rebuild use these + nixosConfigurations = { + appview = mkHost "appview" hosts.appview.modules; + pds = mkHost "pds" hosts.pds.modules; + nixery = mkHost "nixery" hosts.nixery.modules; + }; + + # colmena uses this + colmenaHive = colmena.lib.makeHive { + meta = { + nixpkgs = nixpkgs.legacyPackages.${system}; + specialArgs = { + inherit commonArgs; + nixery-pkgs = import nixery-flake.outPath { + pkgs = import nixpkgs { inherit system; }; + }; + }; + }; + + defaults = { pkgs, ... }: { + environment.systemPackages = [ pkgs.curl ]; }; + + appview = mkColmenaHost "appview" hosts.appview.target hosts.appview.modules; + pds = mkColmenaHost "pds" hosts.pds.target hosts.pds.modules; + nixery = mkColmenaHost "nixery" hosts.nixery.target hosts.nixery.modules; }; }; } -- 2.43.0