Failing to override network dependency for bson

Reproducible github repo (or as I recently learned you can nix-build each different expression snippet standalone!).

I wanted to use the latest unstable and Haskell’s developPackage nix function to do something with the bson library.

I made the following default.nix:

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage { root = ./.;};
in pkg

I got an error about bson being broken:

[cody@nixos:~/haskell-nix-min-repro]$ nix-build default.nix 
error: Package ‘bson-0.4.0.1’ in /nix/store/2h7bbn0kxlnkxnqhqg03jk0w0jpxkaz6-source/pkgs/development/haskell-modules/hackage-packages.nix:44162 is marked as broken, refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowBroken = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowBroken = true; }
to ~/.config/nixpkgs/config.nix.

(use '--show-trace' to show detailed location information)

No problem, I can just override it since I finally know how to properly use overrides in this context:

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage
    { root = ./.;
      # change: adding overrides
      overrides = self: super: {
        bson = pkgs.haskellPackages.callHackage "bson" "0.4.0.1" {};
      };
    };
in pkg

Then I get this error about network and network-bsd being the wrong versions.

[cody@nixos:~/haskell-nix-min-repro]$ nix-build default.nix 
... longer output without errors ...
Setup: Encountered missing or private dependencies:
network <2.9, network-bsd >=2.7 && <2.9
...

I see that bson has a _old-network flag so maybe removing that lets me use newer versions?

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage
    { root = ./.;
      overrides = self: super: {
        # change: using disableCabalFlag
        bson = pkgs.haskell.lib.disableCabalFlag (
          pkgs.haskellPackages.callHackage "bson" "0.4.0.1" {}
        ) "_old-network";
      };
    };
in pkg

Removing that flag apparently locks mongoDB to use network-bsd >=2.7 && <2.9?

[cody@nixos:~/haskell-nix-min-repro]$ nix-build default.nix 
... output without errors ...
Setup: Encountered missing or private dependencies:
network-bsd >=2.7 && <2.9
...

Alright, let’s try to provide it network-bsd >=2.7 && <2.9:

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage
    { root = ./.;
      overrides = self: super: {
        # change: add network-bsd to overrides
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
        bson = pkgs.haskell.lib.disableCabalFlag (
          pkgs.haskellPackages.callHackage "bson" "0.4.0.1" {}
        ) "_old-network";
      };
    };
in pkg

Error:

Setup: Encountered missing or private dependencies:
network-bsd >=2.7 && <2.9

What? Didn’t I just provide it with that?

Okay fine… there is something called source-overrides in developPackages too. What if we put network-bsd there?

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage
    { root = ./.;
      overrides = self: super: {
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
        bson = pkgs.haskell.lib.disableCabalFlag (
          pkgs.haskellPackages.callHackage "bson" "0.4.0.1" {}
        ) "_old-network";
      };
      source-overrides = {
        # change: add network-bsd to source-overrides in case it was supposed to go there. What is the difference?
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
      };
    };
in pkg

error:

Setup: Encountered missing or private dependencies:
network-bsd >=2.7 && <2.9

Well that didn’t do anything and I’m not sure where to go from here. Can anyone explain where I went wrong, what I should do to fix it, or how I could figure this out?

Edit: This worked it seems:

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/75ae5f3de85340f4e6e13334eecb9c8aad4cc2ab.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage
    { root = ./.;
      overrides = self: super: {
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
        # change: explicitly call pkgs.haskell.lib.addBuildDepends instead of relying on override to apply to all overrides dependencies as well
        bson = pkgs.haskell.lib.addBuildDepends (
          pkgs.haskell.lib.disableCabalFlag (
            pkgs.haskellPackages.callHackage "bson" "0.4.0.1" {}
          ) "_old-network")
          [(pkgs.haskellPackages.callHackage "network-bsd" "2.8.1.0" {})];
      };
      source-overrides = {
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
      };
    };
in pkg

Is this how you have to add build depends to each overlay items dependencies?

Maybe if I use self.callHackage instead of pkgshaskellPackages.callHackage`?

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/75ae5f3de85340f4e6e13334eecb9c8aad4cc2ab.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage
    { root = ./.;
      overrides = self: super: {
        # change: use self.callHackage
        network-bsd = self.callHackage "network-bsd" "2.8.1.0" {};
        bson =
          pkgs.haskell.lib.disableCabalFlag (
           # change: use self.callHackage
            self.callHackage "bson" "0.4.0.1" {}
          ) "_old-network";
      };
      source-overrides = {
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
      };
    };
in pkg

Nope, back to the familar error of:

Setup: Encountered missing or private dependencies:
network-bsd >=2.7 && <2.9

I’ll stick with the working version and ask: Is there a better way to write this?

{ compilerVersion ? "ghc883" ,
  pkgs ?
  import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/75ae5f3de85340f4e6e13334eecb9c8aad4cc2ab.tar.gz")
    {}}:
let
  compiler = pkgs.haskell.packages."${compilerVersion}";
  pkg = compiler.developPackage
    { root = ./.;
      overrides = self: super: {
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
        bson = pkgs.haskell.lib.addBuildDepends (
          pkgs.haskell.lib.disableCabalFlag (
            pkgs.haskellPackages.callHackage "bson" "0.4.0.1" {}
          ) "_old-network")
          [(pkgs.haskellPackages.callHackage "network-bsd" "2.8.1.0" {})];
      };
      source-overrides = {
        network-bsd = pkgs.callHackage "network-bsd" "2.8.1.0" {};
      };
    };
in pkg

@codygman Here’s how I would write this, along with a bunch of comments trying to explain what is going on:

let
  # This is the source of nixpkgs we will use.
  #
  # Generally you want a comment on the URL about where this nixpkgs came from.
  # Is it `master`?  Is it one of the release branches?  What is the
  # approximate date it came from?
  #
  # It is possible to figure out these things using `git`, but in general it is
  # nice if you leave a comment for the future reader.
  nixpkgs-src = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz";
    # When you use fetchTarball, if at all possible, you always want to specify
    # a sha256.  This makes sure the tarball will be stored in the /nix/store,
    # so you don't have to frequently re-download it.
    sha256 = "sha256:1jxsaynvj7cis3sdxbs596lxm9wyl0kf8a4519xfxzg8x45wc8cr";
  };

  # This is a full nixpkgs overlay.
  #
  # We only define one new package, the Haskell package set with our overridden
  # packages.
  my-overlay = self: super: {
    # This is a new Haskell package set.  It is built on the `haskellPackages`
    # package set from nixpkgs, but we overrode `bson` and `network-bsd`.
    #
    # The reason for creating a new package set instead of just re-using
    # `haskellPackages` is to make it simpler to get unmodified programs from
    # the normal `haskellPackages`. See
    # https://discourse.nixos.org/t/nix-haskell-development-2020/6170/2?u=cdepillabout
    # for more information.
    #
    # Note that you should make sure to use `haskellPackages.override` here
    # instead of `haskellPackages.extend`, although I don't really understand
    # why this is the case.  I only knew this because I normally see
    # `haskellPackages.override` instead of `haskellPackages.extend`.
    my-haskell-packages = super.haskellPackages.override {
      # These are the actual overrides for the Haskell package set.
      #
      # This is where we override `bson` and `network-bsd`.
      overrides = hSelf: hSuper: {
        bson =
          let
            # I'm not sure why this is needed, but I just followed your example
            # in the first post.  I just overrode hSuper.bson instead of
            # getting it from hackage with callHackage.
            bson-with-disabled-flag =
              self.haskell.lib.disableCabalFlag hSuper.bson "_old-network";

            # It looks like bson is marked broken, so we can unbreak it.
            #
            # I did this instead of getting it from Hackage with callHackage,
            # but it doesn't really matter here.
            bson-unbroken = self.haskell.lib.markUnbroken bson-with-disabled-flag;

            # Disabling the `_old-network` flag in bson appears to add
            # network-bsd as a dependency, so we have to go ahead and add that
            # here ourselves.
            bson-with-build-depend =
              self.haskell.lib.addBuildDepend bson-unbroken hSelf.network-bsd;
          in
          bson-with-build-depend;

        # bson apparently needs an old version of `network-bsd`.
        network-bsd = hSelf.callHackage "network-bsd" "2.8.1.0" {};
      };
    };
  };

  # Apply our overlays to nixpkgs.
  nixpkgs = import nixpkgs-src { overlays = [ my-overlay ]; };

  # This is our local package.
  #
  # I created a new Haskell package set, and set `bson` and `network-bsd`
  # overrides on it, instead of using the arguments to `developPackage`, but
  # you could probably do either.
  #
  # Personally I think it is easier doing it the way it is in this file, but
  # either are probably valid.
  #
  # In your original file, I'm not sure why you had to have both `overrides`
  # and `source-overrides`.
  pkg = nixpkgs.my-haskell-packages.developPackage { root = ./.; };
in
pkg

Let me know if this doesn’t answer any of your questions.

1 Like

Thanks so much! This does build with nix build but it appears within nix-shell I cannot import MyLibrary with:

$ nix-shell --pure --run "ghci"
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
Prelude> import MyLibrary

<no location info>: error:
    Could not find module ‘MyLibrary’
    It is not a module in the current program, or in any known package.

Then I thought maybe I should use cabal repl but it’s not available either:

$ nix-shell --pure --run "cabal repl"
/tmp/nix-shell-9805-0/rc: line 1: cabal: command not found

I thought that developPackage takes care of setting up a shell that you can use cabal repl in for instance or at least makes all your modules in your custom haskell package set available to ghci.

I tried using shellFor without luck, but I think that might be the key here?

Maybe it’s a simple package.yaml error and not a nix error here, but I’m not sure enough of understanding nix to know for sure.

I have other questions but I want to try solving them first and reflecting a bit before asking the rest.

I found an example doing something like adding cabal-install to developPackage and successfully added cabal-install/cabal repl but I still have some issue:

# .. above is like before ...
  developPackage = nixpkgs.my-haskell-packages.developPackage { root = ./.; };
in
  developPackage.overrideAttrs (oldAttrs: with nixpkgs; {
    buildInputs = oldAttrs.buildInputs
      ++ [  haskellPackages.cabal-install ];
  })

Error:

[cody@nixos:~/haskell-nix-min-repro]$ nix-shell --pure --run "cabal repl"
Warning: The package list for 'hackage.haskell.org' is 149 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Build profile: -w ghc-8.8.3 -O1
In order, the following will be built (use -v for more details):
 - fake-package-0 (lib) (first run)
Configuring library for fake-package-0..
Preprocessing library for fake-package-0..
Warning: No exposed modules
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /run/user/1000/cabal-repl.-16815/setcwd.ghci
Prelude> import MyLibrary

<no location info>: error:
    Could not find module ‘MyLibrary’
    It is not a module in the current program, or in any known package.

Maybe it’s not loading MyLibrary in cabal repl’s view because I’m using package.yaml instead of a cabal file?

I don’t have time to try, but maybe I need to add my package with overrideCabal like this?

A few other approaches I can’t try now that may work or I may be able to adapt:

I think this is because developPackage is setup to actually build your package when you run nix-build, but when you run nix-shell, it just sets you up in an environment with all your dependencies available, but your package has not yet been built.

So it is expected that if you run ghci, you won’t be able to load any modules from your package. (Although you should be able to load modules from dependencies).

You’ll need to include cabal-install into your nix-shell environment, as it appears you’ve figured out.

You should be able to then run cabal build or cabal new-build.

However, since you don’t have a .cabal file, you’ll first have to run hpack. After that, you should hopefully be able to run cabal build to build your project.

Thanks! That is working now after adding pkg.overrideAttrs .... I ran into a weird issue trying to add HPDF where a native dependency was failing for Haskell Test Framework however so I went to find the last time it built on hydra and tried pinning that nixpkg revision.

I think I have the syntax mostly right… but there’s some weird detail I’m not getting. Here is my default.nix along with the error inline about HTF being marked as broken even though I used markUnbroken:

let
  nixpkgs-src = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz";
    sha256 = "sha256:1jxsaynvj7cis3sdxbs596lxm9wyl0kf8a4519xfxzg8x45wc8cr";
  };
  HTF-nixpkgs = import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/1caac6f2dc467dd67eff688f3a9befdad5d0f9d0.tar.gz")
    {};
  my-overlay = self: super: {
    my-haskell-packages = super.haskellPackages.override {
      overrides = hSelf: hSuper: {
        bson =
          let
            bson-with-disabled-flag =
              self.haskell.lib.disableCabalFlag hSuper.bson "_old-network";
            bson-unbroken = self.haskell.lib.markUnbroken bson-with-disabled-flag;
            bson-with-build-depend =
              self.haskell.lib.addBuildDepend bson-unbroken hSelf.network-bsd;
          in
          bson-with-build-depend;
        network-bsd = hSelf.callHackage "network-bsd" "2.8.1.0" {};
        HPDF =
          let
            unbroken-old-HTF = self.haskell.lib.markUnbroken HTF-nixpkgs.haskellPackages.HTF;
            unbroken-HPDF = self.haskell.lib.markUnbroken self.haskellPackages.HPDF;
            unbroken-HPDF-with-old-HTF = self.haskell.lib.addBuildDepend unbroken-HPDF unbroken-old-HTF;
          in unbroken-HPDF-with-old-HTF;
        # error:
# nix-build  #
# building '/nix/store/zlcp518lf55ahfasmr7nx59zgbxamrk1-cabal2nix-haskell-nix-minimal.drv'...
# installing
# error: Package ‘HTF-0.14.0.3’ in /nix/store/2h7bbn0kxlnkxnqhqg03jk0w0jpxkaz6-source/pkgs/development/haskell-modules/hackage-packages.nix:9299 is marked as broken, refusing to evaluate.
      };
    };
  };

  nixpkgs = import nixpkgs-src { overlays = [ my-overlay ]; };

  pkg = nixpkgs.my-haskell-packages.developPackage { root = ./.; };
in
pkg.overrideAttrs (attrs: {
        buildInputs = attrs.buildInputs ++ [ nixpkgs.haskellPackages.cabal-install ];
    })

After looking at some examples of usages of source-overrides I think it might be used for this?

Also I realized I can just find the last successful HPDF build: https://hydra.nixos.org/build/86308108#tabs-buildinputs

That led to this failed attempt:

let
  nixpkgs-src = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz";
    sha256 = "sha256:1jxsaynvj7cis3sdxbs596lxm9wyl0kf8a4519xfxzg8x45wc8cr";
  };
  HTF-nixpkgs = import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/0b0c67e5378ccc4f4eef3a7e88eb2acb1127d50f.tar.gz")
    {};
  my-overlay = self: super: {
    my-haskell-packages = super.haskellPackages.override {
      overrides = hSelf: hSuper: {
        bson =
          let
            bson-with-disabled-flag =
              self.haskell.lib.disableCabalFlag hSuper.bson "_old-network";
            bson-unbroken = self.haskell.lib.markUnbroken bson-with-disabled-flag;
            bson-with-build-depend =
              self.haskell.lib.addBuildDepend bson-unbroken hSelf.network-bsd;
          in
            bson-with-build-depend;
        network-bsd = hSelf.callHackage "network-bsd" "2.8.1.0" {};
      };
    };
  };

  nixpkgs = import nixpkgs-src { overlays = [ my-overlay ]; };

  pkg = nixpkgs.my-haskell-packages.developPackage {
    root = ./.;
    source-overrides = {
      HPDF = HTF-nixpkgs.haskellPackages.HPDF;
    };
  };
in
pkg.overrideAttrs (attrs: {
  buildInputs = attrs.buildInputs ++ [ nixpkgs.haskellPackages.cabal-install ];
})

Which resulted in an even more confusing error:

[cody@nixos:~/haskell-nix-minimal]$ nix-build
building '/nix/store/sk6i0z1skj8yibvzbj91yzxm40vl4xgh-cabal2nix-HPDF.drv'...
installing
cabal2nix: nix-prefetch-url: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
builder for '/nix/store/sk6i0z1skj8yibvzbj91yzxm40vl4xgh-cabal2nix-HPDF.drv' failed with exit code 1
error: build of '/nix/store/sk6i0z1skj8yibvzbj91yzxm40vl4xgh-cabal2nix-HPDF.drv' failed
(use '--show-trace' to show detailed location information)

In nix-repl I can see that HPDF is available in HTF-nixpkgs:


nix-repl> HTF-nixpkgs = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/0b0c67e5378ccc4f4eef3a7e88eb2acb1127d50f.tar.gz") {}  

nix-repl> HTF-nixpkgs.haskellPackages.HPDF   

Reducing to just the HPDF case and calling markUnbroken gratuitously:

let
  nixpkgs-src = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz";
    sha256 = "sha256:1jxsaynvj7cis3sdxbs596lxm9wyl0kf8a4519xfxzg8x45wc8cr";
  };
  HTF-nixpkgs = import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/1caac6f2dc467dd67eff688f3a9befdad5d0f9d0.tar.gz")
    {};
  my-overlay = self: super: {
    my-haskell-packages = super.haskellPackages.override {
      overrides = hSelf: hSuper: {
        HPDF =
          let
            unbroken-old-HTF = self.haskell.lib.markUnbroken HTF-nixpkgs.haskellPackages.HTF;
            unbroken-HPDF = self.haskell.lib.markUnbroken self.haskellPackages.HPDF;
            unbroken-HPDF-with-old-HTF = self.haskell.lib.markUnbroken
              (self.haskell.lib.addBuildDepend unbroken-HPDF unbroken-old-HTF);
          in unbroken-HPDF-with-old-HTF;
      };
    };
  };

  nixpkgs = import nixpkgs-src { overlays = [ my-overlay ]; };

  pkg = nixpkgs.my-haskell-packages.developPackage { root = ./.; };
in
pkg.overrideAttrs (attrs: {
  buildInputs = attrs.buildInputs ++ [ nixpkgs.haskellPackages.cabal-install ];
})

error:

nix-build
error: Package ‘HTF-0.14.0.3’ in /nix/store/2h7bbn0kxlnkxnqhqg03jk0w0jpxkaz6-source/pkgs/development/haskell-modules/hackage-packages.nix:9299 is marked as broken, refusing to evaluate.

This does what I was aiming for, but it doesn’t fix the problem. HTF uses older c compiler flags that are no longer compatible with the c compiler in ghc 8.8.3. I thought that I could pin a version of HTF that built not long ago but that can’t work because the c code will still be processed by the c compiler bundled with ghc 8.8.3.

Here’s the default.nix anyway:

let
  nixpkgs-src = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/3567e1f6cc204f3b999431ce9e182a86e115976f.tar.gz";
    sha256 = "sha256:1jxsaynvj7cis3sdxbs596lxm9wyl0kf8a4519xfxzg8x45wc8cr";
  };
  HTF-nixpkgs = import (builtins.fetchTarball
    "https://github.com/NixOS/nixpkgs/archive/1caac6f2dc467dd67eff688f3a9befdad5d0f9d0.tar.gz")
    {};
  unbroken-old-HTF = HTF-nixpkgs.haskell.lib.markUnbroken HTF-nixpkgs.haskellPackages.HTF;
  my-overlay = self: super: {
    my-haskell-packages = super.haskellPackages.override {
      overrides = hSelf: hSuper: {
        HTF = self.haskell.lib.markUnbroken self.haskellPackages.HTF;
        HPDF =
          let
            unbroken-HPDF = self.haskell.lib.markUnbroken hSuper.HPDF;
            unbroken-HPDF-with-old-HTF = self.haskell.lib.addBuildDepend unbroken-HPDF unbroken-old-HTF;
          in unbroken-HPDF-with-old-HTF;
      };
    };
  };

  nixpkgs = import nixpkgs-src { overlays = [ my-overlay ]; };

  pkg = nixpkgs.my-haskell-packages.developPackage { root = ./.; };
in
pkg.overrideAttrs (attrs: {
  buildInputs = attrs.buildInputs ++ [ nixpkgs.haskellPackages.cabal-install ];
})

Do you have this code up online anywhere?

It’s hard to help you with this kind of stuff without an actual project to play around a with.


Also, I should add that in general you can’t take Haskell packages from multiple different package sets. You need to get them all from the same package set.

Yes… I forgot to post it :worried:

Here’s a working derivation:

let
  nixpkgs-src = builtins.fetchTarball {
    # If you search for HPDF on Hydra (https://hydra.nixos.org/search?query=HPDF),
    # you can see that the last successful build was in 18.09: https://hydra.nixos.org/build/89581306
    # Since it is not possible to easily combine different Haskell packages
    # from different nixpkgs, we just fall back to 18.09 and get everything
    # from there.
    #
    # The following nixpkgs commit is from the build inputs of
    # https://hydra.nixos.org/build/89581306.
    #
    # 18.09 contains ghc-8.4.4 (I think?)
    #
    # If you really want to use HPDF and HTF with the latest compiler, you will
    # have to patch them.  See the Haskell stuff in nixpkgs for how to do this.
    # Grepping for "fetchPatch" should give you some good places to look.
    url = "https://github.com/NixOS/nixpkgs/archive/8c2447fdee1af9310367b1ad7b63aed6217d3445.tar.gz";
    sha256 = "sha256:1zp6gn7h8mvs8a8fl9bxwm5ah8c3vg7irfihfr3k104byhfq2xd6";
  };

  my-overlay = self: super: {
    my-haskell-packages = super.haskellPackages.override {
      overrides = hSelf: hSuper: with self.haskell.lib; {
        # !!! Because we moved to 18.09, bson is already working well, so we
        # !!! don't need to override it or anything.
        # bson = ...

        # !!! Because HPDF and HTF are already working in 18.09, we don't have
        # !!! to override them.
        # HPDF = ...
        # HTF = ...

        # HPDF =
        #   let
        #     # !!! It will never work getting some packages from a different
        #     # !!! Haskell Package set like this.  You need to make sure everything
        #     # !!! comes from the same package set.
        #     unbroken-old-HTF = self.haskell.lib.markUnbroken HTF-nixpkgs.haskellPackages.HTF;
        #     unbroken-HPDF = self.haskell.lib.markUnbroken self.haskellPackages.HPDF;
        #     unbroken-HPDF-with-old-HTF = self.haskell.lib.addBuildDepend unbroken-HPDF unbroken-old-HTF;
        #   in unbroken-HPDF-with-old-HTF;
      };
    };
  };

  nixpkgs = import nixpkgs-src {
    overlays = [ my-overlay ];
  };

  pkg = nixpkgs.my-haskell-packages.developPackage {
    root = ./.;
    # You need the name here to be the same as the package name.
    # Normally this gets figured out from the directory name, but
    # in this case, the directory name does not match the package
    # name, so we have to have this.
    name = "haskell-nix-minimal";
  };
in
pkg

See the comments inline in the code again.

Thank you very much.

Sadly to use this for my codebase I need ghc 8.8.3 and HPDF like I currently have with stack.

I forked HPDF and removed the HTF dependency and used fetchFromGithub in my overlay but cabal complains it can’t see HPDF and I have no idea why.

It leads me to believe "fetchFromGithub in an overlay passed to haskell.developPackage does not work’.

I think it’s more likely I’m doing something wrong though.

Also: if you use dontCheck on a Haskell dependency are it’s test dependencies (like HTF) still added to the derivation?

Ah, yeah, the problem here is that fetchFromGithub just returns the Haskell source files. It doesn’t actually build the package.

You’ll have to pass the result of fetchFromGitHub to callCabal2nix in order to actually build that Haskell package.

If you search Google (or GitHub) for callCabal2nix, you’ll hopefully find some examples of people doing this.

I want to say that, no, the test dependencies are not added to the derivation.

However, I’m not 100% sure about this.

What you can do is override the derivation and pass null for the test dependencies just to make sure.

For instance, in an overlay block thing:

HPDF = super.HPDF.override { HTF = null; };
1 Like