GIB
GIB

Reputation: 51

Nix & Haskell - using default.nix from cabal2nix and a generic shell.nix

From a pretty basic cabal file

cabal2nix ./. > default.nix 

and then a shell.nix of

let
  pkgs = import <nixpkgs> {};
  haskellPackages = pkgs.haskellPackages_ghc784.override {
    extension = self: super: {
      thispackage = self.callPackage ./default.nix {};
    };
  };
in pkgs.myEnvFun {
     name = haskellPackages.thispackage.name;
     buildInputs = [
       (haskellPackages.ghcWithPackages (hs: ([
         hs.cabalInstall
       ] ++ hs.thispackage.propagatedNativeBuildInputs)))
     ];
   }

When in the nix-shell and running cabal configure it complains of missing packages such as text.

If I put the text package explicitly into the shell.nix such as

let
  pkgs = import <nixpkgs> {};
  haskellPackages = pkgs.haskellPackages_ghc784.override {
    extension = self: super: {
      thispackage = self.callPackage ./default.nix {};
    };
  };
in pkgs.myEnvFun {
     name = haskellPackages.thispackage.name;
     buildInputs = [
       (haskellPackages.ghcWithPackages (hs: ([
         hs.cabalInstall
         hs.text
       ] ++ hs.thispackage.propagatedNativeBuildInputs)))
     ];
   } 

The cabal configure is fine, but I would expect hs.thispackage.propagatedNativeBuildInputs to be supplying these packages.

The very basic haskell project can be seen at

https://github.com/fatlazycat/haskell-nix-helloworld

Am I wrong in assuming you can work in this way ?

Thanks

Upvotes: 4

Views: 1719

Answers (1)

Peter Simons
Peter Simons

Reputation: 1860

The propagatedNativeBuildInputs attribute is used by Haskell libraries to propagate their build inputs down to other builds that depend on them. Your package, however, is not a library --- it's an executable ---, so there's no need to propagate the build inputs and thus propagatedNativeBuildInputs is empty. Instead, you'll find the information you need in hs.thispackage.extraBuildInputs.

Generally speaking, the definition of these kind of nix-shell environments has become a lot easier in the release-15.09 branch (or nixos-unstable), though. Simply run cabal2nix --shell . >shell.nix and you get a shell.nix file that you can use for building with nix-build shell.nix as well as for entering an interactive development environment with nix-shell.

http://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure has a lot more information about the subject.

Upvotes: 4

Related Questions