Fix evaluation on Hydra (#153)

* Fix eval on Hydra

* Bump nixpkgs to latest 19.03

* Change unit tests into a derivation

Prevents Hydra from complaining about them.

* Add unpacked source pins to Hydra jobset

So that they are cached.
This commit is contained in:
Rodney Lorrimar 2019-06-02 07:21:21 +10:00 committed by GitHub
parent 831f372afe
commit 8512832c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 14 deletions

View File

@ -43,18 +43,20 @@ let
cleanSourceHaskell = pkgs.callPackage ./lib/clean-source-haskell.nix {};
# All packages from Hackage as Nix expressions
hackage = import (fetchExternal {
hackageSrc = fetchExternal {
name = "hackage-exprs-source";
specJSON = hackageSourceJSON;
override = "hackage";
});
};
hackage = import hackageSrc;
# The set of all Stackage snapshots
stackage = import (fetchExternal {
stackageSrc = fetchExternal {
name = "stackage-snapshot-source";
specJSON = stackageSourceJSON;
override = "stackage";
});
};
stackage = import stackageSrc;
packages = self: ({
# Utility functions for working with the component builder.
@ -196,6 +198,11 @@ let
inherit (pkgs.haskellPackages) hpack;
inherit (self) nix-tools;
};
# References to the unpacked sources, for caching in a Hydra jobset.
source-pins = self.callPackage ./lib/make-source-pins.nix {
sources = [ hackageSrc stackageSrc pkgs.path ];
};
});
in

11
lib/make-source-pins.nix Normal file
View File

@ -0,0 +1,11 @@
# Writes the store paths of a list of sources into a file.
# If this derivation is built by Hydra, then the sources will
# be kept and will be available to download from the binary cache.
{ lib, writeTextFile
, sources # A list of paths
}:
writeTextFile {
name = "haskell.nix-source-pins";
text = lib.concatMapStringsSep "\n" toString sources;
}

View File

@ -2,5 +2,9 @@ let
fetch = jsonFile:
with builtins;
let spec = fromJSON (readFile jsonFile);
in fetchTarball { inherit (spec) sha256; url = "${spec.url}/archive/${spec.rev}.tar.gz"; };
in fetchTarball {
name = "nixpkgs";
inherit (spec) sha256;
url = "${spec.url}/archive/${spec.rev}.tar.gz";
};
in import (fetch ./github.json)

View File

@ -1,7 +1,7 @@
{
"url": "https://github.com/nixos/nixpkgs",
"rev": "db85ded4aae63508934dc42064c7fbff16e0ec21",
"url": "https://github.com/NixOS/nixpkgs",
"rev": "0728c3e026e3ac2542a9673d57533829e552e218",
"date": "2019-05-17T15:35:26+02:00",
"sha256": "0b91n0s5zaamxh9842ns11s40678sv4pbpxaxdqnrnkrkp8pn9gy",
"sha256": "0sp8giack8na9hdm8ivk969mpwfcavqrfy7kncx0a1hs1ykw15hy",
"fetchSubmodules": false
}

View File

@ -1,6 +1,7 @@
let
haskell = import ./default.nix {};
in {
inherit (haskell) nix-tools;
inherit (haskell) nix-tools source-pins;
tests = import ./test { inherit haskell; };
}

View File

@ -18,12 +18,16 @@ in {
stack-simple = haskell.callPackage ./stack-simple {};
snapshots = haskell.callPackage ./snapshots {};
shell-for = haskell.callPackage ./shell-for {};
callStackToNix = haskell.callPackage ./callStackToNix {};
callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
# callStackToNix = haskell.callPackage ./callStackToNix {};
# callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
# Run unit tests with: nix-instantiate --eval --strict -A unit
# Run unit tests with: nix-instantiate --eval --strict -A unit.tests
# An empty list means success.
unit = haskell.callPackage ./unit.nix {};
unit = let
tests = haskell.callPackage ./unit.nix {};
in runCommand "unit-tests" { passthru = { inherit tests; }; }
(lib.concatMapStringsSep "\n" (t: "echo ${t.name} failed") tests +
(if builtins.length tests == 0 then "\ntouch $out" else "\nexit 1"));
}
## more possible test cases

View File

@ -16,7 +16,7 @@ nix build $NIX_BUILD_ARGS --no-link --keep-going -f ./default.nix
echo >& 2
printf "*** Running the unit tests... " >& 2
res=$(nix-instantiate --eval --json --strict ./default.nix -A unit)
res=$(nix-instantiate --eval --json --strict ./default.nix -A unit.tests)
num_failed=$(jq length <<< "$res")
if [ $num_failed -eq 0 ]; then
printf "PASSED\n" >& 2