-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
236 lines (214 loc) · 7.47 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
# This is based on the nix-installer flake.nix.
# I'm no Nix expert, please let me know how this could be improved.
{
description = "The Nixsa standalone nix tarball";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz";
fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1.1584.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
nix = {
url = "github:NixOs/nix/2.25.2";
};
};
outputs =
{ self
, nixpkgs
, fenix
, naersk
, nix
}:
let
version = (builtins.fromTOML (builtins.readFile nixsa-bin/Cargo.toml)).package.version;
supportedSystems = [ "i686-linux" "x86_64-linux" "aarch64-linux" ];
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;
};
fenixToolchain = system: with fenix.packages.${system};
combine ([
stable.clippy
stable.rustc
stable.cargo
stable.rustfmt
stable.rust-src
] ++ nixpkgs.lib.optionals (system == "x86_64-linux") [
targets.x86_64-unknown-linux-musl.stable.rust-std
] ++ nixpkgs.lib.optionals (system == "i686-linux") [
targets.i686-unknown-linux-musl.stable.rust-std
] ++ nixpkgs.lib.optionals (system == "aarch64-linux") [
targets.aarch64-unknown-linux-musl.stable.rust-std
]);
in
{
overlays.default = final: prev:
let
toolchain = fenixToolchain final.stdenv.system;
naerskLib = final.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
sharedAttrs = {
name = "nixsa-bin";
inherit version;
src = builtins.path {
name = "nixsa-bin-source";
path = ./nixsa-bin;
filter = (path: type: baseNameOf path != "nix" && baseNameOf path != ".github");
};
nativeBuildInputs = [ ];
doCheck = true;
cargoTestOptions = f: f ++ [ "--all" ];
override = { preBuild ? "", ... }: {
preBuild = preBuild + ''
# logRun "cargo clippy --all-targets --all-features -- -D warnings"
'';
};
};
in
{
nixsa-bin = naerskLib.buildPackage sharedAttrs;
} // nixpkgs.lib.optionalAttrs (prev.stdenv.system == "x86_64-linux") rec {
default = nixsa-bin-static;
nixsa-bin-static = naerskLib.buildPackage
(sharedAttrs // {
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
});
} // nixpkgs.lib.optionalAttrs (prev.stdenv.system == "i686-linux") rec {
default = nixsa-bin-static;
nixsa-bin-static = naerskLib.buildPackage
(sharedAttrs // {
CARGO_BUILD_TARGET = "i686-unknown-linux-musl";
});
} // nixpkgs.lib.optionalAttrs (prev.stdenv.system == "aarch64-linux") rec {
default = nixsa-bin-static;
nixsa-bin-static = naerskLib.buildPackage
(sharedAttrs // {
CARGO_BUILD_TARGET = "aarch64-unknown-linux-musl";
});
};
devShells = forAllSystems ({ system, pkgs, ... }:
let
toolchain = fenixToolchain system;
check = import ./nix/check.nix { inherit pkgs toolchain; };
in
{
default = pkgs.mkShell {
name = "nixsa-shell";
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
nativeBuildInputs = [ ];
buildInputs = [
toolchain
pkgs.rust-analyzer
pkgs.cacert
pkgs.cargo-outdated
pkgs.cargo-audit
pkgs.cargo-watch
pkgs.nixpkgs-fmt
check.check-rustfmt
check.check-spelling
check.check-nixpkgs-fmt
check.check-editorconfig
check.check-semver
check.check-clippy
];
};
});
checks = forAllSystems ({ system, pkgs, ... }:
let
toolchain = fenixToolchain system;
check = import ./nix/check.nix { inherit pkgs toolchain; };
in
{
check-rustfmt = pkgs.runCommand "check-rustfmt" { buildInputs = [ check.check-rustfmt ]; } ''
cd ${./nixsa-bin}
check-rustfmt
touch $out
'';
check-spelling = pkgs.runCommand "check-spelling" { buildInputs = [ check.check-spelling ]; } ''
cd ${./nixsa-bin}
check-spelling
touch $out
'';
check-nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt" { buildInputs = [ check.check-nixpkgs-fmt ]; } ''
cd ${./nixsa-bin}
check-nixpkgs-fmt
touch $out
'';
check-editorconfig = pkgs.runCommand "check-editorconfig" { buildInputs = [ pkgs.git check.check-editorconfig ]; } ''
cd ${./nixsa-bin}
check-editorconfig
touch $out
'';
check-ruff = pkgs.runCommand "check-ruff" { buildInputs = [ check.check-ruff ]; } ''
cd ${./nixsa-build}
check-ruff
touch $out
'';
});
packages = forAllSystems
({ system, pkgs, ... }:
rec {
inherit (pkgs) nixsa-bin nixsa-bin-static;
closureInfo = pkgs.buildPackages.closureInfo {
rootPaths = [
nix.packages."${system}".nix
nix.inputs.nixpkgs.legacyPackages."${system}".cacert
nixsa-bin-static
];
};
nixsa-dir = pkgs.stdenv.mkDerivation {
pname = "nixsa-dir";
inherit version;
src = ./nixsa-build;
buildInputs = [ pkgs.python3 pkgs.bubblewrap ];
buildPhase = ''
set -x
python3 nixsa_build.py ${closureInfo} output
set +x
'';
installPhase = ''
cp -a output $out
'';
};
nixsa-tarball = pkgs.stdenv.mkDerivation {
pname = "nixsa-tarball";
inherit version;
src = ./nixsa-build;
buildInputs = [ pkgs.xz ];
buildPhase = ''
dir=nixsa
fn=nixsa-${version}-${system}.tar.xz
mkdir $dir
cp -a ${nixsa-dir}/* $dir/
chmod -R u+w $dir
chmod -R u-w $dir/nix/store/*
tar -cvJf $fn --owner=0 --group=0 --mtime='1970-01-01' --absolute-names --hard-dereference $dir
'';
installPhase = ''
mkdir $out
cp $fn $out/
'';
};
default = nixsa-tarball;
});
# hydraJobs = {
# vm-test = import ./nix/tests/vm-test {
# inherit forSystem;
# inherit (nixpkgs) lib;
# binaryTarball = nix.tarballs_indirect;
# };
# container-test = import ./nix/tests/container-test {
# inherit forSystem;
# binaryTarball = nix.tarballs_indirect;
# };
# };
};
}