cabal2nix
cabal2nix copied to clipboard
Best way to automate the addition of a custom shellHook?
I was looking at the generated nix expression when using the --shell option, and while it is probably possible to generate a script to patch in a custom shellHook, I'm not seeing a simple way to do it. Possible solutions:
- add in a
--hookoption that takes a file containing the contents of the shellhook and adds it in. - put in an empty
shellHookthat acts as an anchor for the user to write their own patch script more easily (I don't really like this option). - probably the best option, something obvious that I missed but don't know about :-)
I don't think it is wise to extend --shell so it could generate every possible shell the user could since that would add a lot of complexity to the tool. Additionally --shell is not the method for getting a development shell I'd necessarily recommend generally, since it is ultimately flawed since it is based on the nix builder's environment (so doesn't include cabal-install by default for example).
What I'd generally recommend is to use the normal expression generated by cabal2nix (without the --shell) and use overriding to get the rest:
$ cabal2nix . > pkg.nix
$ nix-shell shell.nix
where shell.nix would be something like:
{ pkgs ? import <nixpkgs> { } }:
let
haskellPackages = pkgs.haskellPackages.override {
overrides = self: super: {
my-package = self.callPackage ./pkg.nix { };
};
};
in
haskellPackages.shellFor {
packages = p: [ p.my-package ];
buildInputs = [
# extra build tools
];
shellHook = "echo hello";
}
As you can see, the generated file keeps getting generated and all custom settings live in a separate file.
Unfortunately documentation on all used parts is still lacking which I pledge to work on improving soon :)
In short: I think supporting all permutations you could want for --shell is not really feasible and supporting an arbitrary subset of those is also not great.