NixOS / cabal2nix

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

Invalid Nix is generated for a .cabal file that has the `if` package as a dependency #607

Closed runeksvendsen closed 11 months ago

runeksvendsen commented 11 months ago

The following error was observed after trying to enter a nix-shell from the output generated by cabal2nix:

$ nix-shell shell-tmp.nix 
error: syntax error, unexpected IF, expecting '}', at /home/runeks/code/haskell-graph/all-hackage-ghc-pkg/shell-tmp.nix:7:23

Content of shell-tmp.nix (output of cabal2nix) :

{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:

let

  inherit (nixpkgs) pkgs;

  f = { mkDerivation, if, lib }:
      mkDerivation {
        pname = "all-hackage-deps";
        version = "0.1.0.0";
        src = /run/user/1000/all-hackage-ghc-pkg;
        libraryHaskellDepends = [ if ];
        license = lib.licenses.bsd3;
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

  drv = variant (haskellPackages.callPackage f {});

in

  if pkgs.lib.inNixShell then drv.env else drv

Notice that the reserved if keyword is used as an argument name.

.cabal file:

cabal-version:      2.4
name:               foo
version:            0.1.0.0
license:            BSD-3-Clause
license-file:       LICENSE
author:             Blah
maintainer:         blah@blah.com
extra-source-files: CHANGELOG.md

library
    exposed-modules:  MyLib
    build-depends:    if ==0.1.0.0
    hs-source-dirs:   src
    default-language: Haskell2010
cdepillabout commented 11 months ago

@runeksvendsen Thanks for writing this up.

I'm closing in favor of https://github.com/NixOS/cabal2nix/issues/164