NixOS / cabal2nix

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

Can generate broken filepaths for local directories #85

Closed Fuuzetsu closed 10 years ago

Fuuzetsu commented 10 years ago

if we cabal2nix over a local directory such as foo-1.2.3 which is a common naming scheme from cabal unpack, the path is inserted verbatim and nix complains about a parse error.

The local paths should just be always quoted. I imagine problems in cases the filepath itself has quotes &c but that's a much more rare scenario.

cc @bennofs

bennofs commented 10 years ago

Putting quotes arround the src directory changes behaviour. Right now, the src directory is copied to the store and then the store path is set to $src for the builder. If we quote the path, then $src will be directly the relative path, which means that for example chroot builds will fail. Correct me if I'm wrong about this.

Fuuzetsu commented 10 years ago

Wouldn't that mean that it's impossible to do chroot builds for such paths because we have to quote them?

bennofs commented 10 years ago

I just found out that we don't need to quote them. ./foo-1.2.3 is also parsed fine as a path by nix. However, since b217210538e51c79d222fd71e82e374edce0dec9, cabal2nix should automatically do that. I just tested:

$ cabal get lens-4.4
$ cabal2nix lens-4.4
# This file was auto-generated by cabal2nix. Please do NOT edit manually!

{ cabal, bifunctors, comonad, contravariant, deepseq, distributive
, doctest, exceptions, filepath, free, genericDeriving, hashable
, hlint, HUnit, mtl, nats, parallel, primitive, profunctors
, QuickCheck, reflection, semigroupoids, semigroups, simpleReflect
, split, tagged, testFramework, testFrameworkHunit
, testFrameworkQuickcheck2, testFrameworkTh, text, transformers
, transformersCompat, unorderedContainers, vector, void, zlib
}:

cabal.mkDerivation (self: {
  pname = "lens";
  version = "4.4";
  src = ./lens-4.4;
  buildDepends = [
    bifunctors comonad contravariant distributive exceptions filepath
    free hashable mtl parallel primitive profunctors reflection
    semigroupoids semigroups split tagged text transformers
    transformersCompat unorderedContainers vector void zlib
  ];
  testDepends = [
    deepseq doctest filepath genericDeriving hlint HUnit mtl nats
    parallel QuickCheck semigroups simpleReflect split testFramework
    testFrameworkHunit testFrameworkQuickcheck2 testFrameworkTh text
    transformers unorderedContainers vector
  ];
  meta = {
    homepage = "http://github.com/ekmett/lens/";
    description = "Lenses, Folds and Traversals";
    license = self.stdenv.lib.licenses.bsd3;
    platforms = self.ghc.meta.platforms;
  };
})
Fuuzetsu commented 10 years ago

This only works for paths that start at . so it would still be broken for a case such as cabal2nix /some/location/lens-4.4: src = ./some/location/lens-4.4 doesn't make sense here.

bennofs commented 10 years ago

cabal2nix only prepends ./ if the path doesn't already contain a slash. So /some/location/lens-4.4 is unchanged. Nix requires that paths contain a slash.

Fuuzetsu commented 10 years ago

OK, so the problem still exists, right? Just making sure we're on the same track.

bennofs commented 10 years ago

No, it's fixed since b217210.

Fuuzetsu commented 10 years ago

How exactly is this fixed? See

[shana@lenalee:~/programming]$ cd /tmp

[shana@lenalee:/tmp]$ nix-shell -p pkgs.haskellPackages_ghc783.cabalInstall -p pkgs.haskellPackages_ghc783.ghc

[nix-shell:/tmp]$ cabal unpack lens
Downloading lens-4.4.0.1...
Unpacking to lens-4.4.0.1/

[nix-shell:/tmp]$ exit

[shana@lenalee:/tmp]$ nix-shell -p pkgs.myHaskellPackages_ghc783.cabal2nix -p pkgs.myHaskellPackages_ghc783.ghc

[nix-shell:/tmp]$ cabal2nix /tmp/lens-4.4.0.1/
# This file was auto-generated by cabal2nix. Please do NOT edit manually!

{ cabal, bifunctors, comonad, contravariant, deepseq, distributive
, doctest, exceptions, filepath, free, genericDeriving, hashable
, hlint, HUnit, mtl, nats, parallel, primitive, profunctors
, QuickCheck, reflection, semigroupoids, semigroups, simpleReflect
, split, tagged, testFramework, testFrameworkHunit
, testFrameworkQuickcheck2, testFrameworkTh, text, transformers
, transformersCompat, unorderedContainers, vector, void, zlib
}:

cabal.mkDerivation (self: {
  pname = "lens";
  version = "4.4.0.1";
  src = /tmp/lens-4.4.0.1/;
  buildDepends = [
    bifunctors comonad contravariant distributive exceptions filepath
    free hashable mtl parallel primitive profunctors reflection
    semigroupoids semigroups split tagged text transformers
    transformersCompat unorderedContainers vector void zlib
  ];
  testDepends = [
    deepseq doctest filepath genericDeriving hlint HUnit mtl nats
    parallel QuickCheck semigroups simpleReflect split testFramework
    testFrameworkHunit testFrameworkQuickcheck2 testFrameworkTh text
    transformers unorderedContainers vector
  ];
  meta = {
    homepage = "http://github.com/ekmett/lens/";
    description = "Lenses, Folds and Traversals";
    license = self.stdenv.lib.licenses.bsd3;
    platforms = self.ghc.meta.platforms;
  };
})

[nix-shell:/tmp]$ cabal2nix /tmp/lens-4.4.0.1/ > default.nix

[nix-shell:/tmp]$ nix-shell default.nix
error: syntax error, unexpected ';', at /tmp/default.nix:15:27

This is with cabal2nix HEAD. No matter how I look at it, it generates a path nix can't parse.

bennofs commented 10 years ago

Ah, I think the problem isn't the -, but the trailing slash.

Fuuzetsu commented 10 years ago

Yep, confirmed it with a path without - or ..