From 3672b3067d005503955ba909de47571347217f29 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 4 Mar 2019 11:08:06 +1000 Subject: [PATCH] Add stack/nix integration Relates to #4 --- .gitignore | 3 +++ default.nix | 18 ++++++++++++++++++ nix/iohk-common.nix | 15 +++++++++++++++ nix/iohk-nix.json | 7 +++++++ nix/nixpkgs-src.json | 7 +++++++ nix/stack-shell.nix | 20 ++++++++++++++++++++ stack.yaml | 3 +++ 7 files changed, 73 insertions(+) create mode 100644 default.nix create mode 100644 nix/iohk-common.nix create mode 100644 nix/iohk-nix.json create mode 100644 nix/nixpkgs-src.json create mode 100644 nix/stack-shell.nix diff --git a/.gitignore b/.gitignore index 5500cc0db52..35bdd57fa96 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ cabal.project.local~ .HTF/ .ghc.environment.* .ghci + +### Nix ### +/result* diff --git a/default.nix b/default.nix new file mode 100644 index 00000000000..b4e7193e615 --- /dev/null +++ b/default.nix @@ -0,0 +1,18 @@ +{ system ? builtins.currentSystem +, crossSystem ? null +, config ? {} + +# Import IOHK common nix lib +, iohkLib ? import ./nix/iohk-common.nix +# Pin nixpkgs to a revision on the nixos-19.03 channel +, nixpkgs ? iohkLib.fetchNixpkgs ./nix/nixpkgs-src.json +, pkgs ? import nixpkgs { inherit system crossSystem config; } + +# Keep this argument even if unused. +# It will prevent Hydra from caching the evaluation. +, gitrev ? iohkLib.commitIdFromGitRepo ./. +}: + +{ + inherit pkgs; +} diff --git a/nix/iohk-common.nix b/nix/iohk-common.nix new file mode 100644 index 00000000000..410e1f00657 --- /dev/null +++ b/nix/iohk-common.nix @@ -0,0 +1,15 @@ +# Imports the iohk-nix library. +# The version can be overridden for debugging purposes by setting +# NIX_PATH=iohk_nix=/path/to/iohk-nix + +import ( + let try = builtins.tryEval ; + in if try.success + then builtins.trace "using host " try.value + else + let + spec = builtins.fromJSON (builtins.readFile ./iohk-nix.json); + in builtins.fetchTarball { + url = "${spec.url}/archive/${spec.rev}.tar.gz"; + inherit (spec) sha256; + }) {} diff --git a/nix/iohk-nix.json b/nix/iohk-nix.json new file mode 100644 index 00000000000..4c2fa2f0046 --- /dev/null +++ b/nix/iohk-nix.json @@ -0,0 +1,7 @@ +{ + "url": "https://github.com/input-output-hk/iohk-nix", + "rev": "f20ab3940d3ec5d5a3d92e1f0544f501316adc43", + "date": "2019-02-15T19:35:36+10:00", + "sha256": "07hla7d0l91is5m5mwa86vq51fdxkjvbjv7176ipdg1z59wy21bj", + "fetchSubmodules": false +} diff --git a/nix/nixpkgs-src.json b/nix/nixpkgs-src.json new file mode 100644 index 00000000000..3b16d1bae48 --- /dev/null +++ b/nix/nixpkgs-src.json @@ -0,0 +1,7 @@ +{ + "url": "https://github.com/NixOS/nixpkgs.git", + "rev": "07e2b59812de95deeedde95fb6ba22d581d12fbc", + "date": "2019-02-26T15:31:33+01:00", + "sha256": "1yxmv04v2dywk0a5lxvi9a2rrfq29nw8qsm33nc856impgxadpgf", + "fetchSubmodules": false +} diff --git a/nix/stack-shell.nix b/nix/stack-shell.nix new file mode 100644 index 00000000000..a6487855cca --- /dev/null +++ b/nix/stack-shell.nix @@ -0,0 +1,20 @@ +# This is the derivation used by "stack --nix". +# It provides the system dependencies required for a stack build. +{ system ? builtins.currentSystem +, config ? {} +, walletPackages ? import ./.. { inherit config system; } +, pkgs ? walletPackages.pkgs +}: +with pkgs; + +haskell.lib.buildStackProject { + name = "cardano-wallet-stack-env"; + ghc = haskell.compiler.ghc863; + + buildInputs = [ + zlib gmp ncurses lzma openssl git + ] ++ (lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Cocoa CoreServices libcxx libiconv ])); + + phases = ["nobuildPhase"]; + nobuildPhase = "mkdir -p $out"; +} diff --git a/stack.yaml b/stack.yaml index 03ee5634310..806baf9acff 100644 --- a/stack.yaml +++ b/stack.yaml @@ -8,3 +8,6 @@ extra-deps: - git: https://github.com/input-output-hk/cardano-crypto commit: 3c5db489c71a4d70ee43f5f9b979fcde3c797f2a + +nix: + shell-file: nix/stack-shell.nix