From 24e8170453b351df4972dfc27fa651dadc83c80c Mon Sep 17 00:00:00 2001 From: Asyncnomi Date: Thu, 24 Jul 2025 21:45:00 +0200 Subject: [PATCH] improve the handling of the different nixpkgs version in flake.nix --- flake.nix | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index b32cc24..906b2ed 100644 --- a/flake.nix +++ b/flake.nix @@ -12,28 +12,30 @@ outputs = { self, nixpkgs-25-05, nixpkgs-unstable, deploy-rs, agenix }: let system = "x86_64-linux"; + # Mapping version identifiers to nixpkgs + nixpkgsMap = { + "25.05" = nixpkgs-25-05; + "unstable" = nixpkgs-unstable; + }; + + importPkgs = version: overlays: import nixpkgsMap.${version} { + inherit system; + overlays = if overlays == null then [] else overlays; + }; + # Unmodified nixpkgs - pkgs-25-05 = import nixpkgs-25-05 { inherit system; }; - pkgs-unstable = import nixpkgs-unstable { inherit system; }; + getNixpkgs = version: importPkgs version []; # nixpkgs with deploy-rs overlay but force the nixpkgs package - deployPkgs-25-05 = import nixpkgs-25-05 { - inherit system; - overlays = [ - deploy-rs.overlays.default - (self: super: { deploy-rs = { inherit (pkgs-25-05) deploy-rs; lib = super.deploy-rs.lib; }; }) - ]; - }; - deployPkgs-unstable = import nixpkgs-unstable { - inherit system; - overlays = [ - deploy-rs.overlays.default - (self: super: { deploy-rs = { inherit (pkgs-unstable) deploy-rs; lib = super.deploy-rs.lib; }; }) - ]; - }; - - getDeployPkgs = ver: if ver == "25.05" then deployPkgs-25-05 else deployPkgs-unstable; - getNixpkgs = ver: if ver == "25.05" then nixpkgs-25-05 else nixpkgs-unstable; + getDeployPkgs = version: importPkgs version [ + deploy-rs.overlays.default + (self: super: { + deploy-rs = { + inherit (getNixpkgs version) deploy-rs; + lib = super.deploy-rs.lib; + }; + }) + ]; nodes = import ./nodes.nix; mapping = import ./mapping.nix; @@ -57,7 +59,7 @@ in { nixosConfigurations = builtins.mapAttrs (name: config: - (getNixpkgs config.ver).lib.nixosSystem { + nixpkgsMap.${config.ver}.lib.nixosSystem { system = config.system; modules = getModulesForHost "${name}" ++ defaultModules ++ [{ hostName = "${name}"; }]; }