Skip to content

Commit

Permalink
implementing overlays with haskellPackages
Browse files Browse the repository at this point in the history
  • Loading branch information
disassembler committed Nov 7, 2018
1 parent 16f74fa commit f9e8b48
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 15 deletions.
5 changes: 3 additions & 2 deletions clean-source-haskell.nix
@@ -1,5 +1,6 @@
src:
if (builtins.typeOf src) == "path"
pkgs: src:
let lib = pkgs.lib;
in if (builtins.typeOf src) == "path"
then lib.cleanSourceWith {
filter = with pkgs.stdenv;
name: type: let baseName = baseNameOf (toString name); in ! (
Expand Down
8 changes: 8 additions & 0 deletions default.nix
@@ -0,0 +1,8 @@
{
fetchNixpkgs = import ./fetch-nixpkgs.nix;
cleanSourceHaskell = import ./clean-source-haskell.nix;
haskellPackages = ./haskell-packages.nix;
maybeEnv = import ./maybe-env.nix;
jemallocOverlay = import ./overlays/jemalloc.nix;
getPackages = import ./get-packages.nix;
}
4 changes: 2 additions & 2 deletions fetch-nixpkgs.nix
@@ -1,5 +1,5 @@
let
spec = builtins.fromJSON (builtins.readFile ../nixpkgs-src.json);
srcJson: let
spec = builtins.fromJSON (builtins.readFile srcJson);
in builtins.fetchTarball {
url = "${spec.url}/archive/${spec.rev}.tar.gz";
inherit (spec) sha256;
Expand Down
5 changes: 5 additions & 0 deletions get-packages.nix
@@ -0,0 +1,5 @@
haskellPackages: filter:
let
cusutmPackages = lib.filterAttrs (name: drv: filter name) haskellPackages;
in
customPackages
23 changes: 15 additions & 8 deletions haskell-packages.nix
Expand Up @@ -2,11 +2,14 @@
, forceDontCheck
, enableProfiling
, enablePhaseMetrics
, enableHaddockHydra
, enableBenchmarks
, enableSplitCheck
, fasterBuild
, enableDebugging
, filter
, requiredOverlay
, pkgsGenerated
}:

with pkgs.lib;
Expand All @@ -16,23 +19,27 @@ let
ghc = pkgs.haskell.compiler.ghc822;

# This will yield a set of haskell packages, based on the given compiler.
kgsBase = ((import ../pkgs { inherit pkgs; }).override {
pkgsBase = ((import pkgsGenerated { inherit pkgs; }).override {
inherit ghc;
});

# Overlay logic for *haskell* packages.
requiredOverlay = import requiredOverlay { inherit pkgs enableProfiling; };
benchmarkOverlay = import ./overlays/benchmark.nix { inherit pkgs filter; };
debugOverlay = import ./overlays/debug.nix { inherit pkgs; };
fasterBuildOverlay = import ./overlays/faster-build.nix { inherit pkgs filter; };
dontCheckOverlay = import ./overlays/dont-check.nix { inherit pkgs; };
metricOverlay = import ./overlays/metric.nix { inherit pkgs; };
requiredOverlay' = import requiredOverlay { inherit pkgs enableProfiling; };
benchmarkOverlay = import ./overlays/benchmark.nix { inherit pkgs filter; };
debugOverlay = import ./overlays/debug.nix { inherit pkgs; };
fasterBuildOverlay = import ./overlays/faster-build.nix { inherit pkgs filter; };
dontCheckOverlay = import ./overlays/dont-check.nix { inherit pkgs; };
metricOverlay = import ./overlays/metric.nix { inherit pkgs; };
haddockHydraOverlay = import ./overlays/haddock-hydra.nix { inherit pkgs filter; };
splitCheckOverlay = import ./overlays/split-check.nix { inherit pkgs filter; };

activeOverlays = [ requiredOverlay ]
activeOverlays = [ requiredOverlay' ]
++ optional enablePhaseMetrics metricOverlay
++ optional enableBenchmarks benchmarkOverlay
++ optional enableDebugging debugOverlay
++ optional forceDontCheck dontCheckOverlay
++ optional forceDontCheck splitCheckOverlay
++ optional forceDontCheck haddockHydraOverlay
++ optional fasterBuild fasterBuildOverlay;

in
Expand Down
8 changes: 8 additions & 0 deletions maybe-env.nix
@@ -0,0 +1,8 @@
# Gets the value of an environment variable, with a default if it's
# unset or empty.
env: default:
let
result = builtins.getEnv env;
in if result != ""
then result
else default
7 changes: 5 additions & 2 deletions overlays/benchmark.nix
@@ -1,6 +1,9 @@
{ pkgs, filter }:
let
isBenchmark = args: !((args.isExecutable or false) || (args.isLibrary or true));

with import ../../lib.nix;
in { pkgs, filter }:

with pkgs.lib;

self: super: {
mkDerivation = args: super.mkDerivation (args // optionalAttrs (filter args.pname) {
Expand Down
2 changes: 1 addition & 1 deletion overlays/faster-build.nix
Expand Up @@ -3,7 +3,7 @@

{ pkgs, filter }:

with import ../../lib.nix;
with pkgs.lib;

self: super: {
mkDerivation = args: super.mkDerivation (args // optionalAttrs (filter args.pname) {
Expand Down
16 changes: 16 additions & 0 deletions overlays/haddock-hydra.nix
@@ -0,0 +1,16 @@
{ pkgs, filter }:

with pkgs.lib;

self: super: {
mkDerivation = args: super.mkDerivation (args // optionalAttrs (filter args.pname) {
doHaddock = true;
postInstall = ''
${args.postInstall or ""}
mkdir -pv $doc/nix-support
tar -czvf $doc/${args.pname}-docs.tar.gz -C $doc/share/doc/html .
echo "file binary-dist $doc/${args.pname}-docs.tar.gz" >> $doc/nix-support/hydra-build-products
echo "report ${args.pname}-docs.html $doc/share/doc/html index.html" >> $doc/nix-support/hydra-build-products
'';
});
}
9 changes: 9 additions & 0 deletions overlays/split-check.nix
@@ -0,0 +1,9 @@
{ pkgs, filter }:

with pkgs.lib;

self: super: {
mkDerivation = args: super.mkDerivation (args // optionalAttrs (filter args.pname) {
splitCheck = true;
});
}
11 changes: 11 additions & 0 deletions run-haskell.nix
@@ -0,0 +1,11 @@
name: pkgs: hspkgs: deps: env: code: let
lib = pkgs.lib;
ghc = hspkgs.ghcWithPackages deps;
flags = lib.optionalString pkgs.stdenv.isDarwin "-liconv"; # https://github.com/NixOS/nixpkgs/issues/46814
builtBinary = pkgs.runCommand "${name}-binary" { buildInputs = [ ghc ]; } ''
mkdir -p $out/bin/
ghc ${pkgs.writeText "${name}.hs" code} ${flags} -o $out/bin/${name}
'';
in pkgs.runCommand name env ''
${builtBinary}/bin/$name
''

0 comments on commit f9e8b48

Please sign in to comment.