flake.nix: Dynamically import nixosConfigurations

This commit is contained in:
Donovan Glover 2024-04-08 10:58:32 -04:00
parent 30e0239cf7
commit 5f25e19d3f
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65
2 changed files with 18 additions and 16 deletions

View File

@ -4,10 +4,7 @@ let
inherit (builtins) attrValues; inherit (builtins) attrValues;
in in
{ {
imports = attrValues self.nixosModules ++ [ imports = attrValues self.nixosModules;
./hardware/laptop.nix
];
nixpkgs.overlays = attrValues self.overlays; nixpkgs.overlays = attrValues self.overlays;
home-manager.sharedModules = attrValues self.homeManagerModules; home-manager.sharedModules = attrValues self.homeManagerModules;
environment.systemPackages = attrValues self.packages.${pkgs.system}; environment.systemPackages = attrValues self.packages.${pkgs.system};

View File

@ -27,19 +27,11 @@
inherit (nixpkgs.legacyPackages.x86_64-linux) nixpkgs-fmt callPackage; inherit (nixpkgs.legacyPackages.x86_64-linux) nixpkgs-fmt callPackage;
inherit (builtins) attrNames listToAttrs map replaceStrings readDir; inherit (builtins) attrNames listToAttrs map replaceStrings readDir;
flakeOutputs = [ "overlays" "nixosModules" "homeManagerModules" "packages" "checks" ]; flakeOutputs = [ "overlays" "nixosModules" "nixosConfigurations" "homeManagerModules" "packages" "checks" ];
flakeDirectories = [ "overlays" "modules" "home" "packages" "tests" ]; flakeDirectories = [ "overlays" "modules" "hardware" "home" "packages" "tests" ];
in in
{ {
formatter.x86_64-linux = nixpkgs-fmt; formatter.x86_64-linux = nixpkgs-fmt;
nixosConfigurations = {
nixos = nixosSystem {
system = "x86_64-linux";
specialArgs = attrs // { nix-config = self; };
modules = [ ./. ];
};
};
} // } //
(listToAttrs (listToAttrs
(map (map
@ -52,7 +44,10 @@
attributeValue = (listToAttrs attributeValue = (listToAttrs
(map (map
(file: { (file: {
name = replaceStrings [ ".nix" ] [ "" ] file; name =
if file == "laptop.nix"
then "nixos"
else replaceStrings [ ".nix" ] [ "" ] file;
value = value =
if directory == "packages" if directory == "packages"
then callPackage ./${directory}/${file} { } then callPackage ./${directory}/${file} { }
@ -62,7 +57,17 @@
inherit self; inherit self;
pkgs = nixpkgs.legacyPackages.x86_64-linux; pkgs = nixpkgs.legacyPackages.x86_64-linux;
} }
else import ./${directory}/${file}; else
if directory == "hardware"
then nixosSystem {
system = "x86_64-linux";
specialArgs = attrs // { nix-config = self; };
modules = [
./.
./${directory}/${file}
];
}
else import ./${directory}/${file};
}) })
(attrNames (readDir ./${directory})))); (attrNames (readDir ./${directory}))));