1
0
Fork 0
mirror of https://github.com/numtide/flake-utils.git synced 2024-12-14 11:47:31 +00:00
flake-utils/default.nix
zimbatm 8e1f14e82d
flattenTree: use / as the key separator
That character is less likely to be used in normal packaging names.
2020-07-22 11:35:16 +02:00

81 lines
1.8 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"
];
# 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}";
};
in
{
inherit
defaultSystems
eachDefaultSystem
eachSystem
flattenTree
mkApp
;
}