input-output-hk / stack2nix

Generate nix expressions for Haskell projects
MIT License
98 stars 32 forks source link

show user friendly error if haskell.compiler.ghc843 attribute doesn't exist #102

Open noughtmare opened 6 years ago

noughtmare commented 6 years ago

Running

$(nix-build -A stack2nix)/bin/stack2nix --git-recursive --revision a4e21f43c94dfc253d07614e781347d657c86b9b https://github.com/haskell/haskell-ide-engine.git > ghc-8.4.nix

With default.nix:

{ pkgs ? (import (import ./fetch-nixpkgs.nix) {}) }:

with pkgs; rec {
 stack2nix = import (pkgs.fetchFromGitHub {
   owner = "sectore";
   repo = "stack2nix";
   rev = "4e4141d1f4a4626030f11bdf7623ccc7640f7b08";
   sha256 = "1v5pm770pmalxwvf6ddg196m17ga5lj30r1xq2sdd7fi330k0i27";
 }) { inherit pkgs; };
 hies = runCommandNoCC "hies" {} ''
   mkdir -p $out/bin
   ln -s ${hie82}/bin/hie $out/bin/hie-8.2
   ln -s ${hie84}/bin/hie $out/bin/hie-8.4
 '';
 hie82 = (import ./ghc-8.2.nix { inherit pkgs; }).haskell-ide-engine;
 hie84 = (import ./ghc-8.4.nix { inherit pkgs; }).haskell-ide-engine;
}

and fetch-nixpkgs.nix:

let
  spec = builtins.fromJSON (builtins.readFile ./nixpkgs-src.json);
  src = import <nix/fetchurl.nix> {
    url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
    inherit (spec) sha256;
  };
  nixcfg = import <nix/config.nix>;
in builtins.derivation {
  system = builtins.currentSystem;
  name = "${src.name}-unpacked";
  builder = builtins.storePath nixcfg.shell;
  inherit src;
  args = [
    (builtins.toFile "builder" ''
      $coreutils/mkdir $out
      cd $out
      $gzip -d < $src | $tar -x --strip-components=1
    '')
  ];
  coreutils = builtins.storePath nixcfg.coreutils;
  tar = builtins.storePath nixcfg.tar;
  gzip = builtins.storePath nixcfg.gzip;
}

And nixpkgs-src.json:

{
    "owner":  "NixOS",
    "repo":   "nixpkgs",
    "rev":    "3b1e15140c574c01ae25835b934fe71be3376877",
    "sha256": "03689811fb6baddef167b5e9713c96d3ee631ce45bec60639edf32de4667d04e"
}

Fails with:

stack2nix: haskell.compiler.ghc843 failed to build via nix
CallStack (from HasCallStack):
  error, called at src/Stack2nix/Util.hs:79:22 in stack2nix-0.1.3.1-7PUL0jmN2ShDWzAz8T0G4X:Stack2nix.Util

See also https://github.com/domenkozar/hie-nix/issues/13

domenkozar commented 6 years ago

If the error was the following: `stack2nix: "nix-build -A haskell.compiler.ghc843 ''" failed to build via nix would that give a better hint what's wrong?

noughtmare commented 6 years ago

Yeah, I understand why it gives this error now. Is it maybe possible to first check if haskell.compiler.ghc843 exists before trying to build it (and then show a custom error message if it doesn't exist)?