1
0
Fork 0
mirror of https://github.com/tensorflow/haskell.git synced 2024-11-26 21:09:44 +01:00

Use stack's nix support (#168)

* Add stack --nix support

* Update README for nix shell
This commit is contained in:
Nicolas Mattia 2018-05-25 04:33:15 +02:00 committed by Greg Steuck
parent b063cccc40
commit 8e1d85b5e5
6 changed files with 98 additions and 69 deletions

View file

@ -108,11 +108,14 @@ After running the script to install system dependencies, build the project with
## Build on NixOS ## Build on NixOS
`tools/userchroot.nix` expression contains definitions to open The `shell.nix` provides an environment containing the necessary
chroot-environment containing necessary dependencies. Type dependencies. To build, run:
$ nix-shell tools/userchroot.nix $ stack --nix build
$ stack build --system-ghc
or alternatively you can run
$ nix-shell
to enter the environment and build the project. Note, that it is an emulation to enter the environment and build the project. Note, that it is an emulation
of common Linux environment rather than full-featured Nix package expression. of common Linux environment rather than full-featured Nix package expression.

6
nix/src.json Normal file
View file

@ -0,0 +1,6 @@
{
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "729da53a147eda1a1678a313754fcda3a8791279",
"sha256": "17l19rbhb3wdrrcyjgq34bk3p658jbldzxp9q1scdvrvz0g99psb"
}

26
nix/update Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash nix curl jq
# vim: filetype=sh
# Updates the nixpkgs.json to the latest release
# See https://gist.github.com/zimbatm/de5350245874361762b6a4dfe5366530
set -euo pipefail
cd "$(dirname "$0")" || exit 1
branch=release-17.09
owner=NixOS
repo=nixpkgs
rev=$(curl -sfL https://api.github.com/repos/$owner/$repo/git/refs/heads/$branch | jq -r .object.sha)
url=https://github.com/$owner/$repo/archive/$rev.tar.gz
release_sha256=$(nix-prefetch-url --unpack "$url")
cat <<NIXPKGS | tee src.json
{
"owner": "$owner",
"repo": "$repo",
"rev": "$rev",
"sha256": "$release_sha256"
}
NIXPKGS

55
shell.nix Normal file
View file

@ -0,0 +1,55 @@
{ghc ? null }:
let
# Use pinned packages
_nixpkgs = import <nixpkgs> {};
nixpkgs = _nixpkgs.fetchFromGitHub (_nixpkgs.lib.importJSON ./nix/src.json);
pkgs = import nixpkgs {};
# Either use specified GHC or use GHC 8.2.2 (which we need for LTS 11.9)
myghc = if isNull ghc then pkgs.haskell.compiler.ghc822 else ghc;
# Fetch tensorflow library
tensorflow-c = pkgs.stdenv.mkDerivation {
name = "tensorflow-c";
src = pkgs.fetchurl {
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.8.0.tar.gz";
sha256 = "0qzy15rc3x961cyi3bqnygrcnw4x69r28xkwhpwrv1r0gi6k73ha";
};
# Patch library to use our libc, libstdc++ and others
buildCommand = ''
. $stdenv/setup
mkdir -pv $out
tar -C $out -xzf $src
chmod +w $out/lib/libtensorflow.so
${pkgs.patchelf}/bin/patchelf --set-rpath "${pkgs.stdenv.cc.libc}/lib:${pkgs.stdenv.cc.cc.lib}/lib" $out/lib/libtensorflow.so
chmod -w $out/lib/libtensorflow.so
'';
};
# Wrapped stack executable that uses the nix-provided GHC
stack = pkgs.stdenv.mkDerivation {
name = "stack-system-ghc";
builder = pkgs.writeScript "stack" ''
source $stdenv/setup
mkdir -p $out/bin
makeWrapper ${pkgs.stack}/bin/stack $out/bin/stack \
--add-flags --system-ghc
'';
buildInputs = [ pkgs.makeWrapper ];
};
in
pkgs.haskell.lib.buildStackProject {
ghc = myghc;
stack = stack;
name = "tf-env";
buildInputs =
[
pkgs.snappy
pkgs.zlib
pkgs.protobuf3_3
tensorflow-c
stack
];
}

View file

@ -29,3 +29,7 @@ extra-lib-dirs:
- /usr/local/lib - /usr/local/lib
extra-include-dirs: extra-include-dirs:
- /usr/local/include - /usr/local/include
nix:
enable: false
shell-file: shell.nix

View file

@ -1,65 +0,0 @@
#
# This script is provided by @grwlf (grwlf@gmail.com) and is supported on best
# effort basis. TensorFlow development team does not regularly test this script
# and can't answer any questions about it.
#
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
tensorflow-c = stdenv.mkDerivation {
name = "tensorflow-c";
src = fetchurl {
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.8.0.tar.gz";
sha256 = "0a8e334d7c20879df9857c762472329d70cbf2f316af113d0b26f5c17209fe63";
};
buildCommand = ''
. $stdenv/setup
mkdir -pv $out
tar -C $out -xzf $src
'';
};
fhs = pkgs.buildFHSUserEnv {
name = "fhs";
targetPkgs = pkgs:
with pkgs.python3Packages;
with pkgs.haskellPackages;
with pkgs;
assert stack.version >= "1.4";
assert ghc.version >= "8";
[
snappy
snappy.dev
protobuf3_2
stack
ghc
iana-etc
pkgs.zlib
pkgs.zlib.dev
tensorflow-c
gcc
gdb
];
runScript = "bash";
profile = ''
export USE_CCACHE=1
export LIBRARY_PATH=/usr/lib64
export LD_LIBRARY_PATH=$(pwd):/usr/lib64
export ACLOCAL_PATH=/usr/share/aclocal
export LANG=C
export LC_ALL=en_US.utf-8
export PATH="$HOME/.local/bin:$PATH"
'';
};
in
stdenv.mkDerivation {
name = fhs.name + "-env";
nativeBuildInputs = [ fhs ];
shellHook = "exec fhs";
}