From c1d0ec60cc7af1ca4a5e7b96b0ff06f6913ea075 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Tue, 21 Oct 2025 18:00:17 -0400 Subject: [PATCH 1/3] wip --- flake.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index c14d903..b969c47 100644 --- a/flake.nix +++ b/flake.nix @@ -66,12 +66,18 @@ then path.pname or path.name or null else null; result = rec { - outPaths = lib.lists.flatten paths; + outPaths = lib.sort (a: b: a < b) (lib.lists.flatten paths); # Indexed by the path's unique name # Paths without such a name will be ignored. Hence, you must rely on `out_paths` for comprehensive list of outputs. byName = lib.foldl' (acc: path: let name = nameForStorePath path; - in if name == null then acc else acc // { "${name}" = path; } + in if name == null then acc else + acc // { + "${name}" = + if acc ? "${name}" + then acc.${name} ++ [ path ] + else [ path ]; + } ) { } outPaths; }; in From 41dbc2d0cd6de6309afd442ae1318190d2dd009c Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Tue, 21 Oct 2025 18:02:41 -0400 Subject: [PATCH 2/3] fix? --- flake.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index b969c47..732dd76 100644 --- a/flake.nix +++ b/flake.nix @@ -66,7 +66,9 @@ then path.pname or path.name or null else null; result = rec { - outPaths = lib.sort (a: b: a < b) (lib.lists.flatten paths); + outPaths = + let flattened = lib.lists.flatten paths; + in lib.sort (a: b: toString a < toString b) flattened; # Indexed by the path's unique name # Paths without such a name will be ignored. Hence, you must rely on `out_paths` for comprehensive list of outputs. byName = lib.foldl' (acc: path: From 21d3db95ad7fd475b5c33b8ed14bbffb53355fd3 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Tue, 21 Oct 2025 18:07:07 -0400 Subject: [PATCH 3/3] index by sys --- flake.nix | 76 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index 732dd76..553ff6b 100644 --- a/flake.nix +++ b/flake.nix @@ -53,39 +53,71 @@ }; }; }; - paths = + # Group paths by system + pathsBySystem = lib.flip lib.mapAttrsToList flakeSchema (_: lvlSchema: lib.flip lib.mapAttrsToList lvlSchema.getDrv (kind: getDrv: - builtins.concatMap - (attr: lib.mapAttrsToList getDrv attr) - (lvlSchema.lookupFlake kind inputs.flake) + # For perSystem outputs, return system-tagged paths + if lvlSchema ? lookupFlake && kind != "nixosConfigurations" && kind != "darwinConfigurations" + then + lib.flip builtins.map build-systems (sys: + let attr = lib.attrByPath [ kind sys ] { } inputs.flake; + in { + system = sys; + paths = lib.mapAttrsToList getDrv attr; + } + ) + else + # For flake-level outputs, assign based on target system + let attr = lib.attrByPath [ kind ] { } inputs.flake; + in lib.mapAttrsToList (_: cfg: + { + system = getSystem cfg; + paths = getDrv _ cfg; + } + ) attr ) ); nameForStorePath = path: if builtins.typeOf path == "set" then path.pname or path.name or null else null; - result = rec { - outPaths = - let flattened = lib.lists.flatten paths; - in lib.sort (a: b: toString a < toString b) flattened; - # Indexed by the path's unique name - # Paths without such a name will be ignored. Hence, you must rely on `out_paths` for comprehensive list of outputs. - byName = lib.foldl' (acc: path: - let name = nameForStorePath path; - in if name == null then acc else - acc // { - "${name}" = - if acc ? "${name}" - then acc.${name} ++ [ path ] - else [ path ]; - } - ) { } outPaths; - }; + + # Build result for each system + buildResultForSystem = sys: + let + systemPaths = lib.lists.flatten ( + lib.filter (x: x.system == sys) + (lib.lists.flatten (lib.lists.flatten pathsBySystem)) + ); + outPaths = + let flattened = lib.lists.flatten (map (x: x.paths) systemPaths); + in lib.sort (a: b: toString a < toString b) flattened; + in rec { + inherit outPaths; + byName = lib.foldl' (acc: path: + let name = nameForStorePath path; + in if name == null then acc else + acc // { "${name}" = path; } + ) { } outPaths; + }; + + result = lib.listToAttrs ( + map (sys: { + name = sys; + value = buildResultForSystem sys; + }) build-systems + ); in rec { json = pkgs.writeText "devour-output.json" (builtins.toJSON result); - default = pkgs.writeText "devour-output" (lib.strings.concatLines result.outPaths); + default = pkgs.writeText "devour-output" ( + lib.strings.concatLines ( + lib.lists.flatten ( + lib.mapAttrsToList (_: v: v.outPaths) result + ) + ) + ); } ); };