-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
179 lines (156 loc) · 5.23 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
{
description = "Stampede dev environment and pre-push checks";
# NOTE: enter the environment with `nix develop .#`
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.systems.url = "github:nix-systems/default";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-utils.inputs.systems.follows = "systems";
inputs.git-hooks.url = "github:cachix/git-hooks.nix";
inputs.git-hooks.inputs.nixpkgs.follows = "nixpkgs";
outputs = {
# self,
# systems,
nixpkgs,
flake-utils,
git-hooks,
...
}:
flake-utils.lib.eachDefaultSystem
(
system: let
# NOTE: change to false to disable commit checks
# when disabling, also run "pre-commit uninstall" to disable
enablePreCommitChecks = true;
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
systemPackages =
lib.optionals pkgs.stdenv.isLinux [
# For ExUnit Notifier on Linux.
pkgs.libnotify
# For file_system on Linux.
pkgs.inotify-tools
]
++ lib.optionals pkgs.stdenv.isDarwin [
# For ExUnit Notifier on macOS.
pkgs.terminal-notifier
# For file_system on macOS.
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.darwin.apple_sdk.frameworks.CoreServices
];
########################
# Erlang/Elixir versions
erl = with pkgs; beam.packages.erlang_26;
# # Use graphics-free Erlang. Makes sense but requires full rebuild, as of 10/2024
# erl = with pkgs; beam_nox.packages.erlang_26;
ex = erl.elixir_1_16;
########################
# Python versions
python = pkgs.python312;
mkPyPkg = name: python.withPackages (ps: [(builtins.getAttr name ps)]);
########################
# Git pre-push checks
pc-hooks = git-hooks.lib.${system}.run {
# only run on push and directly calling `pre-commit` in the shell
default_stages = ["manual" "push" "pre-merge-commit"];
src = ./.;
hooks = let
enable_on_commit = {
enable = true;
stages = ["manual" "push" "pre-merge-commit" "pre-commit"];
};
in {
check-merge-conflicts.enable = true;
check-vcs-permalinks.enable = true;
editorconfig-checker = enable_on_commit;
# TODO: tagref
alejandra = enable_on_commit;
flake-checker.enable = true;
# NOTE: disable to reduce deps
actionlint = enable_on_commit;
yamlfmt = enable_on_commit;
convco = {
enable = true;
stages = ["commit-msg"];
};
deadnix.enable = true;
dialyzer = {
enable = true;
package = ex;
pass_filenames = false;
require_serial = true;
};
custom-mix-test = {
enable = true;
name = "mix-test";
entry = "${ex}/bin/mix test";
files = "\\.exs?$";
types = ["text"];
pass_filenames = false;
require_serial = true;
};
custom-mix-format =
enable_on_commit
// {
name = "mix-format";
entry = "${ex}/bin/mix format --check-formatted";
files = "\\.exs?$";
types = ["text"];
pass_filenames = false;
require_serial = true;
};
mypy =
enable_on_commit
// {
package = mkPyPkg "mypy";
};
black =
enable_on_commit
// {
package = mkPyPkg "black";
};
};
};
in {
#####################
# FLAKE OUTPUTS
checks.default = pc-hooks;
devShells.default = let
#####################
# DEV SHELL WITH PRE-PUSH HOOKS
inputs =
[
ex
(erl.elixir-ls.override {elixir = ex;})
pkgs.libyaml
pkgs.libyaml.dev
python
(mkPyPkg "python-lsp-server")
(mkPyPkg "pylsp-mypy")
(mkPyPkg "python-lsp-black")
pkgs.nixd
]
++ pc-hooks.enabledPackages
++ systemPackages;
# define shell startup command
sh-hook =
''
export FLAKE_PYTHON="${python}/bin/python3"
# this allows mix to work on the local directory
mkdir -p .nix-mix
mkdir -p .nix-hex
export MIX_HOME=$PWD/.nix-mix
export HEX_HOME=$PWD/.nix-hex
export PATH=$MIX_HOME/bin:$PATH
export PATH=$HEX_HOME/bin:$PATH
export LANG=en_US.UTF-8
export ERL_AFLAGS="-kernel shell_history enabled"
''
+ lib.optionalString enablePreCommitChecks pc-hooks.shellHook;
in
pkgs.mkShell {
buildInputs = inputs;
shellHook = sh-hook;
};
}
);
}