I want a shell where I have acess to recoll, and a Haskell program I wrote called pandoc-columns. So I wrote this, which works just fine.
$ cat shell.nix
with (import <nixpkgs> {});
let
h = haskellPackages.extend (final: prev: {
pandoc-columns = haskellPackages.callPackage /home/amy/github/nixos-config/overlays/pandoc-columns {};
});
in
mkShell {
buildInputs = [ pkgs.recoll (h.ghcWithPackages (p: [p.pandoc-columns])) ];
}
As I said, it works fine. But /home/amy/github/nixos-config/overlays/pandoc-columns/default.nix uses fetchgit to grab my code from a github repo, which seems a waste (since it’s already on my machine). And I want to be able to include programs without having to put them into GitHub or my NixOS overlay.
So I tried this:
$ cat shell.nix
with (import <nixpkgs> {});
let
h = haskellPackages.extend (final: prev: {
pandoc-columns = haskellPackages.developPackage { root = /home/amy/github/pandoc-columns; };
});
in
mkShell {
buildInputs = [ pkgs.recoll (h.ghcWithPackages (p: [p.pandoc-columns])) ];
}
which invokes this file (which I used to develop the program in the first place).
$ cat /home/amy/github/pandoc-columns/default.nix
let
pkgs = import <nixpkgs> { };
in
pkgs.haskellPackages.developPackage {
root = ./.;
}
However, my Haskell program is not available in the shell, and there are no error messages to indicate the problem.
$ nix-shell
[nix-shell:~/maths]$ which pandoc-columns
which: no pandoc-columns in (/nix/store/1vzppfh7qm... blah blah blah
I don’t know much about how Haskell does things, but have you tried
with (import <nixpkgs> {});
let
h = haskellPackages.extend (final: prev: {
pandoc-columns = import /home/amy/github/pandoc-columns;
});
in
mkShell {
buildInputs = [ pkgs.recoll (h.ghcWithPackages (p: [p.pandoc-columns])) ];
}
Given that default.nix already calls developPackage, calling it on the result of that function seems odd, though I would expect something to break at least.
Edit: Ah, obviously it won’t because currently you just call the full build with a different root. This does the same, though it avoids some duplication. It’s got to be something else going wrong.
What are the contents of /home/amy/github/nixos-config/overlays/pandoc-columns? That might contain a hint as to what’s missing to get the binary into $PATH.
Note that this is also why it’s more common practice to write shells and little derivations like this as functions with default arguments like so:
By default, developPackage will do two different things depending on whether you are calling it in nix-shell or nix-build:
In line 251 and 260, you can see that pkgs.lib.inNixShell is used to determine whether to return drv.envFunc or just drv.
drv.envFunc gives you an environment for hacking on the Haskell package (so it gives you ghc with a package set of all your dependencies). drv just gives you the built Haskell package.
My guess is that you’re getting drv.envFunc (an environment for building pandoc-columns), but you’re expecting to get just drv (the built pandoc-columns executable). You can probably work around this by one of the following methods:
Explicitly pass false to returnShellEnv.
Or, just define pandoc-columns with callCabal2nix. You’re not getting much from using developPackage here. In my own Nix code, I’ve generally found it easier to define packages with callCabal2nix, and then create a development shell with shellFor when I’ve needed it, rather than using developPackage.