mirror of
https://github.com/nmattia/snack.git
synced 2025-01-06 04:25:30 +03:00
snack.nix: allow more overrides
This commit is contained in:
parent
b17afb31c0
commit
726690f4c8
54
README.md
54
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.<version>.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
|
||||
|
19
bin/Snack.hs
19
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
|
||||
|
2
script/install
Executable file
2
script/install
Executable file
@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env bash
|
||||
nix-env -f ./default.nix -iA snack-exe
|
@ -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
|
||||
|
@ -1,4 +1,3 @@
|
||||
{}:
|
||||
let
|
||||
spec = builtins.fromJSON (builtins.readFile ../../../nix/nixpkgs/nixpkgs-src.json);
|
||||
nixpkgs =
|
||||
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
pkgs = ./nix;
|
||||
rec {
|
||||
pkgs = import ./nix;
|
||||
ghcWithPackages = pkgs.haskellPackages.ghcWithPackages;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user