Skip to content

Commit 5028e72

Browse files
committed
Use nix and direnv
1 parent 401a43b commit 5028e72

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

.envrc

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
ssh-add -K &> /dev/null || true
2+
3+
my_ssh_auth_sock=$SSH_AUTH_SOCK
4+
5+
6+
# Usage: use nix_shell
7+
#
8+
# Works like use_nix, except that it's only rebuilt if the shell.nix or shell.nix file changes.
9+
# This avoids scenarios where the nix-channel is being updated and all the projects now need to be re-built.
10+
#
11+
# To force the reload the derivation, run `touch shell.nix`
12+
use_nix_shell() {
13+
local nixcache=".direnv.cache"
14+
local tempfile=
15+
16+
if [[ ! -e "$nixcache" ]] || [[ ".envrc" -nt "$nixcache" ]] || [[ "shell.nix" -nt "$nixcache" ]] || [[ "shell.nix" -nt "$nixcache" ]]; then
17+
tempfile="$(mktemp "$nixcache.XXXXXX")"
18+
nix-shell --show-trace --run 'direnv dump' > "$tempfile" && mv "$tempfile" "$nixcache"
19+
rm -f "$tempfile"
20+
tempfile=
21+
fi
22+
direnv_load cat "$nixcache"
23+
for f in $(git ls-files '*.nix'); do
24+
watch_file $f
25+
done
26+
}
27+
28+
# Configure a custom nix Cache
29+
export NIX_CONF_DIR="$(pwd)"
30+
31+
use_nix_shell
32+
33+
export SSH_AUTH_SOCK=$my_ssh_auth_sock

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ cabal.sandbox.config
3232
test/index.html
3333
*.cabal
3434
binaries
35+
.direnv.cache

nix/pkgs.nix

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
let
2+
fetch = { rev, sha256 }:
3+
builtins.fetchTarball {
4+
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
5+
sha256 = sha256;
6+
};
7+
8+
9+
config = {
10+
packageOverrides = pkgs: rec {
11+
haskellPackages = pkgs.haskellPackages.override {
12+
overrides = haskellPackagesNew: haskellPackagesOld: rec {
13+
# Example of an override:
14+
# dotenv = haskellPackagesNew.callPackage ./dotenv.nix { };
15+
};
16+
};
17+
};
18+
};
19+
20+
pkgsPath = fetch {
21+
# This comes from https://nixos.org/channels/
22+
#
23+
# Pick a release (e.g. nixpkgs-18.09-darwin) and then open the `git-revision`
24+
# file. It will contain a rev like this.
25+
#
26+
# Example: https://releases.nixos.org/nixpkgs/18.09-darwin/nixpkgs-darwin-18.09pre154040.58fbebc4ea5/git-revision
27+
rev = "9ec7625cee5365c741dee7b45a19aff5d5d56205";
28+
29+
# Generate this sha using the following command:
30+
#
31+
# $ nix-prefetch-url --unpack --type sha256 https://github.com/NixOS/nixpkgs/archive/<rev>.tar.gz
32+
sha256 = "0rh26fhdvnp9ssk8g63ysyzigw9zg43k9bd2fzrvhrk75sav723h";
33+
};
34+
in {
35+
pkgs = import pkgsPath { config = config; };
36+
}

shell.nix

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{ pkgs ? (import ./nix/pkgs.nix).pkgs, ghc ? pkgs.ghc }:
2+
pkgs.haskell.lib.buildStackProject {
3+
inherit ghc;
4+
name = "jetpack";
5+
buildInputs = [
6+
pkgs.gcc
7+
pkgs.libiconv
8+
pkgs.ncurses
9+
pkgs.nodejs-10_x
10+
pkgs.packer
11+
pkgs.pcre
12+
pkgs.pkgconfig
13+
pkgs.stack
14+
pkgs.zlib
15+
] ++
16+
(if pkgs.stdenv.system == "x86_64-darwin" then
17+
[
18+
# MacOS dependency of http-client-tls haskell lib, used by content_creation binary.
19+
pkgs.darwin.apple_sdk.frameworks.Cocoa
20+
pkgs.darwin.apple_sdk.frameworks.CoreServices
21+
]
22+
else []);
23+
}

stack.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ extra-package-dbs: []
33
packages:
44
- '.'
55
resolver: lts-13.30
6+
nix:
7+
enable: true
8+
shell-file: shell.nix

0 commit comments

Comments
 (0)