diff --git a/README.md b/README.md index b77cef9..81f54db 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,12 @@ _See the [Hacking](#hacking) section if you want to hack on snack_ Assuming that [Nix][nix] is installed on your machine, clone this repo and run: +``` shell +$ ./script/install +``` + +which is equivalent to + ``` shell $ nix-env -f ./default.nix -iA snack-exe ``` @@ -75,8 +81,8 @@ The _snack_ executable is now in your `PATH`: ``` shell $ snack --help -Usage: snack [-l|--lib DIR] [-j|--cores INT] ([-s|--package-nix PATH] | - [-p|--package-yaml PATH]) COMMAND +Usage: snack [-l|--lib DIR] [-b|--snack-nix PATH] [-j|--cores INT] + ([-s|--package-nix PATH] | [-p|--package-yaml PATH]) COMMAND Available options: -l,--lib DIR Path to the directory to use as the Nix library @@ -221,8 +227,50 @@ $ snack run # looks for a file called package.nix by default Alternatively, use `$ snack build` or `$ snack ghci` if you only want to build, or fire up `ghci`, respectively. -### Advanced Nix Example +### Using other versions of GHC and nixpkgs +The _snack_ executable comes with a [bundled version of +nixpkgs](./nix/nixpkgs/nixpkgs-src.json) and uses the GHC executable provided +by `haskell.packages.ghc822.ghcWithPackages`. You may override those default by +providing a `snack.nix`: + +``` shell +$ snack --snack-nix ./snack.nix build +``` + +This file looks like the following: + + +``` nix +rec { + # If you only wish to change the version of GHC being used, set + # `ghc-version`. The following versions are currently available: + # * ghc7103 + # * ghc7103Binary + # * ghc802 + # * ghc821Binary + # * ghc822 + # * ghc841 + # * ghc842 + # * ghcHEAD + # * ghcjs + # * ghcjsHEAD + # * integer-simple + # NOTE: not all versions have been tested with snack. + ghc-version = "ghc802"; + + # Alternatively you can provide you own `ghcWithPackages`, which should have + # the same structure as that provided by + # `pkgs.haskell.packages..ghcWithPackages: + ghcWithPackages = pkgs.haskellPackages.ghcWithPackages; + + # Finally you can provide your own set of Nix packages, which should evaluate + # to an attribute set: + pkgs = import ./nix; +} +``` + +### Advanced Nix Example You may want custom builds that involve things such as [archiving and base64 encoding entire diff --git a/bin/Snack.hs b/bin/Snack.hs index cdc00d4..c4ed31e 100644 --- a/bin/Snack.hs +++ b/bin/Snack.hs @@ -280,9 +280,10 @@ nixBuild snackCfg extraNixArgs nixExpr = { #{ intercalate "," funArgs } }: let spec = builtins.fromJSON specJson; - pkgs = import #{ pkgsSrc } {}; + config = #{ pkgsSrc }; + pkgs = config.pkgs; libDir = #{ libDir }; - snack = (import libDir) { inherit pkgs; }; + snack = (import libDir) config; in #{ T.unpack $ unNixExpr $ nixExpr } |]) "nix-build" @@ -291,13 +292,17 @@ nixBuild snackCfg extraNixArgs nixExpr = pkgsSrc :: String pkgsSrc = case snackNix snackCfg of Just (SnackNix fp) -> - [i|(import #{ fp }).pkgs|] + [i|(import #{ fp })|] Nothing -> [i| - (builtins.fetchTarball - { url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz"; - sha256 = spec.sha256; - }) + { pkgs = import + ( + builtins.fetchTarball + { url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz"; + sha256 = spec.sha256; + } + ) {} ; + } |] libDir :: String libDir = case snackLib snackCfg of diff --git a/script/install b/script/install new file mode 100755 index 0000000..5a0e9b7 --- /dev/null +++ b/script/install @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +nix-env -f ./default.nix -iA snack-exe diff --git a/snack-lib/default.nix b/snack-lib/default.nix index f355331..fe7ec86 100644 --- a/snack-lib/default.nix +++ b/snack-lib/default.nix @@ -2,6 +2,8 @@ # TODO: currently single out derivations prepend the PWD to the path # TODO: make sure that filters for "base" are airtight { pkgs +, ghc-version ? "ghc822" +, ghcWithPackages ? pkgs.haskell.packages.${ghc-version}.ghcWithPackages }: with pkgs; @@ -16,7 +18,7 @@ with (callPackage ./package-spec.nix {}); with (callPackage ./hpack.nix {}); let - ghcWith = deps: haskellPackages.ghcWithPackages + ghcWith = deps: ghcWithPackages (ps: map (p: ps.${p}) deps); # Assumes the package description describes an executable diff --git a/tests/extended-config/nix/default.nix b/tests/extended-config/nix/default.nix index 5881fb9..12a09a1 100644 --- a/tests/extended-config/nix/default.nix +++ b/tests/extended-config/nix/default.nix @@ -1,4 +1,3 @@ -{}: let spec = builtins.fromJSON (builtins.readFile ../../../nix/nixpkgs/nixpkgs-src.json); nixpkgs = diff --git a/tests/extended-config/snack.nix b/tests/extended-config/snack.nix index 124487a..7ac1785 100644 --- a/tests/extended-config/snack.nix +++ b/tests/extended-config/snack.nix @@ -1,3 +1,4 @@ -{ - pkgs = ./nix; +rec { + pkgs = import ./nix; + ghcWithPackages = pkgs.haskellPackages.ghcWithPackages; } diff --git a/tests/extended-config/test b/tests/extended-config/test index 2ca1d4e..8fc298d 100755 --- a/tests/extended-config/test +++ b/tests/extended-config/test @@ -16,6 +16,6 @@ test() { rm $TMP_FILE } -SNACK="snack -j4 -b snack.nix -s package.nix" test -SNACK="snack -j4 -b snack.nix" test -SNACK="snack -j4 -b snack.nix --package-yaml package.yaml" test +SNACK="snack -j4 --snack-nix snack.nix --package-nix package.nix" test +SNACK="snack -j4 --snack-nix snack.nix" test +SNACK="snack -j4 --snack-nix snack.nix --package-yaml package.yaml" test