-
Notifications
You must be signed in to change notification settings - Fork 5
/
flake.nix
239 lines (206 loc) · 7.24 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
{
description = "Decrypt and encrypt agenix secrets inside Emacs";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
bash-strict-mode = {
url = "github:sellout/bash-strict-mode";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager/release-24.05";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs: let
systems = [
"aarch64-darwin"
"aarch64-linux"
"i686-linux"
"x86_64-darwin"
"x86_64-linux"
];
in
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
inherit systems;
flake = {
overlays = {
default = final: prev: {
emacsPackagesFor = emacs:
(prev.emacsPackagesFor emacs).overrideScope
(inputs.self.lib.overlays.emacs final prev);
};
};
lib.overlays.emacs = final: prev: efinal: eprev: {
agenix = inputs.self.packages.${final.system}.agenix-el;
};
homeConfigurations =
builtins.listToAttrs
(builtins.map (system: {
name = "${system}-example";
value = inputs.home-manager.lib.homeManagerConfiguration {
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [inputs.self.overlays.default];
};
modules = [./nix/home.nix];
};
})
systems);
};
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: let
src = pkgs.lib.cleanSource ./.;
emacsPackageDir = "share/emacs/site-lisp/elpa";
emacsPath = package: "${package}/${emacsPackageDir}/${package.ename}-${package.version}";
# Read version in format: ;; Version: xx.yy
readVersion = fp:
builtins.elemAt
(builtins.match ".*(;; Version: ([[:digit:]]+\.[[:digit:]]+)).*" (builtins.readFile fp))
1;
# We need to tell Eldev where to find its Emacs package.
ELDEV_LOCAL = emacsPath pkgs.emacsPackages.eldev;
in {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [(import ./nix/dependencies.nix)];
};
packages = {
default = self'.packages.agenix-el;
agenix-el =
inputs.bash-strict-mode.lib.checkedDrv pkgs
(pkgs.emacsPackages.trivialBuild {
inherit ELDEV_LOCAL src;
pname = "agenix";
version = readVersion ./agenix.el;
nativeBuildInputs = [
pkgs.emacs
# Emacs-lisp build tool, https://doublep.github.io/eldev/
pkgs.emacsPackages.eldev
];
doCheck = true;
checkPhase = ''
runHook preCheck
eldev test
runHook postCheck
'';
doInstallCheck = true;
instalCheckPhase = ''
runHook preInstallCheck
eldev --packaged test
runHook postInstallCheck
'';
});
};
devShells.default =
## TODO: Use `inputs.bash-strict-mode.lib.checkedDrv` here after
## NixOS/nixpkgs#204606 makes it into a release.
inputs.bash-strict-mode.lib.drv pkgs
(pkgs.mkShell {
inputsFrom =
builtins.attrValues inputs.self.checks.${system}
++ builtins.attrValues inputs.self.packages.${system};
nativeBuildInputs = [
# Nix language server,
# https://github.com/oxalica/nil#readme
pkgs.nil
# Bash language server,
# https://github.com/bash-lsp/bash-language-server#readme
pkgs.nodePackages.bash-language-server
];
});
checks = {
eldev-doctor =
inputs.bash-strict-mode.lib.checkedDrv pkgs
(pkgs.stdenv.mkDerivation {
inherit ELDEV_LOCAL src;
name = "eldev-doctor";
nativeBuildInputs = [
pkgs.emacs
# Emacs-lisp build tool, https://doublep.github.io/eldev/
pkgs.emacsPackages.eldev
];
buildPhase = ''
runHook preBuild
## TODO: Currently needed to make a temp file in
## `eldev--create-internal-pseudoarchive-descriptor`.
export HOME="$(mktemp --directory --tmpdir fake-home.XXXXXX)"
mkdir -p "$HOME/.cache/eldev"
eldev doctor
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
runHook postInstall
'';
});
eldev-lint =
inputs.bash-strict-mode.lib.checkedDrv pkgs
(pkgs.stdenv.mkDerivation {
inherit ELDEV_LOCAL src;
name = "eldev-lint";
nativeBuildInputs = [
pkgs.emacs
pkgs.emacsPackages.eldev
];
postPatch = ''
{ echo
echo "(mapcar"
echo " 'eldev-use-local-dependency"
echo " '(\"${emacsPath pkgs.emacsPackages.dash}\""
echo " \"${emacsPath pkgs.emacsPackages.elisp-lint}\""
echo " \"${emacsPath pkgs.emacsPackages.package-lint}\""
echo " \"${emacsPath pkgs.emacsPackages.relint}\""
echo " \"${emacsPath pkgs.emacsPackages.xr}\"))"
} >> Eldev
'';
buildPhase = ''
runHook preBuild
## TODO: Currently needed to make a temp file in
## `eldev--create-internal-pseudoarchive-descriptor`.
export HOME="$PWD/fake-home"
mkdir -p "$HOME"
## NB: Need `--external` here so that we don’t try to download any
## package archives (which would break the sandbox).
## TODO: Re-enable relint, currently it errors, I think because it
## or Eldev is expecting a multi-file package.
eldev --external lint elisp # re
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
runHook preInstall
'';
});
nix-fmt = pkgs.stdenv.mkDerivation {
inherit src;
name = "nix fmt";
nativeBuildInputs = [self'.formatter];
buildPhase = ''
runHook preBuild
alejandra --check .
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
runHook preInstall
'';
};
};
# Nix code formatter, https://github.com/kamadorueda/alejandra#readme
formatter = pkgs.alejandra;
};
};
}