-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathflake.nix
More file actions
195 lines (164 loc) · 5.27 KB
/
flake.nix
File metadata and controls
195 lines (164 loc) · 5.27 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
{
description = "GitHub Actions-powered Nix binary cache";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
crane.url = "https://flakehub.com/f/ipetkov/crane/*";
fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1";
inputs.nixpkgs.follows = "nixpkgs";
};
nix.url = "https://flakehub.com/f/DeterminateSystems/nix-src/=3.16.3";
};
outputs =
inputs:
let
supportedSystems = [
"aarch64-linux"
"x86_64-linux"
"aarch64-darwin"
];
forEachSupportedSystem =
f:
inputs.nixpkgs.lib.genAttrs supportedSystems (
system:
f rec {
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
];
};
inherit system;
}
);
fenixToolchain =
system:
with inputs.fenix.packages.${system};
combine (
[
stable.clippy
stable.rustc
stable.cargo
stable.rustfmt
stable.rust-src
]
++ inputs.nixpkgs.lib.optionals (system == "x86_64-linux") [
targets.x86_64-unknown-linux-musl.stable.rust-std
]
++ inputs.nixpkgs.lib.optionals (system == "aarch64-linux") [
targets.aarch64-unknown-linux-musl.stable.rust-std
]
);
in
{
packages = forEachSupportedSystem (
{ pkgs, system, ... }:
let
pkgs' = pkgs.pkgsStatic;
toolchain = fenixToolchain system;
craneLib = (inputs.crane.mkLib pkgs').overrideToolchain (_: toolchain);
crateName = craneLib.crateNameFromCargoToml {
cargoToml = ./magic-nix-cache/Cargo.toml;
};
rustTargetSpec = pkgs'.stdenv.hostPlatform.rust.rustcTargetSpec;
rustTargetSpecEnv = pkgs'.lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] rustTargetSpec);
commonArgs = {
inherit (crateName) pname version;
src = inputs.self;
depsBuildBuild = with pkgs'; [
buildPackages.stdenv.cc
lld
];
nativeBuildInputs = with pkgs'; [
pkg-config
protobuf
];
buildInputs = [
inputs.nix.packages.${system}.nix-util-static
inputs.nix.packages.${system}.nix-store-static
inputs.nix.packages.${system}.nix-main-static
inputs.nix.packages.${system}.nix-expr-static
pkgs'.boost
];
doIncludeCrossToolchainEnv = false;
env.CARGO_BUILD_TARGET = rustTargetSpec;
env."CARGO_TARGET_${rustTargetSpecEnv}_LINKER" = "${pkgs'.stdenv.cc.targetPrefix}cc";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
rec {
magic-nix-cache = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
}
);
default = magic-nix-cache;
veryLongChain =
let
ctx = ./README.md;
# Function to write the current date to a file
startFile = pkgs.stdenv.mkDerivation {
name = "start-file";
buildCommand = ''
cat ${ctx} > $out
'';
};
# Recursive function to create a chain of derivations
createChain =
n: startFile:
pkgs.stdenv.mkDerivation {
name = "chain-${toString n}";
src = if n == 0 then startFile else createChain (n - 1) startFile;
buildCommand = ''
echo $src > $out
'';
};
in
# Starting point of the chain
createChain 200 startFile;
}
);
devShells = forEachSupportedSystem (
{ system, pkgs }:
let
toolchain = fenixToolchain system;
pkgs' = if pkgs.stdenv.isDarwin then pkgs else pkgs.pkgsStatic;
rustTargetSpec = pkgs'.stdenv.hostPlatform.rust.rustcTargetSpec;
rustTargetSpecEnv = pkgs'.lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] rustTargetSpec);
in
{
default = pkgs'.mkShell {
env = {
CARGO_BUILD_TARGET = rustTargetSpec;
"CARGO_TARGET_${rustTargetSpecEnv}_LINKER" = "${pkgs'.stdenv.cc.targetPrefix}cc";
};
inputsFrom = [ inputs.self.packages.${system}.default ];
depsBuildBuild = with pkgs; [
buildPackages.stdenv.cc # for linking crates in the build environment
lld
];
packages =
with pkgs;
[
toolchain
bashInteractive
cargo
rustfmt
rust-analyzer
protobuf # for protoc/prost
cargo-bloat
cargo-edit
cargo-udeps
cargo-watch
bacon
age
]
++ (with pkgs'; [
rustc
clippy
]);
};
}
);
};
}