~aasg/nixexprs

68211550c4cc7e33cbd6e8aa7932e6b915500c58 — Aluísio Augusto Silva Gonçalves 5 months ago f11028d
ci: Add Nix expression with all possible package configurations

The new ci.nix, when passed to nix-build:
1. runs the lib tests;
2. builds new packages when imported directly from ./pkgs;
3. builds new packages from the overlay;
4. builds patched packages from the overlay.

These should uncover issues in the direct-overlay translation, which
we'll need before consolidating */default.nix and */overlay.nix.

I don't think we'll support loading the patched packages directly,
moving forward.
5 files changed, 59 insertions(+), 11 deletions(-)

M .builds/nixos-20.03.yml
M .builds/nixos-20.09.yml
M .builds/nixpkgs-unstable.yml
A ci.nix
M lib/tests.nix
M .builds/nixos-20.03.yml => .builds/nixos-20.03.yml +1 -3
@@ 8,13 8,11 @@ sources:
secrets:
  - 06d44cfd-6ded-45c4-9ef4-8e1433f9054e
tasks:
  - test-lib: |
      nix-instantiate --eval --strict nixexprs/lib/tests.nix
  - prepare: |
      cachix use aasg-nixexprs
      nix path-info --all | grep -v '\.drv$' | sort >pre-build-paths
  - build: |
      nix-build --no-out-link --keep-going --keep-failed nixexprs || touch FAILED
      nix-build --no-out-link --keep-going --keep-failed ./nixexprs/ci.nix || touch FAILED
  - cache: |
      nix path-info --all | grep -v '\.drv$' | sort >post-build-paths
      comm -13 pre-build-paths post-build-paths | cachix push aasg-nixexprs

M .builds/nixos-20.09.yml => .builds/nixos-20.09.yml +1 -3
@@ 8,13 8,11 @@ sources:
secrets:
  - 06d44cfd-6ded-45c4-9ef4-8e1433f9054e
tasks:
  - test-lib: |
      nix-instantiate --eval --strict nixexprs/lib/tests.nix
  - prepare: |
      cachix use aasg-nixexprs
      nix path-info --all | grep -v '\.drv$' | sort >pre-build-paths
  - build: |
      nix-build --no-out-link --keep-going --keep-failed nixexprs || touch FAILED
      nix-build --no-out-link --keep-going --keep-failed ./nixexprs/ci.nix || touch FAILED
  - cache: |
      nix path-info --all | grep -v '\.drv$' | sort >post-build-paths
      comm -13 pre-build-paths post-build-paths | cachix push aasg-nixexprs

M .builds/nixpkgs-unstable.yml => .builds/nixpkgs-unstable.yml +2 -3
@@ 12,12 12,11 @@ tasks:
  - prepare: |
      cachix use aasg-nixexprs
      printf 'experimental-features = nix-command flakes\n' >>~/.config/nix/nix.conf
  - test: |
  - check-flake: |
      nix flake check --log-format raw ./nixexprs
      nix-instantiate --eval --strict ./nixexprs/lib/tests.nix
  - build: |
      nix path-info --all | grep -v '\.drv$' | sort >pre-build-paths
      nix-build --no-out-link --keep-going --keep-failed ./nixexprs || touch FAILED
      nix-build --no-out-link --keep-going --keep-failed ./nixexprs/ci.nix || touch FAILED
      nix path-info --all | grep -v '\.drv$' | sort >post-build-paths
  - cache: |
      comm -13 pre-build-paths post-build-paths | cachix push aasg-nixexprs

A ci.nix => ci.nix +52 -0
@@ 0,0 1,52 @@
{ pkgs ? import <nixpkgs> { }
, flake-utils-lib ? import (fetchTarball {
    url = "https://github.com/numtide/flake-utils/archive/588973065fce51f4763287f0fda87a174d78bf48.tar.gz";
    sha256 = "17h8rcp246y3444l9fp92jz1h5gp4gvgpnnd8rmhq686mdbha02r";
  })
}:
let
  inherit (pkgs.lib.attrsets) filterAttrs getAttrFromPath isDerivation listToAttrs mapAttrsToList nameValuePair recurseIntoAttrs;
  inherit (pkgs.lib.strings) concatStringsSep splitString;
  inherit (pkgs.lib.trivial) pipe;

  newPackages = pipe (import ./pkgs { inherit pkgs; }) [
    flake-utils-lib.flattenTree
    (filterAttrs (_: isDerivation))
    (mapAttrsToList (name: _: splitString "/" name))
  ];

  patchedPackages = pipe (import ./patches { inherit pkgs; }) [
    flake-utils-lib.flattenTree
    (filterAttrs (_: isDerivation))
    (mapAttrsToList (name: _: splitString "/" name))
  ];

  flattenAttrsFromPaths = paths: set:
    listToAttrs
      (map
        (path: nameValuePair (concatStringsSep "__" path) (getAttrFromPath path set))
        paths);
in
{
  lib = builtins.deepSeq (import ./lib/tests.nix { lib = pkgs.lib; }) { };

  newPackagesDirect = pipe { inherit pkgs; } [
    (import ./pkgs)
    (flattenAttrsFromPaths newPackages)
    recurseIntoAttrs
  ];

  newPackagesOverlay = pipe [ ./pkgs/overlay.nix ] [
    (map import)
    pkgs.appendOverlays
    (flattenAttrsFromPaths newPackages)
    recurseIntoAttrs
  ];

  patchedPackagesOverlay = pipe [ ./pkgs/overlay.nix ./patches/overlay.nix ] [
    (map import)
    pkgs.appendOverlays
    (flattenAttrsFromPaths patchedPackages)
    recurseIntoAttrs
  ];
}

M lib/tests.nix => lib/tests.nix +3 -2
@@ 1,8 1,9 @@
# To run the tests, do:
#
#     nix-instantiate --eval --strict ./tests.nix
#     nix-instantiate --eval --strict --expr 'import ./tests.nix {}'
{ lib ? (import <nixpkgs> { }).lib }:

with (import ../. { }).lib.extended;
with import ./extension.nix { inherit lib; };
let
  evalFailure = { success = false; value = false; };