Add other packages to cabal2nix generated shell

Hello, I’m still new to Nix and I can’t figure out how to properly setup a Haskell development environment.

I’ve used cabal2nix :

nix-shell --pure -p cabal2nix --run "cabal2nix . --shell > generated.nix"

So I got something like this that was generated :

{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:

let

  inherit (nixpkgs) pkgs;

  f = { mkDerivation, base, scalpel, stdenv }:
      mkDerivation {
        pname = "testHaskellEnv";
        version = "0.1.0.0";
        src = ./.;
        isLibrary = false;
        isExecutable = true;
        executableHaskellDepends = [ base scalpel ];
        license = stdenv.lib.licenses.bsd3;
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

  drv = variant (haskellPackages.callPackage f {});

in

  if pkgs.lib.inNixShell then drv.env else drv

Now, I want to add a non-Haskell dependency which I can’t add to my .cabal file. For instance cowsay.

How can I override buildInputs ? I’ve tried

with (import <nixpkgs> {});
let
  generatedDrv = (import ./generated.nix);
in
  generatedDrv.overrideAttrs (old: {
    buildInputs = old.buildInputs ++ [ cowsay ];
  })

But it says

❯ nix-shell --pure
error: value is a function while a set was expected, at /home/arsleust/projects/scrapping-marmiton/default.nix:5:3

Thanks !

I figured out using nix repl.

Here is my default.nix :

let
  pkgs = (import <nixpkgs> {});
  generatedDrv = (import ./generated.nix {});
in
  generatedDrv.overrideAttrs (old: {
    buildInputs = old.buildInputs ++ [
      ## Put additional packages here
      pkgs.cowsay
    ];
  })