This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
86 lines (77 loc) · 3.47 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
description = "my project description";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
inputs.flake-utils.url = "github:numtide/flake-utils";
# When building myApp through pkgs.haskell.lib.buildStackProject (down below)
# Stack should download Haskell packages directly from Stackage and bypass Nix,
# so force Nix to allow this "non-sandboxed" build. See https://zimbatm.com/notes/nix-packaging-the-heretic-way
nixConfig.sandbox = "relaxed";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# Nix GHC version needs to be the one that the stack.yaml resolver expects.
#
# Find out available Nix GHCs:
# ```
# $ nix repl
# nix-repl> :lf nixpkgs
# nix-repl> legacyPackages.x86_64-linux.haskell.packages.<TAB>
# ```
# `:lf` stands for "load flake"
#
# Find out expected Stack GHCs:
# Visit https://www.stackage.org/ and look for LTS or Nightlies, e.g.
# resolver: lts-20.11 expects ghc-9.2.5
# resolver: nightly-2023-02-14 expects ghc-9.4.4
#
# So if you use "ghc944", set "resolver: nightly-2023-02-14" in your stack.yaml file
hPkgs = pkgs.haskell.packages."ghc944"; # Nix GHC version 9.4.4
myLibDeps = [
pkgs.zlib # External C compression library needed by some Haskell packages
];
myLocalDevTools = [
hPkgs.ghc # GHC compiler in the version above; verify with `ghc --version`
stack-wrapped
#hPkgs.ghcid # Continous terminal Haskell compile checker
#hPkgs.ormolu # Haskell formatter
hPkgs.hlint # Haskell codestyle checker
hPkgs.hoogle # Lookup Haskell documentation
hPkgs.haskell-language-server # LSP server for editor
hPkgs.implicit-hie # auto generate LSP hie.yaml file from cabal
hPkgs.retrie # Haskell refactoring tool
# hPkgs.cabal-install
];
# Wrap Stack to work with our custom Nix integration. We don't modify stack.yaml so it keeps working for non-Nix users.
# --no-nix # Don't use Stack's built-in Nix integrating.
# --system-ghc # Use the existing GHC on PATH (will be provided through this Nix file)
# --no-install-ghc # Don't try to install GHC if no matching GHC version found on PATH
stack-wrapped = pkgs.symlinkJoin {
name = "stack"; # will be available as the usual `stack` in terminal
paths = [ pkgs.stack ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "\
--no-nix \
--system-ghc \
--no-install-ghc \
"
'';
};
myApp = pkgs.haskell.lib.buildStackProject {
name = "myStack";
src = ./.;
ghc = hPkgs.ghc;
buildInputs = myLibDeps;
};
in {
devShells.default = pkgs.mkShell {
buildInputs = myLocalDevTools;
# Make external Nix C libraries like zlib known to GHC, like pkgs.haskell.lib.buildStackProject does
# https://github.com/NixOS/nixpkgs/blob/d64780ea0e22b5f61cd6012a456869c702a72f20/pkgs/development/haskell-modules/generic-stack-builder.nix#L38
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath myLibDeps;
};
packages.default = myApp;
});
}