-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
191 lines (171 loc) · 8.09 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{
description = "A simple Haskell project with Nix Flakes support";
inputs = {
#nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
#nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz"; # Get the current unstable Nixpkgs
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz"; # Get the current stable Nixpkgs
#nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
#nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2405.635167.tar.gz";
#flake-utils.url = "github:numtide/flake-utils";
flake-utils.url = "https://flakehub.com/f/numtide/flake-utils/0.1.101.tar.gz";
};
outputs = { self, nixpkgs, flake-utils }:
#flake-utils.lib.eachDefaultSystem (system:
flake-utils.lib.eachSystem [
"x86_64-linux"
#"aarch64-linux"
] (system:
let
pkgs = import nixpkgs {
inherit system;
#overlays = [
# (self: super: {
# #my-haskell-project = super.haskellPackages.callCabal2nix "my-haskell-project" (self.flake) {};
# my-haskell-project = super.haskellPackages.callCabal2nix "my-haskell-project" ./app {};
# })
#];
};
#pkgs = nixpkgs.legacyPackages.${system}; # 'error: expected a derivation' when run 'nix flake show'
#pkgs = nixpkgs.legacyPackages.x86_64-linux;
# Define a custom derivation
#myHaskellProject = pkgs.haskellPackages.mkDerivation {
# pname = "my-haskell-project";
# version = "0.1.0.0";
# src = ./app;
#
# # Add the required license field
# license = pkgs.lib.licenses.mit;
#
# # Overriding the build phase to use cabal build
# buildPhase = ''
# cabal configure
# cabal build
# '';
#
# installPhase = ''
# mkdir -p $out/bin
# cp -r dist-newstyle/build/*/*/*/build/my-haskell-project/my-haskell-project $out/bin/
# '';
#};
#haskellPackages = pkgs.haskellPackages;
# Define the Haskell project using callCabal2nix
#myHaskellProject = pkgs.haskellPackages.callCabal2nix "my-haskell-project" ./app {};
myHaskellProject = pkgs.haskellPackages.callCabal2nix "my-haskell-project" ./. {};
#myHaskellProject = haskellPackages.callCabal2nix "my-haskell-project" ./. {};
in
{
#devShell = pkgs.mkShell {
# buildInputs = [
# pkgs.haskellPackages.ghc
# pkgs.haskellPackages.cabal-install
# pkgs.neovim
# pkgs.haskell-language-server
# pkgs.haskellPackages.ormolu
# pkgs.ripgrep
# pkgs.cowsay
# ];
#};
#
#devShell = pkgs.mkShell {
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
haskellPackages.ghc
haskellPackages.cabal-install
haskellPackages.hspec # A Testing Framework for Haskell.
haskellPackages.hspec-contrib # Contributed functionality for Hspec.
haskellPackages.hspec-discover # Automatically discover and run Hspec tests.
haskellPackages.ormolu # A formatter for Haskell source code.
# ormolu --mode inplace $(find . -name '*.hs')
haskellPackages.fourmolu # A formatter for Haskell source code.
haskellPackages.hlint # a tool that provides suggestions for improving your Haskell code.
haskellPackages.ghcid # a GHCi-based development tool that provides features like code completion and type checking.
# ghcid -c "cabal repl"
jupyter # A high-level dynamically-typed programming language
ihaskell # A Haskell backend kernel for the Jupyter project. ihaskell-with-packages
haskellPackages.hoogle # a search engine for Haskell documentation; Haskell API search.
haskellPackages.haskell-language-server # LSP server for GHC. The Haskell Language Server can be used with Neovim (or other editors) for features like auto-completion, type information, and more.
ripgrep #ripgrep-all # Utility that combines the usability of The Silver Searcher with the raw speed of grep.
neovim
cowsay
#jupyternotebook+ihaskel # https://github.com/IHaskell/IHaskelll
];
#PS1="$(echo $PS1 | sed 's;\\n;;g') \e[0;31m(nixdev)\e[m "
#PS1="$(echo $PS1 | sed 's;\\n;;g' | sed 's/\]\\\$/] \e[0;31m(nixdev)\e[m \$/g') "
shellHook = ''
echo "---> Haskell development environment loaded! <--- flake.nix"
echo "Available tools:"
echo " - GHC: $(ghc --version)"
echo " - Cabal: $(cabal --version | head -n 1)"
echo " - Ormolu: $(ormolu --version | head -n 1)"
echo " - HLint: $(hlint --version)"
echo " - Ghcid: $(ghcid --version)"
echo " - Haskell Language Server: $(haskell-language-server-wrapper --version)"
echo "Remember to run 'cabal update' if you haven't recently!"
PS1="$(echo $PS1 | sed 's;\\n;;g') \e[0;31m(nixdev)\e[m "
'';
};
#
# Separate the development environment configuration in shell.nix, so flake.nix file focus on the package definition
#devShell = import ./shell.nix { pkgs = pkgs; };
#devShells.default = import ./shell.nix { pkgs = pkgs; };
# when we build with 'nix build'
#defaultPackage = pkgs.my-haskell-project;
#defaultPackage = myHaskellProject;
packages.default = myHaskellProject;
# and then run it with 'nix run'
# nix run .#test1 # not work
# nix run .#test2 # not work
#
# nix develop
# cabal test test1
# cabal test test2
#
# cabal test
apps = {
# # nix run .#speed-functions-test # working
# # cabal test speed-functions-test # working
# #speed-functions-test = flake-utils.lib.mkApp {
speed-functions-test = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "run-test1" ''
${pkgs.cabal-install}/bin/cabal test speed-functions-test
'';
};
};
# XXX: ???
# Define test using the 'checks' attribute for testing
# nix flake check
# nix flake check .#test1
# nix flake check .#test2
checks = {
# test1:
# nix flake check # working
# nix flake check .#speed-functions-test # not working
#speed = pkgs.haskellPackages.callCabal2nix "my-haskell-project-speed-test" ./. {};
#speed-functions-test = pkgs.haskellPackages.callCabal2nix "my-haskell-project" ./. {};
speed-functions-test = myHaskellProject; # working
#
# XXX:
# nix flake check --> error
# nix flake check .#speed-functions-test --> error
#speed-functions-test = pkgs.runCommand "speed-functions-test" { buildInputs = [ myHaskellProject ]; } ''
# ${pkgs.cabal-install}/bin/cabal test speed-functions-test
# touch $out
#'';
#format = flake-utils.lib.checkNixFormat; # ...
format = pkgs.runCommand "check-format" {
buildInputs = [ pkgs.ormolu ];
} ''
ormolu --mode check $(find ${./.} -name '*.hs')
touch $out
'';
#lint = flake-utils.lib.checkNikLint; # ...
lint = pkgs.runCommand "check-lint" {
buildInputs = [ pkgs.hlint ];
} ''
hlint ${./.}
touch $out
'';
};
}
);
}