Skip to content

Commit

Permalink
[#138] Initial attempt to use statix-haskell-nix
Browse files Browse the repository at this point in the history
Resolves #138
  • Loading branch information
chshersh committed Feb 9, 2020
1 parent aa7e20e commit bf0607c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
70 changes: 45 additions & 25 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
{ # The git revision here corresponds to the nixpkgs-unstable channel, which at
# the time of this writing has GHC 8.6.5 as the default compiler (matching the
# one used by stack.yaml). Use https://howoldis.herokuapp.com/ to determine
# the current rev.
pkgs ? import (builtins.fetchTarball "https://github.com/nixos/nixpkgs/archive/002b853782e.tar.gz") {}
# Which GHC compiler to use.
# To determine the list of compilers available run:
# nix-env -f "<nixpkgs>" -qaP -A haskell.compiler
, compiler ? "default"
# Run using:
#
# $(nix-build --no-link -A fullBuildScript)
{
stack2nix-output-path ? "custom-stack2nix-output.nix",
}:
let
haskellPackages =
if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
in
haskellPackages.developPackage {
# The path to our cabal project's root directory
root = ./.;
cabalPackageName = "hit-on";
compiler = "ghc865"; # matching stack.yaml

# Pin static-haskell-nix version.
static-haskell-nix =
if builtins.pathExists ../.in-static-haskell-nix
then toString ../. # for the case that we're in static-haskell-nix itself, so that CI always builds the latest version.
# Update this hash to use a different `static-haskell-nix` version:
else fetchTarball https://github.com/nh2/static-haskell-nix/archive/d1b20f35ec7d3761e59bd323bbe0cca23b3dfc82.tar.gz;

# Pin nixpkgs version
# By default to the one `static-haskell-nix` provides, but you may also give
# your own as long as it has the necessary patches, using e.g.
# pkgs = import (fetchTarball https://github.com/nh2/nixpkgs/archive/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa123.tar.gz) {};
pkgs = import "${static-haskell-nix}/nixpkgs.nix";

# Haskell packages to override
source-overrides = {
github = builtins.fetchTarball "https://github.com/phadej/github/archive/cdae698f50f9e6dc1b58d2181672294e2b11dfb3.tar.gz";
relude = builtins.fetchTarball "https://github.com/kowainik/relude/archive/55968311244690f5cc8b4484a37a63d988ea2ec4.tar.gz";
shellmet = builtins.fetchTarball "https://github.com/kowainik/shellmet/archive/36149eb0eb2b81916a93cdb92f3cb949d2eb9d23.tar.gz";
stack2nix-script = import "${static-haskell-nix}/static-stack2nix-builder/stack2nix-script.nix" {
inherit pkgs;
stack-project-dir = toString ./.; # where stack.yaml is
hackageSnapshot = "2020-02-08T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions
};

overrides = self: super: with pkgs.haskell.lib; {
github = dontCheck super.github; # `dontCheck` skips running tests on this package
static-stack2nix-builder = import "${static-haskell-nix}/static-stack2nix-builder/default.nix" {
normalPkgs = pkgs;
inherit cabalPackageName compiler stack2nix-output-path;
# disableOptimization = true; # for compile speed
};
}

# Full invocation, including pinning `nix` version itself.
fullBuildScript = pkgs.writeShellScript "stack2nix-and-build-script.sh" ''
set -eu -o pipefail
STACK2NIX_OUTPUT_PATH=$(${stack2nix-script})
export NIX_PATH=nixpkgs=${pkgs.path}
${pkgs.nix}/bin/nix-build --no-link -A static_package --argstr stack2nix-output-path "$STACK2NIX_OUTPUT_PATH" "$@"
'';

in
{
static_package = static-stack2nix-builder.static_package;
inherit fullBuildScript;
# For debugging:
inherit stack2nix-script;
inherit static-stack2nix-builder;
}
2 changes: 1 addition & 1 deletion hit-on.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ source-repository head
location: https://github.com/kowainik/hit-on.git

common common-options
build-depends: base ^>= 4.13.0.0
build-depends: base >= 4.12.0.0 && < 4.14
, relude ^>= 0.6.0.0

mixins: base hiding (Prelude)
Expand Down
5 changes: 5 additions & 0 deletions stack-nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resolver: nightly-2020-02-08

extra-deps:
- github-0.23
- binary-instances-1
7 changes: 5 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
resolver: nightly-2019-12-27
resolver: lts-14.7

extra-deps:
- github-0.23
- binary-instances-1
- binary-instances-1 # for github
- optparse-applicative-0.15.1.0
- relude-0.6.0.0
- shellmet-0.0.3.0

0 comments on commit bf0607c

Please sign in to comment.