I’m working on this flake for a Haskell project using cabal2nix. My project is called b32. One of my dependencies, bech32, is broken due to a failing test. How can I add an override to ignore the tests when building the dependency?
{
description = "b32";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = inputs:
let
overlay = final: prev: {
haskell = prev.haskell // {
packageOverrides = hfinal: hprev:
prev.haskell.packageOverrides hfinal hprev // {
b32 = hfinal.callCabal2nix "b32" ./. { };
};
};
b32 = final.haskell.lib.compose.justStaticExecutables final.haskellPackages.b32;
};
perSystem = system:
let
pkgs = import inputs.nixpkgs { inherit system; overlays = [ overlay ]; };
hspkgs = pkgs.haskellPackages;
in
{
devShell = hspkgs.shellFor {
withHoogle = true;
packages = p: [ p.b32 ];
buildInputs = [
hspkgs.cabal-install
hspkgs.haskell-language-server
hspkgs.hlint
hspkgs.fourmolu
pkgs.bashInteractive
];
};
defaultPackage = pkgs.b32;
};
in
{ inherit overlay; } // inputs.flake-utils.lib.eachDefaultSystem perSystem;
}
1 Like
Here’s how you might add an override for another Haskell package to your Haskell package set:
{
description = "b32";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = inputs:
let
overlay = final: prev: {
haskell = prev.haskell // {
packageOverrides = hfinal: hprev:
prev.haskell.packageOverrides hfinal hprev // {
b32 = hfinal.callCabal2nix "b32" ./. { };
bech32 = final.haskell.lib.compose.dontCheck hprev.bech32;
};
};
b32 = final.haskell.lib.compose.justStaticExecutables final.haskellPackages.b32;
};
perSystem = system:
let
pkgs = import inputs.nixpkgs { inherit system; overlays = [ overlay ]; };
hspkgs = pkgs.haskellPackages;
in
{
devShell = hspkgs.shellFor {
withHoogle = true;
packages = p: [ p.b32 ];
buildInputs = [
hspkgs.cabal-install
hspkgs.haskell-language-server
hspkgs.hlint
hspkgs.fourmolu
pkgs.bashInteractive
];
};
defaultPackage = pkgs.b32;
};
in
{ inherit overlay; } // inputs.flake-utils.lib.eachDefaultSystem perSystem;
}
b32
should pick up the changed bech32
due to how hfinal.callCabal2nix
(and internally hfinal.callPackage
) works.
You also might like to read the manual for the Haskell stuff in Nixpkgs, which explains this in more detail: Nixpkgs 23.05 manual | Nix & NixOS
Thanks! I actually tried this previously, and was still getting the broken package error for bech32, so I assumed I was doing the override incorrectly.
My project actually isn’t using bech32 as a direct dependency, but fast-bech32, which in turn relies on bech32. Since the broken package error was referencing failing tests for bech32, I assumed overriding this package would resolve it, but it doesn’t. When I used the code you provided but replaced bech32 with fast-bech32, I was able to get the build to proceed without any broken package error. It’s now failing to build fast-bech32 due to a type error in the source code, which I guess is a different issue.
I’ll read the Nixpkgs manual link you provided to better understand how everything works.
1 Like
I also tried removing the fast-bech32 dependency from my cabal file and switching it to bech32, then using the override code provided - this still fails to build with the broken package error. So I wonder what the override is actually doing, and perhaps whether there’s an additional broken element to the package beyond the failing tests, such that adding dontCheck
isn’t sufficient to fix it.
When I run nix develop --show-trace
it doesn’t give me any useful information about why the package won’t build, and NIXPKGS_ALLOW_BROKEN=1 nix develop --impure
succeeds with no message.
1 Like