Get a nixpkgs/Haskell package, but compiled with non-default options

A Haskell package is available in nixpkgs, but I need it compiled with non-default options. What’s a good way to accomplish this?

Background: I’m using gitit. This package provides both an executable and a library. In order to use plugins, I need to compile gitit with plugin support. Below are the ideas I’ve come up with, in order of increasing appeal.

  1. Clone the gitit repo and compile it on my machine with the desired option.
    Cons: I’d have to manually check periodically for updates and pull them from the primary repo.

  2. Create a local Haskell project that contains a copy of the “main program” (which is essentially an executable wrapper for the library) from the gitit repo. Add a dependency on the gitit library. Now I can compile the executable with any options I need.
    Cons: I’d still have to manually check periodically for updates, but only to the main program.

  3. Write a new Nix derivation or flake that downloads the gitit source code from the repo and compiles it with the options that I want. I guess I would copy the callPackage expression for gitit from hackage-packages.nix and modify it accordingly.

Is there a better option? Is there by any chance a one-liner to specify a dependency on a package from nixpkgs, but compiled with different options?

1 Like

If you don’t need to alter the source, you can create another derivation using override and overrideAttrs. For Haskell packages, there are various helpers documented in Nixpkgs 23.05 manual | Nix & NixOS

You might also find https://github.com/NixOS/nixpkgs/blob/3b759e96f27101c29e83a74812dc137ee13a919e/pkgs/applications/misc/gitit/default.nix interesting.

There was a Gitit NixOS module but since it wasn’t maintained it was removed in nixos/gitit: remove by ajs124 · Pull Request #224460 · NixOS/nixpkgs · GitHub so you could also try reviving that.

2 Likes

For future readers, here’s what worked for me, in shell.nix.

with (import <nixpkgs> {});

let
  gititWithPlugins = haskell.lib.compose.enableCabalFlag "-f-plugins" haskellPackages.gitit;
in
mkShell {
  buildInputs = [
    gititWithPlugins
  ];
}
1 Like