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

WIP feat: add supported systems filter #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
80 changes: 78 additions & 2 deletions lib/buildTree.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
{ path
, args
, supportedSystems ? [
"aarch64-darwin"
"aarch64-genode"
"aarch64-linux"
"aarch64-netbsd"
"aarch64-none"
"aarch64_be-none"
"arm-none"
"armv5tel-linux"
"armv6l-linux"
"armv6l-netbsd"
"armv6l-none"
"armv7a-darwin"
"armv7a-linux"
"armv7a-netbsd"
"armv7l-linux"
"armv7l-netbsd"
"avr-none"
"i686-cygwin"
"i686-darwin"
"i686-freebsd"
"i686-genode"
"i686-linux"
"i686-netbsd"
"i686-none"
"i686-openbsd"
"i686-windows"
"js-ghcjs"
"m68k-linux"
"m68k-netbsd"
"m68k-none"
"mips64el-linux"
"mipsel-linux"
"mipsel-netbsd"
"mmix-mmixware"
"msp430-none"
"or1k-none"
"powerpc-netbsd"
"powerpc-none"
"powerpc64-linux"
"powerpc64le-linux"
"powerpcle-none"
"riscv32-linux"
"riscv32-netbsd"
"riscv32-none"
"riscv64-linux"
"riscv64-netbsd"
"riscv64-none"
"s390-linux"
"s390-none"
"s390x-linux"
"s390x-none"
"vc4-none"
"wasm32-wasi"
"wasm64-wasi"
"x86_64-cygwin"
"x86_64-darwin"
"x86_64-freebsd"
"x86_64-genode"
"x86_64-linux"
"x86_64-netbsd"
"x86_64-none"
"x86_64-openbsd"
"x86_64-redox"
"x86_64-solaris"
"x86_64-windows"
]
}:
let
# copied from <nixpkgs/lib>
Expand Down Expand Up @@ -96,7 +163,16 @@ let
callBuildWith = args: path:
import "${toString path}/BUILD.nix" args;

root = { self = readBuildTree path; } // args;
hasSupport = kernel: builtins.foldl' (x: y: x || y) false (map (i: builtins.match (".+-" + kernel) i != null) supportedSystems);
hasLinuxSupport = hasSupport "linux";
hasDarwinSupport = hasSupport "darwin";

root = {
self = readBuildTree path // { inherit hasLinuxSupport hasDarwinSupport; };
inherit supportedSystems;
} // args;

filterPackages = import ./filterPackages.nix { inherit supportedSystems; };

callBuild = callBuildWith root;

Expand All @@ -113,7 +189,7 @@ let
;
subDirs = lib.filterAttrs dirFilter dir;

buildAttrs = if dir ? "BUILD.nix" then callBuild path else { };
buildAttrs = if dir ? "BUILD.nix" then filterPackages supportedSystems (callBuild path) else { };

op = name: _: readBuildTree "${toString path}/${toString name}";

Expand Down
34 changes: 34 additions & 0 deletions lib/filterPackages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ supportedSystems }:
system: packages:
let
# Adopted from nixpkgs.lib
inherit (builtins) listToAttrs concatMap attrNames filter;
nameValuePair = name: value: { inherit name value; };
intersectLists = e: filter (x: builtins.elem x e);
filterAttrs = pred: set:
listToAttrs (
concatMap
(name:
let v = set.${name}; in
if pred name v then [ (nameValuePair name v) ] else [ ]
)
(attrNames set)
);

# Everything that nix flake check requires for the packages output
sieve = n: v:
with v;
let
inherit (builtins) isAttrs;
isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
isBroken = meta.broken or false;
platforms = meta.platforms or supportedSystems;
badPlatforms = meta.badPlatforms or [ ];
in
# check for isDerivation, so this is independently useful of
# flattenTree, which also does filter on derivations
(isDerivation v && !isBroken && (builtins.length (intersectLists supportedSystems platforms) > 0) &&
!(builtins.elem system badPlatforms)) || (!isDerivation v)
;
in
filterAttrs sieve packages