Merge pull request #16 from joneshf/nix

Setup nix
This commit is contained in:
Hardy Jones 2018-08-26 10:53:14 -07:00 committed by GitHub
commit 6c6e76d383
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 157 deletions

View File

@ -1,40 +1,26 @@
version: 2
jobs:
compile:
ghc-8.2.2:
docker:
- image: haskell:8.2.2
- image: nixorg/nix@sha256:96c3f56563a3b9549ac1da12ff7567c39cb6e648afd6a17d4a1a41f0596ad8f6
steps:
- checkout
- restore_cache:
keys:
- v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
- v1-stack-{{ checksum "package.yaml" }}-
- v1-stack-
name: Restoring stack cache
- v2-nix-{{ checksum "package.yaml" }}
- v2-nix-
name: Restoring cache
- run:
name: Compile
command: make build
- persist_to_workspace:
root: .
paths:
- dist
command: nix-shell --run 'make sdist test --jobs=2'
environment:
CABAL_BUILD_FLAGS: --jobs=2
- save_cache:
key: v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
name: Caching stack
key: v2-nix-{{ checksum "package.yaml" }}
name: Caching nix
paths:
- .stack-work
- /root/.stack
doc-test:
docker:
- image: haskell:8.2.2
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Doc test
command: make test-doc-test
- /nix
- dist
for-github:
docker:
@ -44,31 +30,11 @@ jobs:
name: Passed
command: echo passed
sdist:
docker:
- image: haskell:8.2.2
steps:
- checkout
- restore_cache:
keys:
- v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
- v1-stack-{{ checksum "package.yaml" }}-
- v1-stack-
name: Restoring stack cache
- run:
name: Build sdist
command: make sdist
workflows:
version: 2
base:
jobs:
- compile
- for-github:
requires:
- doc-test
- sdist
- sdist
- doc-test:
requires:
- compile
- ghc-8.2.2
- ghc-8.2.2

View File

@ -1,64 +1,52 @@
BIN ?= bin
CABAL ?= cabal
CABAL_FLAGS ?=
CABAL_BUILD_FLAGS ?=
DIST ?= dist
EMPTY ?= .make
PROJECT_NAME ?= rollbar-hs
STACK ?= stack
STACK_WORK ?= .stack-work
VERBOSITY ?= warn
GHCID ?= ghcid
GHCID_FLAGS ?= --ghc-options=-fno-code
HPACK ?= hpack
NIX_SHELL ?= nix-shell
NIX_SHELL_FLAGS ?=
PROJECT_NAME := rollbar-hs
CABAL_FILE := $(PROJECT_NAME).cabal
CONFIGURE := $(DIST)/setup-config
DOC_TEST := $(DIST)/build/doc-test/doc-test
GHCID := $(BIN)/ghcid
STACK_FLAGS := --verbosity $(VERBOSITY)
.DEFAULT_GOAL := build
$(BIN) $(DIST) $(EMPTY):
mkdir -p $@
$(CABAL_FILE): package.yaml
# `stack` has no way to run `hpack` directly.
# We can run `hpack` indirectly with little overhead.
$(STACK) $(STACK_FLAGS) build --dry-run
$(HPACK)
$(DOC_TEST):
rm -f $(EMPTY)/build
$(MAKE) $(EMPTY)/build
$(CONFIGURE): $(CABAL_FILE)
$(CABAL) $(CABAL_FLAGS) configure --enable-tests
$(EMPTY)/build: $(EMPTY)/stack-setup README.md Setup.hs package.yaml stack.yaml src/**/*.hs test/**/*.hs | $(DIST)
$(STACK) $(STACK_FLAGS) build --no-run-tests --test
cp -R $$($(STACK) $(STACK_FLAGS) path --dist-dir)/build $(DIST)
touch $@
.PHONY: build
build $(DOC_TEST): $(CONFIGURE) default.nix
$(CABAL) $(CABAL_FLAGS) build $(CABAL_BUILD_FLAGS)
$(EMPTY)/stack-setup: | $(EMPTY)
$(STACK) $(STACK_FLAGS) setup
touch $@
$(GHCID): $(EMPTY)/stack-setup | $(BIN)
$(STACK) $(STACK_FLAGS) install ghcid --local-bin-path $(BIN)
.PHONT: build
build: $(EMPTY)/build
.PHONY: cabal-check
cabal-check: $(CABAL_FILE)
$(CABAL) check
.PHONY: check
check: $(CABAL_FILE)
$(CABAL) $(CABAL_FLAGS) check
.PHONY: clean
clean:
rm -f $(CABAL_FILE)
rm -fr $(BIN)
rm -fr $(DIST)
rm -fr $(EMPTY)
rm -fr $(STACK_WORK)
default.nix: $(CABAL_FILE)
cabal2nix . > $@
.PHONY: sdist
sdist: cabal-check | $(DIST)
$(CABAL) sdist
sdist: check
$(CABAL) $(CABAL_FLAGS) sdist
.PHONY: shell
shell:
$(NIX_SHELL) --pure $(NIX_SHELL_FLAGS)
.PHONY: test
test: $(EMPTY)/build test-doc-test
test: test-doc-test
.PHONY: test-doc-test
test-doc-test: $(DOC_TEST)
@ -66,8 +54,8 @@ test-doc-test: $(DOC_TEST)
.PHONY: upload-hackage
upload-hackage: sdist
@ $(CABAL) upload $(DIST)/$(PROJECT_NAME)-*.tar.gz
@ $(CABAL) $(CABAL_FLAGS) upload $(DIST)/$(PROJECT_NAME)-*.tar.gz
.PHONY: watch
watch: $(GHCID)
$(GHCID)
watch: $(CONFIGURE)
$(GHCID) --command "cabal repl lib:$(PROJECT_NAME) $(GHCID_FLAGS)"

21
default.nix Normal file
View File

@ -0,0 +1,21 @@
{ mkDerivation, aeson, base, bytestring, case-insensitive, hostname
, hspec, hspec-golden-aeson, http-client, http-conduit, http-types
, network, QuickCheck, stdenv, text, time, unordered-containers
, uuid
}:
mkDerivation {
pname = "rollbar-hs";
version = "0.3.1.0";
src = ./.;
libraryHaskellDepends = [
aeson base bytestring case-insensitive hostname http-client
http-conduit http-types network text time unordered-containers uuid
];
testHaskellDepends = [
aeson base bytestring case-insensitive hspec hspec-golden-aeson
QuickCheck text unordered-containers
];
homepage = "https://github.com/joneshf/rollbar-hs#readme";
description = "Core Rollbar data types and APIs";
license = stdenv.lib.licenses.bsd3;
}

44
shell.nix Normal file
View File

@ -0,0 +1,44 @@
{ compiler ? "ghc822" }:
let
default = haskell-packages.callPackage (import ./default.nix) {};
derivation = nixpkgs.haskell.lib.addBuildTools default tools;
haskell-packages = nixpkgs.haskell.packages.${compiler};
nixpkgs = import nixpkgs-tarball {};
nixpkgs-revision = "120b013e0c082d58a5712cde0a7371ae8b25a601";
nixpkgs-sha256 = "0hk4y2vkgm1qadpsm4b0q1vxq889jhxzjx3ragybrlwwg54mzp4f";
nixpkgs-tarball = builtins.fetchTarball {
sha256 = nixpkgs-sha256;
url = "https://github.com/NixOS/nixpkgs/archive/${nixpkgs-revision}.tar.gz";
};
# Tools affected by the compiler version.
tools-compiler = [
haskell-packages.cabal-install
haskell-packages.ghc
haskell-packages.ghcid
haskell-packages.hpack
];
# Tools that deal with the basic project infrastructure.
tools-infrastructure = [
nixpkgs.cabal2nix
nixpkgs.curl
nixpkgs.which
];
# All of the tools.
tools =
tools-compiler ++
tools-infrastructure;
in
derivation.env

View File

@ -1,66 +0,0 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-10.5
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
# extra-deps: []
# Override default flag values for local packages and extra-deps
# flags: {}
# Extra package databases containing global packages
# extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.6"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor