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 pkgs
haskellPackages.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