-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.nix
More file actions
203 lines (185 loc) · 6.54 KB
/
Copy pathdefault.nix
File metadata and controls
203 lines (185 loc) · 6.54 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
{
# Pin nixpkgs so nix-build works without '-I nixpkgs=…' or channels.
# Linux builds target glibc 2.34 (Rocky Linux 9 compatibility).
pkgs ?
let
rustOverlay = import (
builtins.fetchTarball {
url = "https://github.com/oxalica/rust-overlay/archive/a313afc75b85fc77ac154bf0e62c36f68361fd0b.tar.gz";
sha256 = "0fb18ysw2dgm3033kcv3nlhsihckssnq6j5ayq4zjq148f12m7yv";
}
);
nixpkgsSrc = builtins.fetchTarball {
url = "https://package.cosmian.com/nixpkgs/8b27c1239e5c421a2bbc2c65d52e4a6fbf2ff296.tar.gz";
sha256 = "sha256-CqCX4JG7UiHvkrBTpYC3wcEurvbtTADLbo3Ns2CEoL8=";
};
in
import nixpkgsSrc {
overlays = [ rustOverlay ];
config.allowUnfree = true;
},
}:
let
# Pinned nixpkgs tarball (same commit as above)
nixpkgsSrc = builtins.fetchTarball {
url = "https://package.cosmian.com/nixpkgs/8b27c1239e5c421a2bbc2c65d52e4a6fbf2ff296.tar.gz";
sha256 = "sha256-CqCX4JG7UiHvkrBTpYC3wcEurvbtTADLbo3Ns2CEoL8=";
};
# Modern Rust toolchain via rust-overlay (pinned to commit a313afc, includes Rust 1.94.1)
rustOverlay = import (
builtins.fetchTarball {
url = "https://github.com/oxalica/rust-overlay/archive/a313afc75b85fc77ac154bf0e62c36f68361fd0b.tar.gz";
sha256 = "0fb18ysw2dgm3033kcv3nlhsihckssnq6j5ayq4zjq148f12m7yv";
}
);
pkgsWithRust = import nixpkgsSrc {
overlays = [ rustOverlay ];
config.allowUnfree = true;
};
# Latest stable Rust toolchain from the pinned overlay (currently 1.94.1).
# Using 'latest' ensures we always use the most recent stable in the pinned overlay.
rustToolchain = pkgsWithRust.rust-bin.stable.latest.minimal.override {
extensions = [
"rustfmt"
"clippy"
];
};
# For Linux, pin nixpkgs 22.05 (glibc 2.34) for Rocky Linux 9 compatibility.
pkgs234 =
if pkgs.stdenv.isLinux then
import (builtins.fetchTarball {
url = "https://package.cosmian.com/nixpkgs/380be19fbd2d9079f677978361792cb25e8a3635.tar.gz";
sha256 = "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=";
}) { config.allowUnfree = true; }
else
pkgs;
# pkgs234.makeRustPlatform (nixpkgs 22.05) has two bugs for git deps with
# workspace inheritance (version.workspace = true, added in Cargo 1.64):
#
# Bug 1: import-cargo-lock.nix is called with `{}` (no cargo override), so it
# uses buildPackages.cargo (= cargo-1.60.0) which can't parse workspace syntax.
# Fix: extend pkgs234 to set cargo = rustToolchain so buildPackages.cargo is modern.
#
# Bug 2: pkgs234's import-cargo-lock.nix is missing the replace-workspace-values.py
# step, so workspace inheritance keys remain in vendored Cargo.toml files.
# Fix: use the modern importCargoLock from pkgsWithRust which has this step,
# and inject it into the pkgs234-based rustPlatform.buildRustPackage.
pkgs234Fixed =
if pkgs.stdenv.isLinux then
pkgs234.extend (_: _: { cargo = rustToolchain; })
else
pkgs234;
# Modern importCargoLock (from pkgsWithRust) that supports workspace inheritance
# via replace-workspace-values.py. Used to override the missing step in pkgs234.
importCargoLockModern =
(pkgsWithRust.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
}).importCargoLock;
# rustPlatform: on Linux use pkgs234Fixed (glibc 2.34) with modern importCargoLock
rustPlatform =
if pkgs.stdenv.isLinux then
let
base = pkgs234Fixed.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
in
base // {
buildRustPackage = base.buildRustPackage.override {
importCargoLock = importCargoLockModern;
};
}
else
pkgsWithRust.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
# Extract version from workspace Cargo.toml
cargoTomlContent = builtins.readFile ./Cargo.toml;
lines = pkgs.lib.splitString "\n" cargoTomlContent;
extractVersion =
lines:
let
findWorkspacePackage =
idx:
if idx >= builtins.length lines then
null
else if pkgs.lib.hasPrefix "[workspace.package]" (builtins.elemAt lines idx) then
idx
else
findWorkspacePackage (idx + 1);
workspaceIdx = findWorkspacePackage 0;
findVersion =
idx:
if idx >= builtins.length lines || workspaceIdx == null then
null
else
let
line = builtins.elemAt lines idx;
isNextSection = pkgs.lib.hasPrefix "[" line && idx > workspaceIdx;
in
if isNextSection then
null
else if pkgs.lib.hasPrefix "version" (pkgs.lib.replaceStrings [ " " "\t" ] [ "" "" ] line) then
builtins.elemAt (pkgs.lib.splitString "\"" line) 1
else
findVersion (idx + 1);
in
if workspaceIdx == null then
throw "Could not find [workspace.package] in Cargo.toml"
else
let
ver = findVersion (workspaceIdx + 1);
in
if ver == null then throw "Could not find version in [workspace.package] section" else ver;
authVersion = extractVersion lines;
# Build cargo-generate-rpm from crates.io (not available in all pinned nixpkgs)
cargoGenerateRpmTool = rustPlatform.buildRustPackage rec {
pname = "cargo-generate-rpm";
version = "0.16.0";
src = pkgs.fetchCrate {
inherit pname version;
sha256 = "sha256-esp3MJ24RQpMFn9zPgccp7NESoFAUPU7y+YRsJBVVr4=";
};
cargoSha256 = "sha256-mUsoPBgv60Eir/uIK+Xe+GmXdSFKXoopB4PlvFvHZuA=";
nativeBuildInputs = [
rustToolchain
pkgs.pkg-config
pkgs.git
pkgs.cacert
];
doCheck = false;
};
# Build auth-server for static linkage
auth-server-static = pkgs.callPackage ./nix/auth-server.nix {
inherit pkgs pkgs234 rustPlatform;
version = authVersion;
static = true;
};
# Build auth-server for dynamic linkage
auth-server-dynamic = pkgs.callPackage ./nix/auth-server.nix {
inherit pkgs pkgs234 rustPlatform;
version = authVersion;
static = false;
};
# Docker image derivation (Linux only)
docker-image = pkgs.callPackage ./nix/docker.nix {
inherit pkgs;
authServer = auth-server-static;
version = authVersion;
};
in
{
# Build attributes accessible via -A
inherit
auth-server-static
auth-server-dynamic
docker-image
cargoGenerateRpmTool
rustToolchain
;
# Convenience aliases used by packaging scripts
"auth-server-static-openssl" = auth-server-static;
"auth-server-dynamic-openssl" = auth-server-dynamic;
}