-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
86 lines (76 loc) · 2.61 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 = "Sonowz Backend";
inputs = {
nixpkgs.url = "nixpkgs/23.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
version = "1.0.0";
name = "sonowz-backend";
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.lib;
haskellPkgs = pkgs.haskell.packages.ghc925; # The version should match with resolver!
haskellLib = pkgs.haskell.lib;
requirements = pkgs.callPackage ./nix/requirements.nix {};
devRequirements = with pkgs; [
stack-wrapped
cabal-install
custom-hls
haskellPkgs.ormolu
hlint
];
custom-hls = pkgs.callPackage ./nix/hls.nix { inherit lib; inherit haskellPkgs; inherit haskellLib; };
# https://docs.haskellstack.org/en/stable/nix_integration/#supporting-both-nix-and-non-nix-developers
stack-wrapped = pkgs.symlinkJoin {
name = "stack";
version = pkgs.stack.version;
paths = [ pkgs.stack ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "\
--no-nix \
--system-ghc \
--no-install-ghc \
"
'';
};
# TODO: remove hardcoded path
binPath = /home/sonowz/sonowz-backend/bin;
# This app is an impure derivation for dev purpose
# Use 'flake.nix' inside each package for production packages
# Build command : nix build --impure
app = pkgs.stdenv.mkDerivation {
inherit name;
inherit version;
src = binPath;
nativeBuildInputs = [];
propagatedBuildInputs = requirements;
installPhase = ''
mkdir -p $out/bin
cp -r . $out/bin
'';
};
in
{
inherit app;
defaultPackage = app;
devShell = (pkgs.haskell.lib.buildStackProject {
inherit name;
inherit version;
ghc = haskellPkgs.ghc;
stack = stack-wrapped;
buildInputs = requirements;
enterShell = ''eval "$(stack --bash-completion-script stack)"'';
}).overrideAttrs (final: prev: {
buildInputs = prev.buildInputs ++ devRequirements;
});
/* devShell = pkgs.mkShell {
buildInputs = devRequirements ++ requirements ++ [ stack-wrapped ghc ];
# LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.glibc ];
}; */
}
);
}