-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathflake.nix
More file actions
250 lines (224 loc) · 7.8 KB
/
flake.nix
File metadata and controls
250 lines (224 loc) · 7.8 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
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
{
description = "The Determinate Nix Installer";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.793735";
crane.url = "github:ipetkov/crane/v0.20.0";
nix = {
url = "https://flakehub.com/f/DeterminateSystems/nix-src/*";
# Omitting `inputs.nixpkgs.follows = "nixpkgs";` on purpose
};
determinate = {
url = "https://flakehub.com/f/DeterminateSystems/determinate/*";
# We set the overrides below so the flake.lock has many fewer nodes.
#
# The `determinate` input is used to access the builds of `determinate-nixd`.
# Below, we access the `packages` outputs, which download static builds of `determinate-nixd` and makes them executable.
# The way we consume the determinate flake means the `nix` and `nixpkgs` inputs are not meaningfully used.
# This means `follows` won't cause surprisingly extensive rebuilds, just trivial `chmod +x` rebuilds.
inputs.nixpkgs.follows = "nixpkgs";
inputs.nix.follows = "nix";
};
};
outputs =
{
self,
nixpkgs,
crane,
nix,
determinate,
...
}@inputs:
let
nix_tarball_url_prefix = "https://releases.nixos.org/nix/nix-2.33.1/nix-2.33.1-";
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
systemsSupportedByDeterminateNixd = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: (forSystem system f));
forSystem =
system: f:
f rec {
inherit system;
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
lib = pkgs.lib;
};
nixTarballs = forAllSystems (
{ system, ... }:
inputs.nix.tarballs_direct.${system} or "${inputs.nix.packages."${system}".binaryTarball}/nix-${
inputs.nix.packages."${system}".default.version
}-${system}.tar.xz"
);
optionalPathToDeterminateNixd =
system:
if builtins.elem system systemsSupportedByDeterminateNixd then
"${inputs.determinate.packages.${system}.default}/bin/determinate-nixd"
else
null;
installerPackage =
{
pkgs,
stdenv,
buildPackages,
}:
let
craneLib = crane.mkLib pkgs;
sharedAttrs = {
src = builtins.path {
name = "nix-installer-source";
path = self;
filter = (path: type: baseNameOf path != "nix" && baseNameOf path != ".github");
};
# Required to link build scripts.
depsBuildBuild = [ buildPackages.stdenv.cc ];
env = {
# For whatever reason, these don’t seem to get set
# automatically when using crane.
#
# Possibly related: <https://github.com/NixOS/nixpkgs/pull/369424>
"CC_${stdenv.hostPlatform.rust.cargoEnvVarTarget}" = "${stdenv.cc.targetPrefix}cc";
"CXX_${stdenv.hostPlatform.rust.cargoEnvVarTarget}" = "${stdenv.cc.targetPrefix}c++";
"CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" = "${stdenv.cc.targetPrefix}cc";
CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.rustcTarget;
};
};
in
craneLib.buildPackage (
sharedAttrs
// {
cargoArtifacts = craneLib.buildDepsOnly sharedAttrs;
cargoTestExtraArgs = "--all";
postInstall = ''
cp nix-installer.sh $out/bin/nix-installer.sh
'';
env = sharedAttrs.env // {
RUSTFLAGS = "--cfg tokio_unstable";
NIX_TARBALL_URL = "${nix_tarball_url_prefix}${pkgs.stdenv.hostPlatform.system}.tar.xz";
DETERMINATE_NIX_TARBALL_PATH = nixTarballs.${stdenv.hostPlatform.system};
DETERMINATE_NIXD_BINARY_PATH = optionalPathToDeterminateNixd stdenv.hostPlatform.system;
};
}
);
in
{
overlays.default = final: prev: {
nix-installer = final.callPackage installerPackage { };
nix-installer-static = final.pkgsStatic.callPackage installerPackage { };
};
devShells = forAllSystems (
{ system, pkgs, ... }:
let
check = import ./nix/check.nix { inherit pkgs; };
in
{
default = pkgs.mkShell {
name = "nix-install-shell";
RUST_SRC_PATH = "${pkgs.rustPlatform.rustcSrc}/library";
NIX_TARBALL_URL = "${nix_tarball_url_prefix}${pkgs.stdenv.hostPlatform.system}.tar.xz";
DETERMINATE_NIX_TARBALL_PATH = nixTarballs.${system};
DETERMINATE_NIXD_BINARY_PATH = optionalPathToDeterminateNixd system;
nativeBuildInputs = with pkgs; [ ];
buildInputs =
with pkgs;
[
rustc
cargo
clippy
rustfmt
shellcheck
rust-analyzer
cargo-outdated
cacert
# cargo-audit # NOTE(cole-h): build currently broken because of time dependency and Rust 1.80
cargo-watch
check.check-rustfmt
check.check-spelling
check.check-nixfmt
check.check-editorconfig
check.check-semver
check.check-clippy
editorconfig-checker
toml-cli
self.formatter.${system}
]
++ lib.optionals (pkgs.stdenv.isLinux) (
with pkgs;
[
checkpolicy
semodule-utils
# users are expected to have a system docker, too
]
);
};
}
);
checks = forAllSystems (
{ system, pkgs, ... }:
let
check = import ./nix/check.nix { inherit pkgs; };
in
{
check-rustfmt = pkgs.runCommand "check-rustfmt" { buildInputs = [ check.check-rustfmt ]; } ''
cd ${./.}
check-rustfmt
touch $out
'';
check-spelling = pkgs.runCommand "check-spelling" { buildInputs = [ check.check-spelling ]; } ''
cd ${./.}
check-spelling
touch $out
'';
check-nixfmt = pkgs.runCommand "check-nixfmt" { buildInputs = [ check.check-nixfmt ]; } ''
cd ${./.}
check-nixfmt
touch $out
'';
check-editorconfig =
pkgs.runCommand "check-editorconfig"
{
buildInputs = [
pkgs.git
check.check-editorconfig
];
}
''
cd ${./.}
check-editorconfig
touch $out
'';
}
);
formatter = forAllSystems ({ pkgs, ... }: pkgs.nixfmt);
packages = forAllSystems (
{ system, pkgs, ... }:
{
inherit (pkgs) nix-installer nix-installer-static;
default = pkgs.nix-installer-static;
}
// nixpkgs.lib.optionalAttrs (pkgs.stdenv.isDarwin) {
determinate-nixd = pkgs.runCommand "determinate-nixd-link" { } ''
ln -s ${optionalPathToDeterminateNixd system} $out
'';
}
);
hydraJobs = {
vm-test = import ./nix/tests/vm-test {
inherit forSystem;
inherit (nixpkgs) lib;
binaryTarball = nix.hydraJobs.binaryTarball;
};
container-test = import ./nix/tests/container-test {
inherit forSystem;
binaryTarball = nix.hydraJobs.binaryTarball;
};
};
};
}