git.iko.soy/typeable/rollbar-hs
on master help sign in
Merge pull request #16 from joneshf/nix

Setup nix

commit6c6e76d38349dcfa8cf9717269423e8361e480a9 authorHardy Jones <jones3.hardy@gmail.com> dateSun 26 Aug 2018, 10:53 (8 years ago) parent4a7a2217ca92c0
5 files changed+110−157
.circleci/config.yml+14−48 Makefile+31−43 default.nix+21 shell.nix+44 stack.yaml−66
.circleci/config.yml+14−48
@@ -1,40 +1,26 @@
11version: 2
22jobs:
3− compile:
3+ ghc-8.2.2:
44 docker:
5− - image: haskell:8.2.2
5+ - image: nixorg/nix@sha256:96c3f56563a3b9549ac1da12ff7567c39cb6e648afd6a17d4a1a41f0596ad8f6
66 steps:
77 - checkout
88 - restore_cache:
99 keys:
10− - v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
11− - v1-stack-{{ checksum "package.yaml" }}-
12− - v1-stack-
13− name: Restoring stack cache
10+ - v2-nix-{{ checksum "package.yaml" }}
11+ - v2-nix-
12+ name: Restoring cache
1413 - run:
1514 name: Compile
16− command: make build
17− - persist_to_workspace:
18− root: .
19− paths:
20− - dist
15+ command: nix-shell --run 'make sdist test --jobs=2'
16+ environment:
17+ CABAL_BUILD_FLAGS: --jobs=2
2118 - save_cache:
22− key: v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
23− name: Caching stack
19+ key: v2-nix-{{ checksum "package.yaml" }}
20+ name: Caching nix
2421 paths:
25− - .stack-work
26− - /root/.stack
27−
28− doc-test:
29− docker:
30− - image: haskell:8.2.2
31− steps:
32− - checkout
33− - attach_workspace:
34− at: .
35− - run:
36− name: Doc test
37− command: make test-doc-test
22+ - /nix
23+ - dist
3824
3925 for-github:
4026 docker:
@@ -44,31 +30,11 @@ jobs:
4430 name: Passed
4531 command: echo passed
4632
47− sdist:
48− docker:
49− - image: haskell:8.2.2
50− steps:
51− - checkout
52− - restore_cache:
53− keys:
54− - v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
55− - v1-stack-{{ checksum "package.yaml" }}-
56− - v1-stack-
57− name: Restoring stack cache
58− - run:
59− name: Build sdist
60− command: make sdist
61−
6233workflows:
6334 version: 2
6435 base:
6536 jobs:
66− - compile
6737 - for-github:
6838 requires:
69− - doc-test
70− - sdist
71− - sdist
72− - doc-test:
73− requires:
74− - compile
39+ - ghc-8.2.2
40+ - ghc-8.2.2
Makefile+31−43
@@ -1,64 +1,52 @@
1−BIN ?= bin
21CABAL ?= cabal
2+CABAL_FLAGS ?=
3+CABAL_BUILD_FLAGS ?=
34DIST ?= dist
4−EMPTY ?= .make
5−PROJECT_NAME ?= rollbar-hs
6−STACK ?= stack
7−STACK_WORK ?= .stack-work
8−VERBOSITY ?= warn
5+GHCID ?= ghcid
6+GHCID_FLAGS ?= --ghc-options=-fno-code
7+HPACK ?= hpack
8+NIX_SHELL ?= nix-shell
9+NIX_SHELL_FLAGS ?=
10+PROJECT_NAME := rollbar-hs
911
1012CABAL_FILE := $(PROJECT_NAME).cabal
13+CONFIGURE := $(DIST)/setup-config
1114DOC_TEST := $(DIST)/build/doc-test/doc-test
12−GHCID := $(BIN)/ghcid
13−STACK_FLAGS := --verbosity $(VERBOSITY)
1415
1516.DEFAULT_GOAL := build
1617
17−$(BIN) $(DIST) $(EMPTY):
18− mkdir -p $@
19−
2018$(CABAL_FILE): package.yaml
21− # `stack` has no way to run `hpack` directly.
22− # We can run `hpack` indirectly with little overhead.
23− $(STACK) $(STACK_FLAGS) build --dry-run
24−
25−$(DOC_TEST):
26− rm -f $(EMPTY)/build
27− $(MAKE) $(EMPTY)/build
28−
29−$(EMPTY)/build: $(EMPTY)/stack-setup README.md Setup.hs package.yaml stack.yaml src/**/*.hs test/**/*.hs | $(DIST)
30− $(STACK) $(STACK_FLAGS) build --no-run-tests --test
31− cp -R $$($(STACK) $(STACK_FLAGS) path --dist-dir)/build $(DIST)
32− touch $@
19+ $(HPACK)
3320
34−$(EMPTY)/stack-setup: | $(EMPTY)
35− $(STACK) $(STACK_FLAGS) setup
36− touch $@
21+$(CONFIGURE): $(CABAL_FILE)
22+ $(CABAL) $(CABAL_FLAGS) configure --enable-tests
3723
38−$(GHCID): $(EMPTY)/stack-setup | $(BIN)
39− $(STACK) $(STACK_FLAGS) install ghcid --local-bin-path $(BIN)
24+.PHONY: build
25+build $(DOC_TEST): $(CONFIGURE) default.nix
26+ $(CABAL) $(CABAL_FLAGS) build $(CABAL_BUILD_FLAGS)
4027
41−.PHONT: build
42−build: $(EMPTY)/build
43−
44−.PHONY: cabal-check
45−cabal-check: $(CABAL_FILE)
46− $(CABAL) check
28+.PHONY: check
29+check: $(CABAL_FILE)
30+ $(CABAL) $(CABAL_FLAGS) check
4731
4832.PHONY: clean
4933clean:
5034 rm -f $(CABAL_FILE)
51− rm -fr $(BIN)
5235 rm -fr $(DIST)
53− rm -fr $(EMPTY)
54− rm -fr $(STACK_WORK)
36+
37+default.nix: $(CABAL_FILE)
38+ cabal2nix . > $@
5539
5640.PHONY: sdist
57−sdist: cabal-check | $(DIST)
58− $(CABAL) sdist
41+sdist: check
42+ $(CABAL) $(CABAL_FLAGS) sdist
43+
44+.PHONY: shell
45+shell:
46+ $(NIX_SHELL) --pure $(NIX_SHELL_FLAGS)
5947
6048.PHONY: test
61−test: $(EMPTY)/build test-doc-test
49+test: test-doc-test
6250
6351.PHONY: test-doc-test
6452test-doc-test: $(DOC_TEST)
@@ -66,8 +54,8 @@ test-doc-test: $(DOC_TEST)
6654
6755.PHONY: upload-hackage
6856upload-hackage: sdist
69− @ $(CABAL) upload $(DIST)/$(PROJECT_NAME)-*.tar.gz
57+ @ $(CABAL) $(CABAL_FLAGS) upload $(DIST)/$(PROJECT_NAME)-*.tar.gz
7058
7159.PHONY: watch
72−watch: $(GHCID)
73− $(GHCID)
60+watch: $(CONFIGURE)
61+ $(GHCID) --command "cabal repl lib:$(PROJECT_NAME) $(GHCID_FLAGS)"
default.nixnew file+21
@@ -0,0 +1,21 @@
1+{ mkDerivation, aeson, base, bytestring, case-insensitive, hostname
2+, hspec, hspec-golden-aeson, http-client, http-conduit, http-types
3+, network, QuickCheck, stdenv, text, time, unordered-containers
4+, uuid
5+}:
6+mkDerivation {
7+ pname = "rollbar-hs";
8+ version = "0.3.1.0";
9+ src = ./.;
10+ libraryHaskellDepends = [
11+ aeson base bytestring case-insensitive hostname http-client
12+ http-conduit http-types network text time unordered-containers uuid
13+ ];
14+ testHaskellDepends = [
15+ aeson base bytestring case-insensitive hspec hspec-golden-aeson
16+ QuickCheck text unordered-containers
17+ ];
18+ homepage = "https://github.com/joneshf/rollbar-hs#readme";
19+ description = "Core Rollbar data types and APIs";
20+ license = stdenv.lib.licenses.bsd3;
21+}
shell.nixnew file+44
@@ -0,0 +1,44 @@
1+{ compiler ? "ghc822" }:
2+
3+let
4+
5+ default = haskell-packages.callPackage (import ./default.nix) {};
6+
7+ derivation = nixpkgs.haskell.lib.addBuildTools default tools;
8+
9+ haskell-packages = nixpkgs.haskell.packages.${compiler};
10+
11+ nixpkgs = import nixpkgs-tarball {};
12+
13+ nixpkgs-revision = "120b013e0c082d58a5712cde0a7371ae8b25a601";
14+
15+ nixpkgs-sha256 = "0hk4y2vkgm1qadpsm4b0q1vxq889jhxzjx3ragybrlwwg54mzp4f";
16+
17+ nixpkgs-tarball = builtins.fetchTarball {
18+ sha256 = nixpkgs-sha256;
19+ url = "https://github.com/NixOS/nixpkgs/archive/${nixpkgs-revision}.tar.gz";
20+ };
21+
22+ # Tools affected by the compiler version.
23+ tools-compiler = [
24+ haskell-packages.cabal-install
25+ haskell-packages.ghc
26+ haskell-packages.ghcid
27+ haskell-packages.hpack
28+ ];
29+
30+ # Tools that deal with the basic project infrastructure.
31+ tools-infrastructure = [
32+ nixpkgs.cabal2nix
33+ nixpkgs.curl
34+ nixpkgs.which
35+ ];
36+
37+ # All of the tools.
38+ tools =
39+ tools-compiler ++
40+ tools-infrastructure;
41+
42+in
43+
44+ derivation.env
stack.yamldeleted−66
@@ -1,66 +0,0 @@
1−# This file was automatically generated by 'stack init'
2−#
3−# Some commonly used options have been documented as comments in this file.
4−# For advanced use and comprehensive documentation of the format, please see:
5−# https://docs.haskellstack.org/en/stable/yaml_configuration/
6−
7−# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8−# A snapshot resolver dictates the compiler version and the set of packages
9−# to be used for project dependencies. For example:
10−#
11−# resolver: lts-3.5
12−# resolver: nightly-2015-09-21
13−# resolver: ghc-7.10.2
14−# resolver: ghcjs-0.1.0_ghc-7.10.2
15−# resolver:
16−# name: custom-snapshot
17−# location: "./custom-snapshot.yaml"
18−resolver: lts-10.5
19−
20−# User packages to be built.
21−# Various formats can be used as shown in the example below.
22−#
23−# packages:
24−# - some-directory
25−# - https://example.com/foo/bar/baz-0.0.2.tar.gz
26−# - location:
27−# git: https://github.com/commercialhaskell/stack.git
28−# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
29−# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
30−# extra-dep: true
31−# subdirs:
32−# - auto-update
33−# - wai
34−#
35−# A package marked 'extra-dep: true' will only be built if demanded by a
36−# non-dependency (i.e. a user package), and its test suites and benchmarks
37−# will not be run. This is useful for tweaking upstream packages.
38−packages:
39−- .
40−# Dependency packages to be pulled from upstream that are not in the resolver
41−# (e.g., acme-missiles-0.3)
42−# extra-deps: []
43−
44−# Override default flag values for local packages and extra-deps
45−# flags: {}
46−
47−# Extra package databases containing global packages
48−# extra-package-dbs: []
49−
50−# Control whether we use the GHC we find on the path
51−# system-ghc: true
52−#
53−# Require a specific version of stack, using version ranges
54−# require-stack-version: -any # Default
55−# require-stack-version: ">=1.6"
56−#
57−# Override the architecture used by stack, especially useful on Windows
58−# arch: i386
59−# arch: x86_64
60−#
61−# Extra directories used by stack for building
62−# extra-include-dirs: [/path/to/dir]
63−# extra-lib-dirs: [/path/to/dir]
64−#
65−# Allow a newer minor version of GHC than the snapshot specifies
66−# compiler-check: newer-minor