-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
204 lines (196 loc) · 5.93 KB
/
flake.nix
File metadata and controls
204 lines (196 loc) · 5.93 KB
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
devenv.url = "github:cachix/devenv";
clj-nix.url = "github:jlesquembre/clj-nix";
clj-nix.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
cljfmt.url = "github:noblepayne/cljfmt-flake";
cljfmt.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
devenv,
clj-nix,
treefmt-nix,
cljfmt,
...
} @ inputs: let
supportedSystems = ["x86_64-linux" "aarch64-linux"];
pkgsBySystem = nixpkgs.lib.getAttrs supportedSystems nixpkgs.legacyPackages;
forAllPkgs = fn: nixpkgs.lib.mapAttrs (system: pkgs: (fn system pkgs)) pkgsBySystem;
# treefmt configuration
treefmtEval = forAllPkgs (
system: pkgs:
treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.alejandra.enable = true;
programs.cljfmt.enable = true;
programs.cljfmt.package = cljfmt.packages.${system}.default;
programs.prettier.enable = true;
programs.mdformat.enable = true;
}
);
in {
formatter = forAllPkgs (system: pkgs: treefmtEval.${system}.config.build.wrapper);
checks = forAllPkgs (system: pkgs: {
formatting = treefmtEval.${system}.config.build.check self;
});
devShells = forAllPkgs (system: pkgs': let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
in {
testenv = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
(
{
config,
pkgs,
...
}: {
packages = [
pkgs.clojure
];
services.minio = {
enable = true;
accessKey = "s3accesskey";
secretKey = "s3secretkey";
buckets = ["testbucket"];
};
env = {
ENV = "DEV";
};
}
)
];
};
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
(
{
config,
pkgs,
...
}: {
# https://devenv.sh/reference/options/
packages =
[
pkgs.git
pkgs.babashka
pkgs.jet
pkgs.neovim
#pkgs.vscode
(pkgs.vscode-with-extensions.override {
vscodeExtensions = [
pkgs.vscode-extensions.betterthantomorrow.calva
pkgs.vscode-extensions.vscodevim.vim
pkgs.vscode-extensions.jnoortheen.nix-ide
];
})
]
++ (builtins.attrValues treefmtEval.x86_64-linux.config.build.programs);
languages.clojure.enable = true;
services.minio = {
enable = true;
accessKey = "s3accesskey";
secretKey = "s3secretkey";
buckets = ["testbucket"];
};
# N.B. picks up quotes and inline comments
dotenv.enable = true;
env = {
ENV = "DEV";
};
scripts.format.exec = ''
nix fmt .
cljfmt fix src
cljfmt fix deps.edn
'';
scripts.lock.exec = ''
nix flake lock
nix run .#deps-lock
'';
scripts.update.exec = ''
nix flake update
nix run .#deps-lock
'';
scripts.build.exec = ''
nix build .
'';
scripts.repl.exec = ''
clojure -M:repl \
-m nrepl.cmdline \
--middleware "[cider.nrepl/cider-middleware]" \
-b 0.0.0.0 \
-p 9998
'';
scripts.tests.exec = ''
clojure -M:test
'';
scripts.watch.exec = ''
clojure -M:test/watch
'';
scripts.outdated.exec = ''
clojure -Aoutdated -M -m "antq.core"
'';
scripts.scripts.exec = ''
echo ${builtins.concatStringsSep " " (builtins.attrNames config.scripts)}
'';
enterShell = ''
# start editor
echo "===================================================="
echo "Type \`scripts\` for help and a list of available scripts."
echo -n "Available scripts: "
scripts
echo "===================================================="
echo
echo "Starting editor and user shell..."
export SHELL=$OLDSHELL
code . &>/dev/null
'';
}
)
];
};
});
nixosModules = {
default = {
options,
config,
pkgs,
...
}: {
imports = [./module.nix];
config.services.boostbox.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
};
packages = forAllPkgs (system: pkgs: {
deps-lock = clj-nix.packages.${system}.deps-lock;
container = pkgs.dockerTools.buildLayeredImage {
name = "boostbox";
tag = "latest";
config = {
Entrypoint = ["${self.packages.${system}.default}/bin/boostbox"];
ExposedPorts = {
"8080" = {};
};
};
};
default = clj-nix.lib.mkCljApp {
inherit pkgs;
modules = [
{
projectSrc = ./.;
name = "com.noblepayne/boostbox";
main-ns = "boostbox.boostbox";
}
];
};
});
};
}