From d76fdbf81b946e5c544b3a100294c629869c910b Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 10 Dec 2023 09:41:02 +0100 Subject: [PATCH] flake: make inputs configurable per nixos host --- flake.nix | 58 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index f1d8c7b..30ae8c7 100644 --- a/flake.nix +++ b/flake.nix @@ -3,11 +3,17 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + #nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; # gnome plugins broken + nixpkgs-2311.url = "github:NixOS/nixpkgs/nixos-23.11"; + unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; # https://github.com/nix-community/home-manager home-manager.url = "github:nix-community/home-manager/release-23.05"; + #home-manager.url = "github:nix-community/home-manager/release-23.11"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; + home-manager-2311.url = "github:nix-community/home-manager/release-23.11"; + home-manager-2311.inputs.nixpkgs.follows = "nixpkgs-2311"; # https://github.com/NixOS/nixos-hardware nixos-hardware.url = "github:NixOS/nixos-hardware"; @@ -23,6 +29,8 @@ # https://github.com/Mic92/sops-nix sops-nix.url = "github:Mic92/sops-nix"; sops-nix.inputs.nixpkgs.follows = "nixpkgs"; + sops-nix-2311.url = "github:Mic92/sops-nix"; + sops-nix-2311.inputs.nixpkgs.follows = "nixpkgs-2311"; /** / matrix-next.url = "github:dali99/nixos-matrix-modules"; # see https://git.pvv.ntnu.no/Drift/pvv-nixos-config/src/main/flake.nix @@ -62,17 +70,23 @@ outputs = { self, - nixpkgs, - unstable, + #nixpkgs, + #unstable, nixos-hardware, nixos-generators, - home-manager, + #home-manager, sops-nix, #flake-programs-sqlite, ... } @ inputs: let - flake = inputs: system: nixpkgs.lib.mapAttrs (name: flake: { + inputs-2311 = inputs // { + nixpkgs = inputs.nixpkgs-2311; + home-manager = inputs.home-manager-2311; + sops-nix = inputs.sops-nix-2311; + }; + + flake = inputs: system: inputs.nixpkgs.lib.mapAttrs (name: flake: { # TODO filter non-flake inputs nixos = flake.nixosModules or null; @@ -83,10 +97,10 @@ or flake.lib or null; }) inputs; - forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f rec { + forSystems = systems: f: inputs.nixpkgs.lib.genAttrs systems (system: f rec { inherit system; - pkgs = nixpkgs.legacyPackages.${system}; - lib = nixpkgs.legacyPackages.${system}.lib; + pkgs = inputs.nixpkgs.legacyPackages.${system}; + lib = inputs.nixpkgs.legacyPackages.${system}.lib; flakes = flake inputs system; }); forAllSystems = forSystems [ @@ -95,7 +109,7 @@ #"riscv64-linux" ]; - mkModule = hostname: domain: system: modules: ({ lib, ... }: { + mkModule = hostname: domain: system: inputs: modules: ({ lib, ... }: { #TODO: fix infinite recursion: /** / _module.args = lib.mkFinal { @@ -106,8 +120,8 @@ imports = [ ./base.nix "${self}/hosts/${hostname}" - sops-nix.nixosModules.sops - home-manager.nixosModule + inputs.sops-nix.nixosModules.sops + inputs.home-manager.nixosModule ] ++ modules; #++ flake-programs-sqlite.nixosModules.programs-sqlite; # TODO: make work @@ -135,12 +149,12 @@ nixpkgs.overlays = [ (final: prev: { #unstable = unstable.legacyPackages.${final.system}; - unstable = import unstable { inherit system; config.allowUnfree = true; }; # TODO: inherit nixos config from stable + unstable = import inputs.unstable { inherit system; config.allowUnfree = true; }; # TODO: inherit nixos config from stable }) ]; # This makes commandline tools like 'nix run nixpkgs#hello' # and 'nix-shell -p hello' use the same channel as system was built with - nix.registry.nixpkgs.flake = inputs.nixpkgs; + nix.registry.nixpkgs.flake = inputs.nixpkgs; nix.registry.nixpkgs-unstable.flake = inputs.unstable; #nix.registry.nixpkgs-unstable.flake.url = "github:NixOS/nixpkgs/nixos-unstable"; nix.nixPath = [ @@ -149,23 +163,23 @@ #"nixpkgs-unstable=github:NixOS/nixpkgs/nixos-unstable" ]; }); - mkConfig = hostname: domain: system: modules: nixpkgs.lib.nixosSystem { + mkConfig = hostname: domain: system: inputs: modules: inputs.nixpkgs.lib.nixosSystem { inherit system; specialArgs = { inherit inputs; flakes = flake inputs system; }; - modules = [ (mkModule hostname domain system modules) ]; + modules = [ (mkModule hostname domain system inputs modules) ]; }; mkHosts = mk: with nixos-hardware.nixosModules; { # TODO: move nixos-hardware imports to the nixos configs? - noximilien = mk "noximilien" "pbsds.net" "x86_64-linux" [ common-pc common-pc-ssd common-cpu-intel ]; - brumlebasse = mk "brumlebasse" "pbsds.net" "x86_64-linux" [ common-pc common-pc-ssd common-cpu-amd ]; - nord = mk "nord" "pbsds.net" "x86_64-linux" [ common-pc common-pc-ssd common-cpu-intel-cpu-only common-cpu-intel-sandy-bridge common-gpu-amd common-hidpi ]; - sopp = mk "sopp" "pbsds.net" "x86_64-linux" [ common-pc common-pc-ssd common-cpu-intel common-gpu-nvidia-nonprime ]; - bolle = mk "bolle" "pbsds.net" "x86_64-linux" [ common-pc common-pc-ssd common-cpu-intel ]; - eple = mk "eple" "pbsds.net" "x86_64-linux" [ common-pc common-pc-ssd common-cpu-intel ]; - garp = mk "garp" "pbsds.net" "x86_64-linux" [ common-pc common-pc-ssd common-cpu-intel ]; # TODO: common-gpu-nvidia-nonprime ]; + noximilien = mk "noximilien" "pbsds.net" "x86_64-linux" inputs [ common-pc common-pc-ssd common-cpu-intel ]; + brumlebasse = mk "brumlebasse" "pbsds.net" "x86_64-linux" inputs [ common-pc common-pc-ssd common-cpu-amd ]; + nord = mk "nord" "pbsds.net" "x86_64-linux" inputs [ common-pc common-pc-ssd common-cpu-intel-cpu-only common-cpu-intel-sandy-bridge common-gpu-amd common-hidpi ]; + sopp = mk "sopp" "pbsds.net" "x86_64-linux" inputs [ common-pc common-pc-ssd common-cpu-intel common-gpu-nvidia-nonprime ]; + bolle = mk "bolle" "pbsds.net" "x86_64-linux" inputs [ common-pc common-pc-ssd common-cpu-intel ]; + eple = mk "eple" "pbsds.net" "x86_64-linux" inputs [ common-pc common-pc-ssd common-cpu-intel ]; + garp = mk "garp" "pbsds.net" "x86_64-linux" inputs [ common-pc common-pc-ssd common-cpu-intel ]; # TODO: common-gpu-nvidia-nonprime ]; #gomperud smattkuken skrytebiffen skalkesnerken balleby brumlebasse bingus skjrlaltatjlstad #bergjlot snortheimsmoen ditlefsen skrukkerud podebusk zmaragd makrell alfnes blix urke eple hasselknippe pytte uddu imdorf rosenqvist }; @@ -199,7 +213,7 @@ nixosConfigurations = mkHosts mkConfig; homeConfigurations = forAllSystems ({ pkgs, flakes, ... }: let - mkHome = user: home: modules: home-manager.lib.homeManagerConfiguration { + mkHome = user: home: modules: inputs.home-manager.lib.homeManagerConfiguration { inherit pkgs; modules = modules ++ [{ home.username = user;