137 lines
3.0 KiB
Nix
137 lines
3.0 KiB
Nix
let
|
|
# copied from <nixpkgs/lib>
|
|
genAttrs = names: f:
|
|
builtins.listToAttrs (map (n: { name = n; value = f n; }) names);
|
|
|
|
mapAttrsToList = f: attrs:
|
|
map (name: f name attrs.${name}) (builtins.attrNames attrs);
|
|
|
|
# The list of systems supported by nixpkgs and hydra
|
|
defaultSystems = [
|
|
"aarch64-linux"
|
|
"i686-linux"
|
|
"x86_64-darwin"
|
|
"x86_64-linux"
|
|
];
|
|
|
|
# List of all systems defined in nixpkgs
|
|
# Keep in sync with nixpkgs wit the following command:
|
|
# $ nix-instantiate --json --eval --expr "with import <nixpkgs> {}; lib.platforms.all" | jq
|
|
allSystems = [
|
|
"aarch64-linux"
|
|
"armv5tel-linux"
|
|
"armv6l-linux"
|
|
"armv7a-linux"
|
|
"armv7l-linux"
|
|
"mipsel-linux"
|
|
"i686-cygwin"
|
|
"i686-freebsd"
|
|
"i686-linux"
|
|
"i686-netbsd"
|
|
"i686-openbsd"
|
|
"x86_64-cygwin"
|
|
"x86_64-freebsd"
|
|
"x86_64-linux"
|
|
"x86_64-netbsd"
|
|
"x86_64-openbsd"
|
|
"x86_64-solaris"
|
|
"x86_64-darwin"
|
|
"i686-darwin"
|
|
"aarch64-darwin"
|
|
"armv7a-darwin"
|
|
"x86_64-windows"
|
|
"i686-windows"
|
|
"wasm64-wasi"
|
|
"wasm32-wasi"
|
|
"x86_64-redox"
|
|
"powerpc64le-linux"
|
|
"riscv32-linux"
|
|
"riscv64-linux"
|
|
"arm-none"
|
|
"armv6l-none"
|
|
"aarch64-none"
|
|
"avr-none"
|
|
"i686-none"
|
|
"x86_64-none"
|
|
"powerpc-none"
|
|
"msp430-none"
|
|
"riscv64-none"
|
|
"riscv32-none"
|
|
"vc4-none"
|
|
"js-ghcjs"
|
|
"aarch64-genode"
|
|
"x86_64-genode"
|
|
];
|
|
|
|
# eachSystem using defaultSystems
|
|
eachDefaultSystem = eachSystem defaultSystems;
|
|
|
|
# Builds a map from <attr>=value to <system>.<attr>=value for each system.
|
|
#
|
|
#
|
|
eachSystem = systems: f:
|
|
let
|
|
op = attrs: system:
|
|
let
|
|
ret = f system;
|
|
op = attrs: key:
|
|
attrs //
|
|
{
|
|
${key} = (attrs.${key} or { }) // { ${system} = ret.${key}; };
|
|
}
|
|
;
|
|
in
|
|
builtins.foldl' op attrs (builtins.attrNames ret);
|
|
in
|
|
builtins.foldl' op { } systems
|
|
;
|
|
|
|
# Nix flakes insists on having a flat attribute set of derivations in
|
|
# various places like the `packages` and `checks` attributes.
|
|
#
|
|
# This function traverses a tree of attributes (by respecting
|
|
# recurseIntoAttrs) and only returns their derivations, with a flattened
|
|
# key-space.
|
|
#
|
|
# Eg:
|
|
#
|
|
# flattenTree { hello = pkgs.hello; gitAndTools = pkgs.gitAndTools };
|
|
#
|
|
# Returns:
|
|
#
|
|
# {
|
|
# hello = «derivation»;
|
|
# "gitAndTools/git" = «derivation»;
|
|
# "gitAndTools/hub" = «derivation»;
|
|
# # ...
|
|
# }
|
|
flattenTree = tree: import ./flattenTree.nix tree;
|
|
|
|
# Returns the structure used by `nix app`
|
|
mkApp =
|
|
{ drv
|
|
, name ? drv.pname or drv.name
|
|
, exePath ? drv.passthru.exePath or "/bin/${name}"
|
|
}:
|
|
{
|
|
type = "app";
|
|
program = "${drv}${exePath}";
|
|
};
|
|
|
|
# This function tries to capture a common flake pattern.
|
|
simpleFlake = import ./simpleFlake.nix { inherit lib; };
|
|
|
|
lib = {
|
|
inherit
|
|
allSystems
|
|
defaultSystems
|
|
eachDefaultSystem
|
|
eachSystem
|
|
flattenTree
|
|
mkApp
|
|
simpleFlake
|
|
;
|
|
};
|
|
in
|
|
lib
|