Skip to content

Instantly share code, notes, and snippets.

@shajra
Created January 1, 2020 18:27
Show Gist options
  • Save shajra/ae0e81539e891060ced0a5681f626acf to your computer and use it in GitHub Desktop.
Save shajra/ae0e81539e891060ced0a5681f626acf to your computer and use it in GitHub Desktop.
Is there a better way to override a library in Haskell.nix?
let
src = import ./sources.nix;
hnSrc = src."haskell.nix";
pinnedNixpkgsSrc = "${hnSrc}/nixpkgs";
hnArgsOrig = import hnSrc;
hnArgs = hnArgsOrig // {
nixpkgs-pin = "release-19.03";
# DESIGN: exposing an alternative "cabal-doctest" library in Nixpkgs.
#
overlays = hnArgsOrig.overlays ++ [(self: super: {
cabal-doctest = cabal-doctest-alt;
})];
};
pkgs = import pinnedNixpkgsSrc hnArgs;
hn = (import pinnedNixpkgsSrc hnArgs).haskell-nix;
# DESIGN: my alternative cabal-doctest Haskell library
#
cabal-doctest-alt = (hn.cabalProject {
name = "cabal-doctest-alt";
src = src.cabal-doctest;
}).cabal-doctest.components.library;
plan = hn.importAndFilterProject
(hn.callCabalProjectToNix {
name = "exceptions-checked";
src = ../.;
index-state = "2019-12-26T01:32:20Z";
index-sha256 = "1b9956ypjb65sigpwqiy6ylbk15mngg61h5a6q3panwalycnsbsg";
});
# DESIGN: I'm removing the reference to "cabal-doctest" from the plan, and
# it then finds it in the Nixpkgs overlay above.
#
modifiedPlan = plan.pkgs // {
pkgs = hackage: {
packages = builtins.removeAttrs (plan.pkgs.pkgs hackage).packages ["cabal-doctest"];
compiler = (plan.pkgs.pkgs hackage).compiler;
};
};
pkgSet = hn.mkCabalProjectPkgSet {
plan-pkgs = modifiedPlan;
modules = [({config, ...}: {
reinstallableLibGhc = true;
packages.exceptions-checked.components.tests.doctests = {
extraSrcFiles = [ "test" ];
preCheck = ''
ghc-pkg init dist/package.conf.inplace
'';
preConfigure = ''
substituteInPlace test/doctests.hs \
--replace "B.flags" "B.flags_exe_doctests" \
--replace "B.pkgs" "B.pkgs_exe_doctests" \
--replace "B.module_sources" "B.module_sources_exe_doctests"
'';
};
})];
};
in { inherit hn pkgs pkgSet plan; }
@ilyakooo0
Copy link

I made a thing that solves the problem: https://github.com/ilyakooo0/haskell-nix-extra-hackage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment