From 494ac8b862a1045b2fa6f7b11678d56525bd0e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Schwarz=C3=A4ugl?= Date: Fri, 19 Dec 2025 17:41:34 +0100 Subject: [PATCH] fix: globals evaluation pinned to static arch --- nix/globals.nix | 28 ++++++++++++++++++---------- nix/hosts.nix | 9 ++++++--- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/nix/globals.nix b/nix/globals.nix index 563a901..fae2b0d 100644 --- a/nix/globals.nix +++ b/nix/globals.nix @@ -1,25 +1,35 @@ # adapted from https://github.com/oddlama/nix-config/blob/main/nix/globals.nix -{ inputs, ... }: +{ self, inputs, ... }: { - flake = { config, lib, ... }: + + imports = [ + ( + { lib, flake-parts-lib, ... }: + flake-parts-lib.mkTransposedPerSystemModule { + name = "globals"; + file = ./globals.nix; + option = lib.mkOption { + type = lib.types.unspecified; + }; + } + ) + ]; + perSystem = { lib, pkgs, ... }: { globals = let globalsSystem = lib.evalModules { prefix = [ "globals" ]; specialArgs = { - inherit (inputs.self.pkgs.x86_64-linux) lib; # fuck - # inherit (self.outputs) lib; + inherit (pkgs) lib; + inherit (self.outputs) nodes; inherit inputs; - inherit (config) nodes; }; modules = [ ../modules/nixos/common/globals.nix ( { lib, ... }: let - # Try to access the extra builtin we loaded via nix-plugins. - # Throw an error if that doesn't exist. sopsImportEncrypted = assert lib.assertMsg (builtins ? extraBuiltins.sopsImportEncrypted) "The extra builtin 'sopsImportEncrypted' is not available, so repo.secrets cannot be decrypted. Did you forget to add nix-plugins and point it to `./nix/extra-builtins.nix` ?"; @@ -38,7 +48,7 @@ { globals = lib.mkMerge ( lib.concatLists ( - lib.flip lib.mapAttrsToList config.nodes ( + lib.flip lib.mapAttrsToList self.outputs.nodes ( name: cfg: builtins.addErrorContext "while aggregating globals from nixosConfigurations.${name} into flake-level globals:" cfg.config._globalsDefs ) @@ -50,8 +60,6 @@ }; in { - # Make sure the keys of this attrset are trivially evaluatable to avoid infinite recursion, - # therefore we inherit relevant attributes from the config. inherit (globalsSystem.config.globals) domains services diff --git a/nix/hosts.nix b/nix/hosts.nix index e582437..1e0d756 100644 --- a/nix/hosts.nix +++ b/nix/hosts.nix @@ -11,7 +11,8 @@ specialArgs = { inherit inputs outputs self minimal homeLib configName arch; inherit (config.pkgs.${arch}) lib; - inherit (config) globals nodes; + inherit (config) nodes; + globals = config.globals.${arch}; type = "nixos"; }; modules = [ @@ -68,7 +69,8 @@ inputs.nix-darwin.lib.darwinSystem { specialArgs = { inherit inputs lib outputs self minimal configName; - inherit (config) globals nodes; + inherit (config) nodes; + globals = config.globals.${arch}; }; modules = [ # inputs.disko.nixosModules.disko @@ -103,7 +105,8 @@ inherit pkgs; extraSpecialArgs = { inherit inputs lib outputs self configName arch type; - inherit (config) globals nodes; + inherit (config) nodes; + globals = config.globals.${arch}; minimal = false; }; modules = [