simplify flake.nix and dedupe #4

open
opened by anirudh.fi targeting master from push-oqkkllmzurup
Changed files
+64 -75
+64 -75
flake.nix
···
{
description = "nix infra for tangled";
+
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
tangled.url = "git+https://tangled.org/@tangled.org/core";
···
};
};
-
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;
};
};
}