2020-04-22 15:12:09 +00:00
|
|
|
let
|
2020-04-11 14:45:25 +00:00
|
|
|
# The list of systems supported by nixpkgs and hydra
|
2020-04-22 15:12:09 +00:00
|
|
|
defaultSystems = [
|
2020-04-11 14:45:25 +00:00
|
|
|
"aarch64-linux"
|
2021-08-20 17:38:52 +00:00
|
|
|
"aarch64-darwin"
|
2020-04-11 14:45:25 +00:00
|
|
|
"x86_64-darwin"
|
|
|
|
"x86_64-linux"
|
|
|
|
];
|
|
|
|
|
2020-08-10 10:06:06 +00:00
|
|
|
# List of all systems defined in nixpkgs
|
|
|
|
# Keep in sync with nixpkgs wit the following command:
|
2022-05-14 19:26:36 +00:00
|
|
|
# $ nix-instantiate --json --eval --expr "with import <nixpkgs> {}; lib.platforms.all" | jq 'sort' | sed 's!,!!'
|
|
|
|
|
2020-08-10 10:06:06 +00:00
|
|
|
allSystems = [
|
2022-05-14 19:26:36 +00:00
|
|
|
"aarch64-darwin"
|
|
|
|
"aarch64-genode"
|
2020-08-10 10:06:06 +00:00
|
|
|
"aarch64-linux"
|
2022-05-14 19:26:36 +00:00
|
|
|
"aarch64-netbsd"
|
|
|
|
"aarch64-none"
|
|
|
|
"aarch64_be-none"
|
|
|
|
"arm-none"
|
2020-08-10 10:06:06 +00:00
|
|
|
"armv5tel-linux"
|
|
|
|
"armv6l-linux"
|
2022-05-14 19:26:36 +00:00
|
|
|
"armv6l-netbsd"
|
|
|
|
"armv6l-none"
|
|
|
|
"armv7a-darwin"
|
2020-08-10 10:06:06 +00:00
|
|
|
"armv7a-linux"
|
2022-05-14 19:26:36 +00:00
|
|
|
"armv7a-netbsd"
|
2020-08-10 10:06:06 +00:00
|
|
|
"armv7l-linux"
|
2022-05-14 19:26:36 +00:00
|
|
|
"armv7l-netbsd"
|
|
|
|
"avr-none"
|
2020-08-10 10:06:06 +00:00
|
|
|
"i686-cygwin"
|
2022-05-14 19:26:36 +00:00
|
|
|
"i686-darwin"
|
2020-08-10 10:06:06 +00:00
|
|
|
"i686-freebsd"
|
2022-05-14 19:26:36 +00:00
|
|
|
"i686-genode"
|
2020-08-10 10:06:06 +00:00
|
|
|
"i686-linux"
|
|
|
|
"i686-netbsd"
|
2022-05-14 19:26:36 +00:00
|
|
|
"i686-none"
|
2020-08-10 10:06:06 +00:00
|
|
|
"i686-openbsd"
|
|
|
|
"i686-windows"
|
2022-05-14 19:26:36 +00:00
|
|
|
"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"
|
2020-08-10 10:06:06 +00:00
|
|
|
"powerpc64le-linux"
|
2022-05-14 19:26:36 +00:00
|
|
|
"powerpcle-none"
|
2020-08-10 10:06:06 +00:00
|
|
|
"riscv32-linux"
|
2022-05-14 19:26:36 +00:00
|
|
|
"riscv32-netbsd"
|
|
|
|
"riscv32-none"
|
2020-08-10 10:06:06 +00:00
|
|
|
"riscv64-linux"
|
2022-05-14 19:26:36 +00:00
|
|
|
"riscv64-netbsd"
|
2020-08-10 10:06:06 +00:00
|
|
|
"riscv64-none"
|
2022-05-14 19:26:36 +00:00
|
|
|
"s390-linux"
|
|
|
|
"s390-none"
|
|
|
|
"s390x-linux"
|
|
|
|
"s390x-none"
|
2020-08-10 10:06:06 +00:00
|
|
|
"vc4-none"
|
2022-05-14 19:26:36 +00:00
|
|
|
"wasm32-wasi"
|
|
|
|
"wasm64-wasi"
|
|
|
|
"x86_64-cygwin"
|
|
|
|
"x86_64-darwin"
|
|
|
|
"x86_64-freebsd"
|
2020-08-10 10:06:06 +00:00
|
|
|
"x86_64-genode"
|
2022-05-14 19:26:36 +00:00
|
|
|
"x86_64-linux"
|
|
|
|
"x86_64-netbsd"
|
|
|
|
"x86_64-none"
|
|
|
|
"x86_64-openbsd"
|
|
|
|
"x86_64-redox"
|
|
|
|
"x86_64-solaris"
|
|
|
|
"x86_64-windows"
|
2020-08-10 10:06:06 +00:00
|
|
|
];
|
|
|
|
|
2022-01-20 17:42:55 +00:00
|
|
|
# A map from system to system. It's useful to detect typos.
|
|
|
|
#
|
|
|
|
# Instead of typing `"x86_64-linux"`, type `flake-utils.lib.system.x86_64-linux`
|
|
|
|
# and get an error back if you used a dash instead of an underscore.
|
|
|
|
system =
|
|
|
|
builtins.listToAttrs
|
|
|
|
(map (system: { name = system; value = system; }) allSystems);
|
|
|
|
|
2020-04-22 15:12:09 +00:00
|
|
|
# eachSystem using defaultSystems
|
|
|
|
eachDefaultSystem = eachSystem defaultSystems;
|
|
|
|
|
2021-10-21 21:17:30 +00:00
|
|
|
# Builds a map from <attr>=value to <attr>.<system>=value for each system,
|
|
|
|
# except for the `hydraJobs` attribute, where it maps the inner attributes,
|
|
|
|
# from hydraJobs.<attr>=value to hydraJobs.<attr>.<system>=value.
|
2020-04-11 14:45:25 +00:00
|
|
|
#
|
2020-04-22 15:12:09 +00:00
|
|
|
eachSystem = systems: f:
|
|
|
|
let
|
2021-11-28 17:59:42 +00:00
|
|
|
# Taken from <nixpkgs/lib/attrsets.nix>
|
|
|
|
isDerivation = x: builtins.isAttrs x && x ? type && x.type == "derivation";
|
|
|
|
|
|
|
|
# Used to match Hydra's convention of how to define jobs. Basically transforms
|
|
|
|
#
|
|
|
|
# hydraJobs = {
|
|
|
|
# hello = <derivation>;
|
|
|
|
# haskellPackages.aeson = <derivation>;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# to
|
|
|
|
#
|
|
|
|
# hydraJobs = {
|
|
|
|
# hello.x86_64-linux = <derivation>;
|
|
|
|
# haskellPackages.aeson.x86_64-linux = <derivation>;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# if the given flake does `eachSystem [ "x86_64-linux" ] { ... }`.
|
|
|
|
pushDownSystem = system: merged:
|
|
|
|
builtins.mapAttrs
|
|
|
|
(name: value:
|
|
|
|
if ! (builtins.isAttrs value) then value
|
|
|
|
else if isDerivation value then (merged.${name} or {}) // { ${system} = value; }
|
|
|
|
else pushDownSystem system (merged.${name} or {}) value);
|
|
|
|
|
|
|
|
# Merge together the outputs for all systems.
|
2020-04-22 15:12:09 +00:00
|
|
|
op = attrs: system:
|
|
|
|
let
|
|
|
|
ret = f system;
|
2020-04-22 15:17:40 +00:00
|
|
|
op = attrs: key:
|
2021-11-28 17:59:42 +00:00
|
|
|
let
|
|
|
|
appendSystem = key: system: ret:
|
|
|
|
if key == "hydraJobs"
|
|
|
|
then (pushDownSystem system (attrs.hydraJobs or {}) ret.hydraJobs)
|
|
|
|
else { ${system} = ret.${key}; };
|
|
|
|
in attrs //
|
|
|
|
{
|
|
|
|
${key} = (attrs.${key} or { })
|
|
|
|
// (appendSystem key system ret);
|
|
|
|
}
|
2020-05-02 20:51:26 +00:00
|
|
|
;
|
2020-04-22 15:12:09 +00:00
|
|
|
in
|
|
|
|
builtins.foldl' op attrs (builtins.attrNames ret);
|
|
|
|
in
|
2020-05-02 20:51:26 +00:00
|
|
|
builtins.foldl' op { } systems
|
|
|
|
;
|
2022-05-17 08:27:56 +00:00
|
|
|
|
|
|
|
# eachSystemMap using defaultSystems
|
|
|
|
eachDefaultSystemMap = eachSystemMap defaultSystems;
|
2022-01-20 17:46:32 +00:00
|
|
|
|
|
|
|
# Builds a map from <attr>=value to <system>.<attr> = value.
|
|
|
|
eachSystemMap = systems: f: builtins.listToAttrs (builtins.map (system: { name = system; value = f system; }) systems);
|
2020-04-11 17:29:17 +00:00
|
|
|
|
2020-07-22 08:38:25 +00:00
|
|
|
# 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»;
|
2020-07-22 09:35:14 +00:00
|
|
|
# "gitAndTools/git" = «derivation»;
|
|
|
|
# "gitAndTools/hub" = «derivation»;
|
2020-07-22 08:38:25 +00:00
|
|
|
# # ...
|
|
|
|
# }
|
|
|
|
flattenTree = tree: import ./flattenTree.nix tree;
|
2020-07-22 08:42:18 +00:00
|
|
|
|
2021-04-12 08:52:05 +00:00
|
|
|
# Nix check functionality validates packages for various conditions, like if
|
|
|
|
# they build for any given platform or if they are marked broken.
|
|
|
|
#
|
|
|
|
# This function filters a flattend package set for conditinos that
|
|
|
|
# would *trivially* break `nix flake check`. It does not flatten a tree and it
|
|
|
|
# does not implement advanced package validation checks.
|
|
|
|
#
|
|
|
|
# Eg:
|
|
|
|
#
|
|
|
|
# filterPackages "x86_64-linux" {
|
|
|
|
# hello = pkgs.hello;
|
|
|
|
# "gitAndTools/git" = pkgs.gitAndTools // {meta.broken = true;};
|
|
|
|
# };
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# hello = «derivation»;
|
|
|
|
# }
|
2021-05-11 19:05:05 +00:00
|
|
|
filterPackages = import ./filterPackages.nix { inherit allSystems; };
|
2021-04-12 08:52:05 +00:00
|
|
|
|
2020-07-22 08:42:18 +00:00
|
|
|
# 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}";
|
|
|
|
};
|
2020-07-22 08:38:25 +00:00
|
|
|
|
2020-08-23 13:28:05 +00:00
|
|
|
# This function tries to capture a common flake pattern.
|
2022-05-12 16:28:05 +00:00
|
|
|
simpleFlake = import ./simpleFlake.nix { inherit lib defaultSystems; };
|
2020-08-23 13:28:05 +00:00
|
|
|
|
2021-06-14 08:47:39 +00:00
|
|
|
# Helper functions for Nix evaluation
|
|
|
|
check-utils = import ./check-utils.nix;
|
|
|
|
|
2020-08-23 13:28:05 +00:00
|
|
|
lib = {
|
|
|
|
inherit
|
|
|
|
allSystems
|
2021-06-14 08:47:39 +00:00
|
|
|
check-utils
|
2020-08-23 13:28:05 +00:00
|
|
|
defaultSystems
|
|
|
|
eachDefaultSystem
|
|
|
|
eachSystem
|
2022-05-17 08:27:56 +00:00
|
|
|
eachDefaultSystemMap
|
2022-02-07 10:27:31 +00:00
|
|
|
eachSystemMap
|
2021-04-25 10:08:52 +00:00
|
|
|
filterPackages
|
2021-06-14 08:47:39 +00:00
|
|
|
flattenTree
|
2020-08-23 13:28:05 +00:00
|
|
|
mkApp
|
|
|
|
simpleFlake
|
2022-01-20 17:42:55 +00:00
|
|
|
system
|
2020-08-23 13:28:05 +00:00
|
|
|
;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib
|