NixOS / cabal2nix

Generate Nix build instructions from a Cabal file
https://haskell4nix.readthedocs.io
Other
360 stars 155 forks source link

cabal2nix inside of nix expression #428

Open Profpatsch opened 5 years ago

Profpatsch commented 5 years ago

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:

Profpatsch commented 4 years ago

Because somebody asked on IRC, the workaround we use currently is as follows:

1) import the gitignore-filtered (pkgs.nix-gitignore.gitignoreSource) source code into the nix store (fully, every time some code changes) 2) Run pkgs.callCabal2nix on 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.