From 1558b77796206dfaba45d4b724049075cbf38b8a Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Mon, 1 Apr 2024 11:48:10 -0400 Subject: [PATCH] feat(flake.nix): Separate outputs logic from variables Reduces complexity and makes things easier to reason about. --- flake.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 982fad17..d5dc9874 100644 --- a/flake.nix +++ b/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))); }