Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement flattenTreeSystem #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ let
# }
flattenTree = tree: import ./flattenTree.nix tree;

# It turns out that we also need to filter by the supported system. This is
# the same thing as able, but that also looks at meta.hydraPlatforms or
# meta.platforms if the former is undefined.
flattenTreeSystem = system: tree: import ./flattenTreeSystem.nix system tree;

# Returns the structure used by `nix app`
mkApp =
{ drv
Expand All @@ -128,6 +133,7 @@ let
eachDefaultSystem
eachSystem
flattenTree
flattenTreeSystem
mkApp
simpleFlake
;
Expand Down
40 changes: 40 additions & 0 deletions flattenTreeSystem.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
system: tree:
let
op = sum: path: val:
let
pathStr = builtins.concatStringsSep "/" path;
in
# Ignore values that are not attrsets
if (builtins.typeOf val) != "set" then
sum
# For derivations
else if val ? type && val.type == "derivation" then
let
meta = val.meta or { };
platforms = meta.hydraPlatforms or meta.platforms or [ ];
in
# Only include those that target this system
if builtins.any (p: p == system) platforms then
(sum // {
# We used to use the derivation outPath as the key, but that crashes Nix
# so fallback on constructing a static key
"${pathStr}" = val;
})
else
sum
# Recurse into attrsets who have that key
else if (val.recurseForDerivations or false) == true then
recurse sum path val
# Ignore that value as well
else
sum
;

recurse = sum: path: val:
builtins.foldl'
(sum: key: op sum (path ++ [ key ]) val.${key})
sum
(builtins.attrNames val)
;
in
recurse { } [ ] tree
2 changes: 1 addition & 1 deletion simpleFlake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let
legacyPackages = packages;

# Flake expects a flat attrset containing only derivations as values
packages = lib.flattenTree packages;
packages = lib.flattenTreeSystem system packages;
}
//
(
Expand Down