mirror of
https://github.com/donovanglover/nix-config.git
synced 2024-11-22 16:23:57 +01:00
feat(flake.nix): Separate outputs logic from variables
Reduces complexity and makes things easier to reason about.
This commit is contained in:
parent
dd6ab4cc97
commit
1558b77796
12
flake.nix
12
flake.nix
@ -24,6 +24,10 @@
|
||||
outputs = { self, nixpkgs, home-manager, stylix, ... } @ attrs: let
|
||||
inherit (nixpkgs.lib) nixosSystem;
|
||||
inherit (nixpkgs.legacyPackages.x86_64-linux) nixpkgs-fmt callPackage;
|
||||
|
||||
flakeOutputs = [ "overlays" "nixosModules" "homeManagerModules" "packages" ];
|
||||
flakeDirectories = [ "overlays" "modules" "home" "packages" ];
|
||||
packageDirectory = "packages";
|
||||
in {
|
||||
formatter.x86_64-linux = nixpkgs-fmt;
|
||||
|
||||
@ -57,14 +61,14 @@
|
||||
(attributeName: {
|
||||
name = attributeName;
|
||||
value = let
|
||||
directory = builtins.replaceStrings ["nixosModules" "homeManagerModules"] ["modules" "home"] attributeName;
|
||||
directory = builtins.replaceStrings flakeOutputs flakeDirectories attributeName;
|
||||
attributeValue = (builtins.listToAttrs
|
||||
(builtins.map
|
||||
(file: {
|
||||
name = builtins.replaceStrings [".nix"] [""] file;
|
||||
value = if directory == "packages" then callPackage ./${directory}/${file} { } else import ./${directory}/${file}; })
|
||||
value = if directory == packageDirectory then callPackage ./${directory}/${file} { } else import ./${directory}/${file}; })
|
||||
(builtins.attrNames (builtins.readDir ./${directory}))));
|
||||
attributeSet = if directory == "packages" then { x86_64-linux = attributeValue; } else attributeValue;
|
||||
attributeSet = if directory == packageDirectory then { x86_64-linux = attributeValue; } else attributeValue;
|
||||
in (attributeSet); })
|
||||
["overlays" "nixosModules" "homeManagerModules" "packages"]));
|
||||
(flakeOutputs)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user