use cabal2nix to create local nix environment for packages that aren't in nixpkgs
Asked Answered
K

1

3

I currently have a Yesod web application that I am developing on NixOS. I am using a default.nix file like described in O'Charles' blog post:

{ haskellPackages ? (import <nixpkgs> {}).haskellPackages }:

haskellPackages.cabal.mkDerivation (self: {
  pname = "myblog";
  version = "0.0.0";
  src = ./.;
  isLibrary = true;
  isExecutable = true;
  buildDepends = with haskellPackages; [
    aeson bson conduit dataDefault fastLogger hjsmin
    httpConduit monadControl monadLogger mongoDB persistent
    #persistentMongoDB
    persistentTemplate poolConduit shakespeare text
    waiExtra waiLogger warp yaml yesod yesodAuth
    yesodCore yesodDefault yesodForm yesodStatic
  ];
  testDepends = with haskellPackages; [
    hspec monadLogger persistent
    #persistentMongoDB
    resourcet transformers yesod yesodCore yesodTest
  ];
  buildTools = with haskellPackages; [
    cabalInstall ghcMod yesodBin
  ];
  jailbreak = true;
})

This is working very well. I can use the yesod binary and cabal like normal. However, I am running into one problem. When running cabal haddock, I am getting the following error:

Running Haddock for mycoolblog-0.0.0...
Preprocessing library mycoolblog-0.0.0...
Warning: The documentation for the following packages are not installed. No
links will be generated to these packages: persistent-mongoDB-2.1.1
<command line>: cannot satisfy -package-id aeson-0.8.0.2-9e93bdd6f8e68379314dd5f31414f87f
    (use -v for more information)

Googling about this brings up the following link: github: cabal haddock 'cannot satisfy -package-id' #2468. It seems like it is saying that ghcWithPackages should be used.

Googling about ghcWithPackages brings up O'Charles' (personal?) wiki on Nix. It has an example of using ghcWithPackages to develop a package that is already in nixpkgs, but I can't get it to work with a package that is not already in nixpkgs (my cms/blog).

Setting it up like described on O'Charles' wiki and running nix-shell -v, I get the following error:

evaluating file `/nix/store/an4sg7cxi1ii3vids8417kajl3ss13vd-nix-1.7/share/nix/corepkgs/derivation.nix'
error: cannot auto-call a function that has an argument without a default value (`cabal')

Why am I getting the above error? How can I write a default.nix and shell.nix for a Haskell project that's not already in nixpkgs? Ideally it would be using ghcWithPackages so that cabal haddock works.

Koonce answered 30/11, 2014 at 16:17 Comment(0)
K
4

I was able to get this working after using the method on O'Charles' Nix wiki. I have not determined why this method was not working before.

Basically, first run cabal2nix. Then create a generic shell.nix (that can be shared between all Haskell packages).

$ cabal2nix --jailbreak --sha256=X ./$cabal > default.nix
$ sed -i 's#sha = .*#src = builtins.filterSource (path: type: type != "unknown") ./.;#' default.nix
$ cat - > shell.nix <<EOF
let
  pkgs = import <nixpkgs> {};
  haskellPackages = pkgs.haskellPackages.override {
    extension = self: super: {
      thispackage = self.callPackage ./. {};
    };
  };
in pkgs.myEnvFun {
     name = haskellPackages.thispackage.name;
     buildInputs = [
       (haskellPackages.ghcWithPackages (hs: ([
         hs.cabalInstall
         hs.hscolour
         hs.ghcMod
       ] ++ hs.thispackage.propagatedNativeBuildInputs)))
     ];
   }      
EOF
$ nix-shell
Koonce answered 4/12, 2014 at 1:32 Comment(1)
no target for the link behind "O'Charles' Nix wiki."Molality

© 2022 - 2024 — McMap. All rights reserved.