Skip to content

Commit 91a976b

Browse files
authored
nix: Pin cargo-about to 0.8.2 (#44901)
`cargo-about` got pinned to 0.8.2 in #44012, but this isn't exactly "easy" to accomplish in nix. The version of nixpkgs in the flake inputs uses the proper version, but if you override the nixpkgs input or use the provided overlay, you might end up trying to build with a bad version of `cargo-about`. Since nixpkgs is versioned as a whole, your options are (in rough order of desirability): 1. Hope that nixpkgs simply includes multiple versions of the same package (common for things with stable major versions/breaking changes) 1. Use either `override` or `overrideAttrs` to provide different version/source attributes 1. Depend on multiple versions of nixpkgs to get the specific versions of the packages you want 1. Vendor the whole package build from a specific point in its history Option 1 is out - there's only one version of cargo-about in nixpkgs. Option 2 doesn't seem to work due to the way that `buildRustPackage` wraps the base `mkDerivation` which provides the `override` extension functions. There *might* be a way to make this work, but I haven't dug into the `buildRustPackage` internals enough to say for sure. Edit: I apparently can't read and the problems with this option were already solved for `cargo-bundle`, so this is the final approach! Option 3 always just feels a bit icky and opaque to me. Leaving Option 4. I usually find this approach to be "fine" for small package definitions that aren't actually much bigger than the overridden attributes would have be with the Option 2 approach. ~~Since the `cargo-about` definition is nice and small, this is the approach I chose.~~ ~~Since this has the potential to require a build of `cargo-about`, I'm only actually invoking its build if the provided version is wrong - more or less the same thing that's happening in the `generate-licenses` script, but nix-y.~~ Edit: Shouldn't ever cause a rebuild since there's only one 0.8.2 input source/vendored deps, so anything that was already using it will already be cached. I'm also updating nixpkgs to the latest unstable which currently has `cargo-about 0.8.4` to prove that this works. Unrelatedly, I also ran `nix fmt` as a drive-by change. `nix/build.nix` was a bit out of spec. Release Notes: - N/A
1 parent e4029c1 commit 91a976b

File tree

2 files changed

+100
-77
lines changed

2 files changed

+100
-77
lines changed

flake.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/build.nix

Lines changed: 96 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -83,70 +83,94 @@ let
8383

8484
cargoLock = ../Cargo.lock;
8585

86-
nativeBuildInputs =
87-
[
88-
cmake
89-
copyDesktopItems
90-
curl
91-
perl
92-
pkg-config
93-
protobuf
94-
cargo-about
95-
rustPlatform.bindgenHook
96-
]
97-
++ lib.optionals stdenv'.hostPlatform.isLinux [ makeWrapper ]
98-
++ lib.optionals stdenv'.hostPlatform.isDarwin [
99-
(cargo-bundle.overrideAttrs (
100-
new: old: {
101-
version = "0.6.1-zed";
102-
src = fetchFromGitHub {
103-
owner = "zed-industries";
104-
repo = "cargo-bundle";
105-
rev = "2be2669972dff3ddd4daf89a2cb29d2d06cad7c7";
106-
hash = "sha256-cSvW0ND148AGdIGWg/ku0yIacVgW+9f1Nsi+kAQxVrI=";
107-
};
108-
cargoHash = "sha256-urn+A3yuw2uAO4HGmvQnKvWtHqvG9KHxNCCWTiytE4k=";
109-
110-
# NOTE: can drop once upstream uses `finalAttrs` here:
111-
# https://github.com/NixOS/nixpkgs/blob/10214747f5e6e7cb5b9bdf9e018a3c7b3032f5af/pkgs/build-support/rust/build-rust-package/default.nix#L104
112-
#
113-
# See (for context): https://github.com/NixOS/nixpkgs/pull/382550
114-
cargoDeps = rustPlatform.fetchCargoVendor {
115-
inherit (new) src;
116-
hash = new.cargoHash;
117-
patches = new.cargoPatches or [];
118-
name = new.cargoDepsName or new.finalPackage.name;
119-
};
120-
}
121-
))
122-
];
123-
124-
buildInputs =
125-
[
126-
curl
127-
fontconfig
128-
freetype
129-
# TODO: need staticlib of this for linking the musl remote server.
130-
# should make it a separate derivation/flake output
131-
# see https://crane.dev/examples/cross-musl.html
132-
libgit2
133-
openssl
134-
sqlite
135-
zlib
136-
zstd
137-
]
138-
++ lib.optionals stdenv'.hostPlatform.isLinux [
139-
alsa-lib
140-
libxkbcommon
141-
wayland
142-
gpu-lib
143-
xorg.libX11
144-
xorg.libxcb
145-
]
146-
++ lib.optionals stdenv'.hostPlatform.isDarwin [
147-
apple-sdk_15
148-
(darwinMinVersionHook "10.15")
149-
];
86+
nativeBuildInputs = [
87+
cmake
88+
copyDesktopItems
89+
curl
90+
perl
91+
pkg-config
92+
protobuf
93+
# Pin cargo-about to 0.8.2. Newer versions don't work with the current license identifiers
94+
# See https://github.com/zed-industries/zed/pull/44012
95+
(cargo-about.overrideAttrs (
96+
new: old: rec {
97+
version = "0.8.2";
98+
99+
src = fetchFromGitHub {
100+
owner = "EmbarkStudios";
101+
repo = "cargo-about";
102+
tag = version;
103+
sha256 = "sha256-cNKZpDlfqEXeOE5lmu79AcKOawkPpk4PQCsBzNtIEbs=";
104+
};
105+
106+
cargoHash = "sha256-NnocSs6UkuF/mCM3lIdFk+r51Iz2bHuYzMT/gEbT/nk=";
107+
108+
# NOTE: can drop once upstream uses `finalAttrs` here:
109+
# https://github.com/NixOS/nixpkgs/blob/10214747f5e6e7cb5b9bdf9e018a3c7b3032f5af/pkgs/build-support/rust/build-rust-package/default.nix#L104
110+
#
111+
# See (for context): https://github.com/NixOS/nixpkgs/pull/382550
112+
cargoDeps = rustPlatform.fetchCargoVendor {
113+
inherit (new) src;
114+
hash = new.cargoHash;
115+
patches = new.cargoPatches or [ ];
116+
name = new.cargoDepsName or new.finalPackage.name;
117+
};
118+
}
119+
))
120+
rustPlatform.bindgenHook
121+
]
122+
++ lib.optionals stdenv'.hostPlatform.isLinux [ makeWrapper ]
123+
++ lib.optionals stdenv'.hostPlatform.isDarwin [
124+
(cargo-bundle.overrideAttrs (
125+
new: old: {
126+
version = "0.6.1-zed";
127+
src = fetchFromGitHub {
128+
owner = "zed-industries";
129+
repo = "cargo-bundle";
130+
rev = "2be2669972dff3ddd4daf89a2cb29d2d06cad7c7";
131+
hash = "sha256-cSvW0ND148AGdIGWg/ku0yIacVgW+9f1Nsi+kAQxVrI=";
132+
};
133+
cargoHash = "sha256-urn+A3yuw2uAO4HGmvQnKvWtHqvG9KHxNCCWTiytE4k=";
134+
135+
# NOTE: can drop once upstream uses `finalAttrs` here:
136+
# https://github.com/NixOS/nixpkgs/blob/10214747f5e6e7cb5b9bdf9e018a3c7b3032f5af/pkgs/build-support/rust/build-rust-package/default.nix#L104
137+
#
138+
# See (for context): https://github.com/NixOS/nixpkgs/pull/382550
139+
cargoDeps = rustPlatform.fetchCargoVendor {
140+
inherit (new) src;
141+
hash = new.cargoHash;
142+
patches = new.cargoPatches or [ ];
143+
name = new.cargoDepsName or new.finalPackage.name;
144+
};
145+
}
146+
))
147+
];
148+
149+
buildInputs = [
150+
curl
151+
fontconfig
152+
freetype
153+
# TODO: need staticlib of this for linking the musl remote server.
154+
# should make it a separate derivation/flake output
155+
# see https://crane.dev/examples/cross-musl.html
156+
libgit2
157+
openssl
158+
sqlite
159+
zlib
160+
zstd
161+
]
162+
++ lib.optionals stdenv'.hostPlatform.isLinux [
163+
alsa-lib
164+
libxkbcommon
165+
wayland
166+
gpu-lib
167+
xorg.libX11
168+
xorg.libxcb
169+
]
170+
++ lib.optionals stdenv'.hostPlatform.isDarwin [
171+
apple-sdk_15
172+
(darwinMinVersionHook "10.15")
173+
];
150174

151175
cargoExtraArgs = "-p zed -p cli --locked --features=gpui/runtime_shaders";
152176

@@ -177,7 +201,7 @@ let
177201
ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled.";
178202
RELEASE_VERSION = version;
179203
LK_CUSTOM_WEBRTC = livekit-libwebrtc;
180-
PROTOC="${protobuf}/bin/protoc";
204+
PROTOC = "${protobuf}/bin/protoc";
181205

182206
CARGO_PROFILE = profile;
183207
# need to handle some profiles specially https://github.com/rust-lang/cargo/issues/11053
@@ -217,14 +241,13 @@ let
217241
# `webrtc-sys` expects a staticlib; nixpkgs' `livekit-webrtc` has been patched to
218242
# produce a `dylib`... patching `webrtc-sys`'s build script is the easier option
219243
# TODO: send livekit sdk a PR to make this configurable
220-
postPatch =
221-
''
222-
substituteInPlace webrtc-sys/build.rs --replace-fail \
223-
"cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc"
224-
''
225-
+ lib.optionalString withGLES ''
226-
cat ${glesConfig} >> .cargo/config/config.toml
227-
'';
244+
postPatch = ''
245+
substituteInPlace webrtc-sys/build.rs --replace-fail \
246+
"cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc"
247+
''
248+
+ lib.optionalString withGLES ''
249+
cat ${glesConfig} >> .cargo/config/config.toml
250+
'';
228251
in
229252
crates: drv:
230253
if hasWebRtcSys crates then

0 commit comments

Comments
 (0)