Aliases, paths and cabal

Hi,

I am trying to build a haskell executable and wondering where I am going wrong:

{ pkgs         ? (import <nixpkgs>{}), 
  mkDerivation ? pkgs.stdenv.mkDerivation, 
  base         ? pkgs.haskellPackages.base, 
  clay         ? pkgs.haskellPackages.clay, 
  scotty       ? pkgs.haskellPackages.scotty}:
mkDerivation {
  pname = "Scotty";
  version = "0.1.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  libraryHaskellDepends = [ base ];
  buildOptions = with pkgs;[cabal-install ghc];
  executableHaskellDepends = [ base clay scotty ];
  license = "unknown";
  buildPhase = ''
    alias cabal=".${pkgs.cabal-install}/bin/cabal";
    alias ghc="$.{pkgs.ghc}/bin/ghc";
    cabal build 
  '';
  shellHook = ''
    alias cabal="${pkgs.cabal-install}/bin/cabal";
    alias ghc="${pkgs.ghc}/bin/ghc";
    cabal build 
  '';
}

For some reason, cabal doesn’t seem to find ghc - althought it is aliased when the build happens. The same goes for running nix-shell. But then when I open the environment and run ghc or cabal they both seem to be working fine. Can you please point out to me where I am going wrong?

Thank you.

Ok, problem solved by adding the bin paths to the ‘PATH’. Wondering if there isn’t a more straightforward way

{ pkgs         ? (import <nixpkgs>{}), 
  mkDerivation ? pkgs.stdenv.mkDerivation, 
  base         ? pkgs.haskellPackages.base, 
  clay         ? pkgs.haskellPackages.clay, 
  scotty       ? pkgs.haskellPackages.scotty}:
mkDerivation {
  pname = "Scotty";
  version = "0.1.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  libraryHaskellDepends = [ base ];
  buildOptions = with pkgs;[cabal-install ghc];
  executableHaskellDepends = [ base clay scotty ];
  license = "unknown";
  installPhase = ''
    export PATH="${pkgs.cabal-install}/bin:$PATH";
    export PATH="${pkgs.ghc}/bin:$PATH";
    cabal build
  '';
  shellHook = ''
    alias cabal="${pkgs.cabal-install}/bin/cabal"
    alias ghc="${pkgs.ghc}/bin/ghc"
    export PATH="${pkgs.cabal-install}/bin:$PATH"
    export PATH="${pkgs.ghc}/bin:$PATH"
  '';
}

For haskell builds, you’ll want to refer to https://haskell4nix.readthedocs.io/nixpkgs-users-guide.html#how-to-create-nix-builds-for-your-own-private-haskell-packages

Cheers for pointing out the haskell4nix docs. Somehow didn’t stumble upon it previously - a far more indepth resource than the other ones I have read.

My prior cabal2nix attempt did not work - so I tried to troubleshoot by building it manually. In the end I managed to get both to work.