1
1
mirror of https://github.com/nmattia/snack.git synced 2024-10-26 04:29:51 +03:00

snack.nix: allow more overrides

This commit is contained in:
Nicolas Mattia 2018-10-02 23:38:41 +03:00
parent b17afb31c0
commit 726690f4c8
7 changed files with 74 additions and 17 deletions

View File

@ -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 Assuming that [Nix][nix] is installed on your machine, clone this repo
and run: and run:
``` shell
$ ./script/install
```
which is equivalent to
``` shell ``` shell
$ nix-env -f ./default.nix -iA snack-exe $ nix-env -f ./default.nix -iA snack-exe
``` ```
@ -75,8 +81,8 @@ The _snack_ executable is now in your `PATH`:
``` shell ``` shell
$ snack --help $ snack --help
Usage: snack [-l|--lib DIR] [-j|--cores INT] ([-s|--package-nix PATH] | Usage: snack [-l|--lib DIR] [-b|--snack-nix PATH] [-j|--cores INT]
[-p|--package-yaml PATH]) COMMAND ([-s|--package-nix PATH] | [-p|--package-yaml PATH]) COMMAND
Available options: Available options:
-l,--lib DIR Path to the directory to use as the Nix library -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, Alternatively, use `$ snack build` or `$ snack ghci` if you only want to build,
or fire up `ghci`, respectively. 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 You may want custom builds that involve things such as [archiving and base64
encoding entire encoding entire

View File

@ -280,9 +280,10 @@ nixBuild snackCfg extraNixArgs nixExpr =
{ #{ intercalate "," funArgs } }: { #{ intercalate "," funArgs } }:
let let
spec = builtins.fromJSON specJson; spec = builtins.fromJSON specJson;
pkgs = import #{ pkgsSrc } {}; config = #{ pkgsSrc };
pkgs = config.pkgs;
libDir = #{ libDir }; libDir = #{ libDir };
snack = (import libDir) { inherit pkgs; }; snack = (import libDir) config;
in #{ T.unpack $ unNixExpr $ nixExpr } in #{ T.unpack $ unNixExpr $ nixExpr }
|]) |])
"nix-build" "nix-build"
@ -291,13 +292,17 @@ nixBuild snackCfg extraNixArgs nixExpr =
pkgsSrc :: String pkgsSrc :: String
pkgsSrc = case snackNix snackCfg of pkgsSrc = case snackNix snackCfg of
Just (SnackNix fp) -> Just (SnackNix fp) ->
[i|(import #{ fp }).pkgs|] [i|(import #{ fp })|]
Nothing -> Nothing ->
[i| [i|
(builtins.fetchTarball { pkgs = import
{ url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz"; (
sha256 = spec.sha256; builtins.fetchTarball
}) { url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
sha256 = spec.sha256;
}
) {} ;
}
|] |]
libDir :: String libDir :: String
libDir = case snackLib snackCfg of libDir = case snackLib snackCfg of

2
script/install Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
nix-env -f ./default.nix -iA snack-exe

View File

@ -2,6 +2,8 @@
# TODO: currently single out derivations prepend the PWD to the path # TODO: currently single out derivations prepend the PWD to the path
# TODO: make sure that filters for "base" are airtight # TODO: make sure that filters for "base" are airtight
{ pkgs { pkgs
, ghc-version ? "ghc822"
, ghcWithPackages ? pkgs.haskell.packages.${ghc-version}.ghcWithPackages
}: }:
with pkgs; with pkgs;
@ -16,7 +18,7 @@ with (callPackage ./package-spec.nix {});
with (callPackage ./hpack.nix {}); with (callPackage ./hpack.nix {});
let let
ghcWith = deps: haskellPackages.ghcWithPackages ghcWith = deps: ghcWithPackages
(ps: map (p: ps.${p}) deps); (ps: map (p: ps.${p}) deps);
# Assumes the package description describes an executable # Assumes the package description describes an executable

View File

@ -1,4 +1,3 @@
{}:
let let
spec = builtins.fromJSON (builtins.readFile ../../../nix/nixpkgs/nixpkgs-src.json); spec = builtins.fromJSON (builtins.readFile ../../../nix/nixpkgs/nixpkgs-src.json);
nixpkgs = nixpkgs =

View File

@ -1,3 +1,4 @@
{ rec {
pkgs = ./nix; pkgs = import ./nix;
ghcWithPackages = pkgs.haskellPackages.ghcWithPackages;
} }

View File

@ -16,6 +16,6 @@ test() {
rm $TMP_FILE rm $TMP_FILE
} }
SNACK="snack -j4 -b snack.nix -s package.nix" test SNACK="snack -j4 --snack-nix snack.nix --package-nix package.nix" test
SNACK="snack -j4 -b snack.nix" test SNACK="snack -j4 --snack-nix snack.nix" test
SNACK="snack -j4 -b snack.nix --package-yaml package.yaml" test SNACK="snack -j4 --snack-nix snack.nix --package-yaml package.yaml" test