Skip to content

Commit d6c1f70

Browse files
authored
Non-invasive Nix + Nix Flake dev shell support (#106)
* add nix flake.nix and shell.nix to support 'nix develop' and 'nix-shell' on systems with flake-enabled nix * remove unneeded packages
1 parent 51e88eb commit d6c1f70

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ haddock-out/
88
runtests.log
99
regression-tests/out
1010

11+
.envrc
12+
1113
# Created by https://www.toptal.com/developers/gitignore/api/haskell
1214
# Edit at https://www.toptal.com/developers/gitignore?templates=haskell
1315

flake.lock

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
description = "sslang: a language built atop the Sparse Synchronous Model";
3+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
4+
inputs.flake-utils.url = "github:numtide/flake-utils";
5+
6+
outputs = { self, nixpkgs, flake-utils }:
7+
flake-utils.lib.eachDefaultSystem (system:
8+
let
9+
pkgs = nixpkgs.legacyPackages.${system};
10+
11+
hPkgs =
12+
pkgs.haskell.packages."ghc8107"; # need to match Stackage LTS version
13+
# from stack.yaml resolver
14+
15+
myDevTools = [
16+
hPkgs.ghc # GHC compiler in the desired version (will be available on PATH)
17+
hPkgs.hlint # Haskell codestyle checker
18+
hPkgs.haskell-language-server # LSP server for editor
19+
stack-wrapped
20+
pkgs.zlib # External C library needed by some Haskell packages
21+
];
22+
23+
# Wrap Stack to work with our Nix integration. We don't want to modify
24+
# stack.yaml so non-Nix users don't notice anything.
25+
# - no-nix: We don't want Stack's way of integrating Nix.
26+
# --system-ghc # Use the existing GHC on PATH (will come from this Nix file)
27+
# --no-install-ghc # Don't try to install GHC if no matching GHC found on PATH
28+
stack-wrapped = pkgs.symlinkJoin {
29+
name = "stack"; # will be available as the usual `stack` in terminal
30+
paths = [ pkgs.stack ];
31+
buildInputs = [ pkgs.makeWrapper ];
32+
postBuild = ''
33+
wrapProgram $out/bin/stack \
34+
--add-flags "\
35+
--no-nix \
36+
--system-ghc \
37+
--no-install-ghc \
38+
"
39+
'';
40+
};
41+
in {
42+
devShells.default = pkgs.mkShell {
43+
buildInputs = myDevTools;
44+
45+
# Make external Nix c libraries like zlib known to GHC, like
46+
# pkgs.haskell.lib.buildStackProject does
47+
# https://github.com/NixOS/nixpkgs/blob/d64780ea0e22b5f61cd6012a456869c702a72f20/pkgs/development/haskell-modules/generic-stack-builder.nix#L38
48+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath myDevTools;
49+
};
50+
});
51+
}

shell.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{ system ? builtins.currentSystem }:
2+
3+
(builtins.getFlake (toString ./.)).devShells.${system}

0 commit comments

Comments
 (0)