Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
Add ways to build hadrian using nix
Browse files Browse the repository at this point in the history
This adds two new files to the hadrian directory

    shell.nix sets up the build envrionment you need to build ghc
    build-nix is a simple wrapper which invokes hadrian in the correct environment

Note: this patch was authored by @mpickering, however it ended up on phabricator due to the subtree as https://phabricator.haskell.org/D4207.
  • Loading branch information
angerman authored and mpickering committed Nov 17, 2017
1 parent fa95caa commit a228f38
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
32 changes: 32 additions & 0 deletions build-nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash shell.nix

function rl {
TARGET_FILE="$1"

cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"

# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE="$(readlink "$TARGET_FILE")"
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE="$(basename "$TARGET_FILE")"
done

# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR="$(pwd -P)"
RESULT="$PHYS_DIR/$TARGET_FILE"
echo "$RESULT"
}

absoluteRoot="$(dirname "$(rl "$0")")"
echo $absoluteRoot
cd "$absoluteRoot"

hadrian \
--lint \
--directory="$absoluteRoot/.." \
"$@"
57 changes: 57 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{ nixpkgs ? import <nixpkgs> {} }:

let
haskellPackages = nixpkgs.haskell.packages.ghc821;

removeBuild = path: type:
let baseName = baseNameOf (toString path);
in
! (baseName == "_build"
|| baseName == "dist"
|| baseName == "dist-newstyle"
|| baseName == ".stack-work"
|| baseName == "config.log"
|| baseName == "config.status"
|| nixpkgs.lib.hasSuffix ".sh" baseName
|| !(nixpkgs.lib.cleanSourceFilter path type)) ;

filterSrc = path: builtins.filterSource removeBuild path;


hadrianPackages = nixpkgs.haskell.packages.ghc821.override {
overrides = self: super: let
localPackage = name: path: self.callCabal2nix name (filterSrc path) {};
in {
hadrian = localPackage "hadrian" ./. ;
shake = self.callHackage "shake" "0.16" {};
Cabal = localPackage "Cabal" ./../libraries/Cabal/Cabal ;
filepath = localPackage "filepath" ./../libraries/filepath ;
text = localPackage "text" ./../libraries/text ;
hpc = localPackage"hpc" ./../libraries/hpc ;
parsec = localPackage "parsec" ./../libraries/parsec ;
HUnit = nixpkgs.haskell.lib.dontCheck (self.callHackage "HUnit" "1.3.1.2" {});
process = localPackage "process" ./../libraries/process ;
directory = localPackage "directory" ./../libraries/directory ;
}; };

in

nixpkgs.stdenv.mkDerivation {
name = "ghc-dev";
buildInputs = [
hadrianPackages.hadrian
nixpkgs.haskell.compiler.ghc821
haskellPackages.alex
haskellPackages.happy
nixpkgs.python3
nixpkgs.git
nixpkgs.autoconf
nixpkgs.automake
nixpkgs.perl
nixpkgs.gcc
nixpkgs.python3Packages.sphinx
nixpkgs.ncurses
nixpkgs.m4
nixpkgs.gmp
nixpkgs.file ];
}

0 comments on commit a228f38

Please sign in to comment.