cabal2nix
cabal2nix copied to clipboard
cabal2nix inside of nix expression
In my default.nix, I have a derivation like this:
src = pkgs.nix-gitignore.gitignoreSource [".git/" "*.nix"] ./.;
generatedNix = pkgs.runCommand "pkg-default.nix" {}
''
cp -r ${src}/* .
cp -r ${builtins.path { path = ./.git; name = "dotgit"; }} .git
${pkgs.cabal2nix}/bin/cabal2nix . > $out
sed -e 's|src = ./.|src = ${src}|' -i $out
'';
I filter the src with the contents of the .gitignore file (which uses builtins.filterSource under the hood), then I want to run cabal2nix on the cabal file in the filtered source.
Ideally, something like cabal2nix --src $out file://$src > $out would just work out of the box and generate a nix file in $out.
Instead, there’s two things one has to manually fix:
- cabal2nix tries multiple cvs systems and fails if it can’t find any, so we have to copy the whole
.gitto the store and copy it into the build environment - cabal2nix uses the path it’s given for the
srcfield, which is./., so I need to patch the generated source file. I suggest adding a--srcflag to specify it manually.
Because somebody asked on IRC, the workaround we use currently is as follows:
- import the gitignore-filtered (
pkgs.nix-gitignore.gitignoreSource) source code into the nix store (fully, every time some code changes) - Run
pkgs.callCabal2nixon that imported code, so the generated cabal file that references./.is in the nix store, and ./. would be imported into the nix store, but it already is, so that import becomes a no-op.