From a1e39754f93c53b45983398c562efa85d176c6cf Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 31 Jul 2023 15:03:52 +0200 Subject: [PATCH] Generate colmena and hydraJobs outputs from the same hosts attribute set --- flake.nix | 2 +- helper.nix | 13 +++++++++---- hosts.nix | 6 +++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 92fda46..3615c48 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ outputs = { self, nixpkgs, nixpkgs-unstable, nixos-generators, ... }@inputs: let hosts = import ./hosts.nix inputs; - helper = (import ./helper.nix) inputs; + helper = import ./helper.nix inputs; in { colmena = { meta = { diff --git a/helper.nix b/helper.nix index fc91e4e..2188959 100644 --- a/helper.nix +++ b/helper.nix @@ -19,8 +19,13 @@ system, modules, ... - }: - (nixpkgs.lib.filterAttrs (name: host: (builtins.substring 0 1 name) != "_") (hostNixpkgs.lib.nixosSystem { - inherit system modules; - })).config.system.build.toplevel; + }: + let + # Filter attritubes starting with _ to avoid infinite recursion when building with hydra + # TODO: Why does this happen? + filter = name: host: (builtins.substring 0 1 name) != "_"; + in + (nixpkgs.lib.filterAttrs filter (hostNixpkgs.lib.nixosSystem { + inherit system modules; + })).config.system.build.toplevel; # Builds the entire NixOS system, see: https://nixos.org/manual/nixos/stable/#sec-building-parts } diff --git a/hosts.nix b/hosts.nix index 083d5b8..2ba24de 100644 --- a/hosts.nix +++ b/hosts.nix @@ -1,23 +1,27 @@ { nixpkgs, nixpkgs-unstable, ... }: let + # Set of environment specific modules environments = { "proxmox" = [ ./configuration/proxmox-vm ./configuration/proxmox-vm/hardware-configuration.nix ]; }; + # generateDefaults = hosts: builtins.mapAttrs (name: { hostNixpkgs ? nixpkgs, system ? "x86_64-linux", + # pkgs is explicitly defined so that overlays for each host can easily be created pkgs ? hostNixpkgs.legacyPackages.${system}, environment ? "proxmox", site }: { inherit hostNixpkgs system pkgs environment site; + # define common and host modules and additionally add environment specific modules modules = [ ./configuration/common ./hosts/${name} - ] ++ (if environments ? ${environment} then environments.${environment} else []); + ] ++ environments.${environment}; }) hosts; in generateDefaults {