diff --git a/lib/buildTree.nix b/lib/buildTree.nix index f45fe7c..6e32ff1 100644 --- a/lib/buildTree.nix +++ b/lib/buildTree.nix @@ -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 @@ -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; @@ -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}"; diff --git a/lib/filterPackages.nix b/lib/filterPackages.nix new file mode 100644 index 0000000..fcb6449 --- /dev/null +++ b/lib/filterPackages.nix @@ -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