Reputation: 809
The cabal isn't found on the following example and the question is, how to correct the example so that cabal is found.
This example is very straigthforward modification of the nix pill 8.1. On nix-repl
, typing :l <nixpkgs>
and then "${cabal-install}"
gives a path to the store where cabal-install is and it contains sub-dirs with bin there containing cabal-executable. I.e.
> /nix/store/pathtocabal-install/bin/cabal -v
cabal-install version 2.0.0.0
compiled using version 2.0.0.2 of the Cabal library
Below you should find the files corresponding to the the "make c" example.
With them, the
> nix-build hello.nix
doesn't work. It first tells to build "these derivations" and then says that
hello_builder.sh: line 2: cabal: command not found
I'm suspecting that $cabal-install/bin is a wrong way to refer to cabal but on nix-repl
its store-path is found.
hello_builder.sh is even shorter than in the c-example. Note that installation part is still missing (first the builder should be made to find the cabal).
export PATH="$coreutils/bin:$ghc/bin:$cabal-install/bin:$binutils/bin"
cabal build hello
hello.nix - maybe the binutils is not needed.
with (import <nixpkgs> {});
derivation {
name = "hello";
builder = "${bash}/bin/bash";
args = [ ./hello_builder.sh ];
inherit binutils coreutils ghc cabal-install;
src = ./hello.cabal;
system = builtins.currentSystem;
}
hello.cabal - in nix-shell
with cabal-install and ghc, this works.
name: hello
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.24
executable hello
main-is: hello.hs
default-language: Haskell2010
build-depends: base >=4.9 && <4.10
hello.hs
module Main where
main :: IO ()
main = putStrLn "Hello there!"
Late additions:
By adding echo $PATH
to the builder, we can see that the path is not correct. It is /nix/store/...coreutils-8.28/bin:/nix/store...ghc-8.0.2/bin:-install/bin:/nix/store/...binutils-2.28.1/bin
. There the $cabal
is turned into an empty string and it is not referring to $cabal-install
. Thus there is no correct store-path for the cabal-executable.
This answers part of the why-part of the question and how to correct it remains. And the open why-part is, why inherit cabal-install
cannot be used here.
Upvotes: 0
Views: 83
Reputation: 9885
The problem with inherit cabal-install;
is that cabal-install
is not a valid variable name in BASH. Nix converts the keys in the set provided to derivation
into variables in BASH.
Instead of inherit cabal-install;
you can do something like cabal_install = cabal-install;
and then use cabal_install
in your builder.
Upvotes: 1