/
flake.nix
264 lines (230 loc) · 8.37 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# ============================================================================ #
#
# A cross-platform environment manager with sharing as a service.
#
# ---------------------------------------------------------------------------- #
{
description = "flox - Harness the power of Nix";
nixConfig.extra-substituters = [
"https://cache.flox.dev"
];
nixConfig.extra-trusted-public-keys = [
"flox-cache-public-1:7F4OyH7ZCnFhcze3fJdfyXYLQw/aV7GEed86nQ7IsOs="
];
inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
# drop once bear is no longer broken in a newer release
inputs.nixpkgs-bear.url = "github:NixOS/nixpkgs/release-23.05";
inputs.sqlite3pp.url = "github:aakropotkin/sqlite3pp";
inputs.sqlite3pp.inputs.nixpkgs.follows = "nixpkgs";
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
inputs.crane.url = "github:ipetkov/crane";
inputs.crane.inputs.nixpkgs.follows = "nixpkgs";
inputs.fenix.url = "github:nix-community/fenix";
inputs.fenix.inputs.nixpkgs.follows = "nixpkgs";
# -------------------------------------------------------------------------- #
outputs = {
self,
nixpkgs,
sqlite3pp,
pre-commit-hooks,
crane,
fenix,
...
} @ inputs: let
# Given a function `fn' which takes system names as an argument, produce an
# attribute set whose keys are system names, and values are the result of
# applying that system name to `fn'.
eachDefaultSystemMap = let
defaultSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
in
fn: let
proc = system: {
name = system;
value = fn system;
};
in
builtins.listToAttrs (map proc defaultSystems);
# ------------------------------------------------------------------------ #
# Overlays
# --------
# Add IWYU pragmas to `nlohmann_json'
# ( _include what you use_ extensions to headers for static analysis )
overlays.nlohmann = final: prev: {
nlohmann_json = final.callPackage ./pkgs/nlohmann_json {
inherit (prev) nlohmann_json;
};
};
# Use nix@2.17
overlays.nix = final: prev: {
# Uncomment to compile Nix with debug symbols on Linux
# nix = final.enableDebugging (final.callPackage ./pkgs/nix {});
nix = final.callPackage ./pkgs/nix {};
};
# Use cpp-semver
overlays.semver = final: prev: {
cpp-semver = final.callPackage ./pkgs/cpp-semver {};
};
# bear is broken in release 23.11 on darwin
overlays.bear = final: prev: {
inherit (inputs.nixpkgs-bear.legacyPackages.${prev.system}) bear;
};
# Aggregates all external dependency overlays before adding any of the
# packages defined by this flake.
overlays.deps = nixpkgs.lib.composeManyExtensions [
overlays.nlohmann
overlays.semver
overlays.nix
overlays.bear
sqlite3pp.overlays.default
fenix.overlays.default
];
# Packages defined in this repository.
overlays.flox = final: prev: let
callPackage = final.lib.callPackageWith (final
// {
inherit inputs self;
pkgsFor = final;
});
# We depend on several nightly features of rustfmt,
# so pick the current nightly version.
# We're using `default.withComponents`
# which _should_ only pull the nightly rustfmt component.
# Alternatively, we could use nixpkgs.rustfmt,
# and rebuild with a (stable) fenix toolchain and `asNightly = true`,
# which would avoid the need to pull another channel altogether.
rustfmt-nightly = final.fenix.default.withComponents ["rustfmt"];
rust-toolchain = final.fenix.stable;
in {
# Generates a `.git/hooks/pre-commit' script.
pre-commit-check = pre-commit-hooks.lib.${final.system}.run {
src = builtins.path {path = ./.;};
default_stages = ["manual" "push"];
hooks = {
alejandra.enable = true;
clang-format = {
enable = true;
types_or = final.lib.mkForce [
"c"
"c++"
];
};
rustfmt = let
wrapper = final.symlinkJoin {
name = "rustfmt-wrapped";
paths = [rustfmt-nightly];
nativeBuildInputs = [final.makeWrapper];
postBuild = let
# Use nightly rustfmt
PATH = final.lib.makeBinPath [final.fenix.stable.cargo rustfmt-nightly];
in ''
wrapProgram $out/bin/cargo-fmt --prefix PATH : ${PATH};
'';
};
in {
enable = true;
entry = final.lib.mkForce "${wrapper}/bin/cargo-fmt fmt --all --manifest-path 'cli/Cargo.toml' -- --color always";
};
clippy.enable = true;
commitizen.enable = true;
shfmt.enable = false;
# shellcheck.enable = true; # disabled until we have time to fix all the warnings
};
settings = {
clippy.denyWarnings = true;
alejandra.verbosity = "quiet";
rust.cargoManifestPath = "cli/Cargo.toml";
};
tools = {
# use fenix provided clippy
clippy = rust-toolchain.clippy;
clang-tools = final.clang-tools_16;
};
};
# Customized `gh' executable used for auth.
flox-gh = callPackage ./pkgs/flox-gh {};
# Package Database Utilities: scrape, search, and resolve.
flox-pkgdb = callPackage ./pkgs/flox-pkgdb {};
# Flox Command Line Interface ( development build ).
flox-cli = callPackage ./pkgs/flox-cli {
rust-toolchain = rust-toolchain;
rustfmt = rustfmt-nightly;
};
# Flox Command Line Interface Manpages
flox-manpages = callPackage ./pkgs/flox-manpages {};
# Flox Command Line Interface ( production build ).
flox = callPackage ./pkgs/flox {};
# Wrapper scripts for running test suites.
flox-cli-tests = callPackage ./pkgs/flox-cli-tests {};
# Integration tests
flox-tests = callPackage ./pkgs/flox-tests {};
flox-tests-pure = callPackage ./pkgs/flox-tests-pure {inputs = inputs;};
};
# Composes dependency overlays and the overlay defined here.
overlays.default =
nixpkgs.lib.composeExtensions overlays.deps
overlays.flox;
# ------------------------------------------------------------------------ #
# Apply overlays to the `nixpkgs` _base_ set.
# This is exposed as an output later; but we don't use the name
# `legacyPackages' to avoid checking the full closure with
# `nix flake check' and `nix search'.
pkgsFor = eachDefaultSystemMap (system: let
base = builtins.getAttr system nixpkgs.legacyPackages;
in
base.extend overlays.default);
# ------------------------------------------------------------------------ #
checks = eachDefaultSystemMap (system: let
pkgs = builtins.getAttr system pkgsFor;
in {
inherit (pkgs) pre-commit-check;
});
# ------------------------------------------------------------------------ #
packages = eachDefaultSystemMap (system: let
pkgs = builtins.getAttr system pkgsFor;
in {
inherit
(pkgs)
flox-gh
flox-pkgdb
flox-cli
flox-cli-tests
flox-manpages
flox
pre-commit-check
flox-tests-pure
;
default = pkgs.flox;
});
# ------------------------------------------------------------------------ #
in {
inherit overlays packages pkgsFor checks;
devShells = eachDefaultSystemMap (system: let
pkgsBase = builtins.getAttr system pkgsFor;
pkgs = pkgsBase.extend (final: prev: {
flox-cli-tests = prev.flox-cli-tests.override {
PROJECT_TESTS_DIR = "/cli/tests";
PKGDB_BIN = null;
FLOX_BIN = null;
};
flox-tests = prev.flox-tests.override {
PROJECT_TESTS_DIR = "/tests";
PKGDB_BIN = null;
FLOX_BIN = null;
};
flox-cli = prev.flox-cli.override {flox-pkgdb = null;};
});
checksFor = builtins.getAttr system checks;
in {
default = pkgs.callPackage ./shells/default {
inherit (checksFor) pre-commit-check;
};
});
}; # End `outputs'
# -------------------------------------------------------------------------- #
}