Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of passing `-p zlib` argument to `nix-shell` in `shell.nix`

If I build my Haskell project under nix-shell it gives error about missing zlib.

If I build the project in nix-shell using nix-shell -p zlib then the project sees zlib and builds successfully.

How can I add the zlib package to shell.nix file so that passing -p zlib is no longer needed?

Note: the builds were done using cabal v2-build

For building with stack I had to do the following

This is how my shell.nix is currently defined:

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

let

  inherit (nixpkgs) pkgs;

  f = { mkDerivation, base, directory, stdenv, text, turtle, zlib }:
      mkDerivation {
        pname = "haskell-editor-setup";
        version = "0.1.0.0";
        src = ./.;
        isLibrary = false;
        isExecutable = true;
        executableHaskellDepends = [ base directory text turtle zlib ];
        description = "Terminal program that will set up Haskell environment with a target selected editor or IDE";
        license = stdenv.lib.licenses.gpl3;
      };

  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
like image 869
Răzvan Flavius Panda Avatar asked Oct 10 '19 15:10

Răzvan Flavius Panda


1 Answers

I got it to work by creating a GHC environment using a haskell+nix tutorial. Below is my release.nix and default.nix is generated via cabal2nix . > default.nix : (note the zlib as a part of the haskell packages to include in the ghcWithPackages call)

let
  config = 
  {
    packageOverrides = pkgs: 
    {
      haskellPackages = pkgs.haskellPackages.override 
      {
        overrides = new: old:
        {
          interview = new.callPackage ./default.nix;
        };
      };
    };
  };

  pkgs = import <nixpkgs> { inherit config; };

  ghc = pkgs.haskellPackages.ghcWithPackages (hpkgs: with hpkgs;
    [ cabal-install
      interview
      zlib
    ]
  );
in

with pkgs;

mkShell 
{ buildInputs = [ ghc ];
}

like image 66
theNerd247 Avatar answered Oct 26 '22 23:10

theNerd247