1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-14 18:21:41 +03:00

.ci: Add instantiate-all.nix

This is to be used with `nix-env` in a CI situation to list everything
from release.nix.
This commit is contained in:
Samuel Dionne-Riel 2020-03-28 22:41:46 -04:00
parent 558907989b
commit 8b3bcc16db

63
.ci/instantiate-all.nix Normal file
View File

@ -0,0 +1,63 @@
# This file is used to flattenize release.nix for `nix-env` use.
# In turn, this is used by the CI steps for validating the evaluation is still
# working fine, and to get a list of diffs for the changes.
let
# Evaluate release.nix
release = import ../release.nix {
systems = [ "aarch64-linux" "x86_64-linux" ];
};
# Get "a" Nixpkgs for its lib.
pkgs = import <nixpkgs> {};
inherit (pkgs) lib;
# And import what we need in scope.
inherit (lib.attrsets) getAttrFromPath nameValuePair mapAttrs' mapAttrsToList;
inherit (lib.strings) splitString;
inherit (lib.lists) flatten;
# Given a path, returns the attrset at that path in release,
# with the attribute names prefixed with path.
dig = dig' release;
# Given a path, returns the attrset at that path in attrset,
# with the attribute names prefixed with path.
dig' = attrset: path:
mapAttrs' (name: value: nameValuePair "${path}.${name}" value)
(getAttrFromPath (splitString "." path) attrset)
;
# Flattened attrset of device builds.
devices =
let
# Listifies devices in a list of lists of nameValuePairs.
# This will be flattened and re-hydrated in a shallow attrset.
devicesList =
mapAttrsToList
(deviceName: list: mapAttrsToList (platformName: value: {
name = "device.${deviceName}.${platformName}";
value = value;
}) list)
release.device
;
in
builtins.listToAttrs (flatten devicesList)
;
flattened =
release //
devices //
# We could try and do something smart to unwrap two levels of attrsets
# automatically, but by stating we want those paths we are ensuring that
# they are still present in the attrsets.
(dig "overlay.aarch64-linux.aarch64-linux") //
(dig "overlay.x86_64-linux.aarch64-linux-cross") //
(dig "overlay.x86_64-linux.armv7l-linux-cross") //
(dig "overlay.x86_64-linux.x86_64-linux")
;
# Escape the name so `nix-env` will show it.
escapeName = builtins.replaceStrings ["."] ["++"];
in
mapAttrs'
(name: value: nameValuePair (escapeName name) value)
flattened