cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Cabal doesn't see happy on PATH

Open yaitskov opened this issue 1 year ago • 3 comments

Describe the bug cabal fails to build happy complaining that happy executable is not found, nonetheless happy is on PATH

To Reproduce

$ git clone https://github.com/yaitskov/happy-ghc11/tree/master
# commit just in case 71d4ad5a862793dd1753a1a6b453346e9533157d
$ nix-shell
....
Preprocessing executable 'happy' for happy-1.21.0..
Error: Setup: The program 'happy' is required but it could not be found

error: builder for '/nix/store/ccphy1szsn9fg2lx80p299bib2ky9izp-happy-1.21.0.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/l73rh8grlx1wqsjshdf344x44c75g2cj-ghc-9.8.1-with-packages.drv' failed to build

System information

cabal --version
cabal-install version 3.10.3.0
compiled using version 3.10.3.0 of the Cabal library 

uname -a
Linux diehard 5.13.11 #1 SMP Sun Aug 15 11:46:11 EDT 2021 x86_64 GNU/Linux

Workaround

cabal --extra-prog-path=$(which happy) build 

I guess it is expected behavior, but the fact that cabal is using alternative PATH not related to canonical BASH one is not obvious at all. I would not close the issue until error message is extended mentioning this - e.g. suggesting extra-prog-path or just borrow whole PATH.

yaitskov avatar Apr 17 '24 17:04 yaitskov

Cabal does make use of the path environment variable. "extra-prog-path" as it says is just an extra path to augment the existing system path. It is not clear to me how your system is configured that this does not work.

Perhaps when you enter the nix-shell the path is overridden?

gbaz avatar Apr 17 '24 18:04 gbaz

If $(which happy) works, then executable is in PATH. I would consider this a bug, not a user question.

@yaitskov, we need your help to diagnose this, cabal build -v3 or similar prints enviroment variables (starting with with environment). Can you tel us how ("PATH","… differs from echo $PATH?

ffaf1 avatar Apr 17 '24 18:04 ffaf1

Cabal does make use of the path environment variable

I started grepping cabal source code - exception is thrown from lookupProgram which looks into a some Db and I assumed that program is referred in such a way is expected to be "cabally installed". I didn't trace all way.

Here is another way to reproduce the issue, which is easier to investigate

$ rm -rf ~/.cabal ~/.local/state/cabal ~/.cache/cabal
$ git clone https://github.com/haskell/happy.git 
# commit 78dcc03336d74822d58b8474e9639c6281c1a422
$ cd happy
cat<<EOF > ./default.nix
{ pkgs ? import <nixpkgs> {} }:
let
  inherit (pkgs) lib;
  hp = pkgs.haskell.packages.ghcHEAD;
  sourceRegexes = [
    "^src.*"
    "^exe.*"
    "^package.yaml"
    "^.*\\.cabal"
    "^LICENSE"
  ];

  shell = hp.shellFor {
    packages = p: [];
    shellHook = ''echo ok'';
    nativeBuildInputs = [ pkgs.cabal-install pkgs.happy ];
  };
in
{ inherit shell; }

EOF
$ nix-shell
$ type happy
happy is /nix/store/4z00pcvs075ghpnyhsvg6xg54kzncv5m-happy-1.20.1.1/bin/happy
$ cd packages/frontend # important step
$ cabal build
Warning: Unknown/unsupported 'ghc' version detected (Cabal 3.10.3.0 supports
'ghc' version < 9.10):
/nix/store/z3d4vkisfchw9ydyalax4q32pp5ry0dr-ghc-9.11.20240323/bin/ghc is
version 9.11.20240323
Build profile: -w ghc-9.11.20240323 -O1
In order, the following will be built (use -v for more details):
 - happy-frontend-2.0 (lib) (first run)
 - happy-3.0 (exe:happy) (first run)
Preprocessing library for happy-frontend-2.0..
Error: .cabal-wrapped: The program 'happy' is required but it could not be
found

Error: cabal: Failed to build happy-frontend-2.0 (which is required by
exe:happy from happy-3.0).


yaitskov avatar Apr 17 '24 18:04 yaitskov

This is a bug in the 1.20.1 and 1.21.0 happy releases (which are long deprecated). https://github.com/haskell/happy/issues/274 is an entry-point to that story, I suppose. Happy version 1.20.1.1 is currently the most recent version that should install as expected.

Meanwhile we fixed the situation on happy master as well and you should have more success building it.

sgraf812 avatar Jul 22 '24 14:07 sgraf812

Thanks Sebastian!

I wonder if we should close it in the light of the above.

ulysses4ever avatar Jul 22 '24 14:07 ulysses4ever