Skip to content

Commit 905e99a

Browse files
authored
feat(build): add Nix-native Linux toolchains (#2875)
* feat(nix): add glibc 2.28 development shell * feat(nix): add musl development shell * feat(build): use mold in musl development shell * feat(flake): add nix remote cache * feat(build): use mold in default development shell
1 parent 7fc6138 commit 905e99a

9 files changed

Lines changed: 312 additions & 27 deletions

File tree

Cargo.lock

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

flake.lock

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

flake.nix

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
{
55
description = "OpenShell development environment";
66

7+
nixConfig = {
8+
extra-substituters = [ "https://openshell.cachix.org" ];
9+
extra-trusted-public-keys = [
10+
"openshell.cachix.org-1:OAr5MunsfH5PZvUsfD08OtGx5RtcwdNZGJdU5FqLm5w="
11+
];
12+
};
13+
714
inputs = {
815
flake-utils.url = "github:numtide/flake-utils";
916
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
@@ -33,34 +40,51 @@
3340
inherit system;
3441
overlays = [ (import rust-overlay) ];
3542
};
43+
commonDevShellPackages = with pkgs; [
44+
# Assemble Debian artifacts on macOS and Linux.
45+
dpkg
46+
# Required to find packages.
47+
pkg-config
48+
# Coverage.
49+
lcov
50+
];
3651
treefmtEval = treefmt-nix.lib.evalModule pkgs {
3752
projectRootFile = "flake.nix";
3853
programs.nixfmt.enable = true;
3954
};
4055
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
56+
z3-static = pkgs.callPackage ./nix/pkgs/z3-static.nix { };
57+
aws-lc-static = pkgs.callPackage ./nix/pkgs/aws-lc-static.nix { };
4158
testGuest = import ./nix/test-guest { inherit pkgs; };
4259
in
4360
{
4461
apps.test-guest = testGuest.app;
4562
apps.test-guest-cache = testGuest.cacheApp;
4663

47-
devShells.default = pkgs.mkShell {
48-
packages = with pkgs; [
49-
rustToolchain
50-
# Assemble Debian artifacts on macOS and Linux.
51-
dpkg
52-
# Required to find packages
53-
pkg-config
54-
# Required for bindgen generation.
55-
llvmPackages.libclang
56-
# system dependency for openshell-prover
57-
z3
58-
# Coverage
59-
lcov
60-
];
61-
62-
env = {
63-
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
64+
devShells = {
65+
default =
66+
(pkgs.mkShell.override {
67+
stdenv =
68+
if pkgs.stdenv.hostPlatform.isLinux then
69+
pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv
70+
else
71+
pkgs.stdenv;
72+
})
73+
{
74+
packages = [
75+
rustToolchain
76+
z3-static
77+
aws-lc-static
78+
]
79+
++ commonDevShellPackages;
80+
};
81+
}
82+
// pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
83+
glibc-2-28 = import ./nix/devShells/glibc-2-28.nix {
84+
inherit pkgs rust-overlay commonDevShellPackages;
85+
};
86+
musl = import ./nix/devShells/musl.nix {
87+
inherit pkgs rust-overlay commonDevShellPackages;
6488
};
6589
};
6690

nix/devShells/glibc-2-28.nix

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{
5+
pkgs,
6+
rust-overlay,
7+
commonDevShellPackages,
8+
}:
9+
10+
let
11+
toolchain = import ../toolchains/linux-gnu-2.28 { inherit pkgs; };
12+
z3-static = pkgs.callPackage ../pkgs/z3-static.nix {
13+
stdenv = toolchain.stdenv;
14+
};
15+
aws-lc-static = pkgs.callPackage ../pkgs/aws-lc-static.nix {
16+
stdenv = toolchain.stdenv;
17+
};
18+
rustScope = {
19+
stdenv = toolchain.stdenv;
20+
gccForLibs.lib = toolchain.sharedRuntime;
21+
pkgsTargetTarget = pkgs.pkgsTargetTarget // {
22+
stdenv = toolchain.stdenv;
23+
};
24+
};
25+
rust-bin = rust-overlay.lib.mkRustBin { } (
26+
pkgs
27+
// rustScope
28+
// {
29+
callPackage = pkgs.newScope rustScope;
30+
}
31+
);
32+
in
33+
(pkgs.mkShell.override { stdenv = toolchain.stdenv; }) {
34+
packages = [
35+
(rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml)
36+
z3-static
37+
aws-lc-static
38+
]
39+
++ commonDevShellPackages;
40+
}

nix/devShells/musl.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{
5+
pkgs,
6+
rust-overlay,
7+
commonDevShellPackages,
8+
}:
9+
10+
let
11+
muslPkgs = pkgs.pkgsMusl;
12+
stdenv = pkgs.stdenvAdapters.useMoldLinker muslPkgs.stdenv;
13+
rust-bin = rust-overlay.lib.mkRustBin { } muslPkgs;
14+
rustToolchain = (rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml).override {
15+
enableLibsecret = false;
16+
};
17+
in
18+
(muslPkgs.mkShell.override { inherit stdenv; }) {
19+
packages = [
20+
rustToolchain
21+
(muslPkgs.callPackage ../pkgs/z3-static.nix { })
22+
(muslPkgs.callPackage ../pkgs/aws-lc-static.nix {
23+
rust-bindgen = pkgs.rust-bindgen;
24+
})
25+
]
26+
++ commonDevShellPackages;
27+
}

nix/pkgs/aws-lc-static.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{
5+
aws-lc,
6+
rust-bindgen,
7+
stdenv,
8+
}:
9+
10+
aws-lc.override {
11+
inherit stdenv rust-bindgen;
12+
useSharedLibraries = false;
13+
withRustBindings = true;
14+
}

nix/pkgs/z3-static.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{ z3, stdenv }:
5+
6+
(z3.override {
7+
inherit stdenv;
8+
pythonBindings = false;
9+
}).overrideAttrs
10+
(old: {
11+
cmakeFlags = old.cmakeFlags ++ [ "-DZ3_BUILD_LIBZ3_SHARED=OFF" ];
12+
})
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{ pkgs }:
5+
6+
let
7+
glibc = pkgs.callPackage ./libc.nix { };
8+
mkStdenv =
9+
{
10+
libraryPaths ? [ ],
11+
ldflags ? null,
12+
}:
13+
let
14+
runtime = pkgs.buildEnv {
15+
name = "gcc-static-runtime";
16+
paths = libraryPaths ++ map pkgs.lib.getDev libraryPaths;
17+
pathsToLink = [
18+
"/include"
19+
"/include-cxx"
20+
"/lib"
21+
];
22+
postBuild = ''
23+
mkdir -p $out/lib
24+
find $out/lib -type l ! \( -name '*.a' -o -name 'crt*.o' \) -delete
25+
printf 'GROUP ( libgcc.a libgcc_eh.a )\n' > $out/lib/libgcc_s.a
26+
'';
27+
passthru.isGNU = true;
28+
};
29+
in
30+
pkgs.stdenvAdapters.useMoldLinker (
31+
pkgs.overrideCC pkgs.stdenv (
32+
pkgs.wrapCCWith {
33+
cc = pkgs.gccNGPackages.gcc-unwrapped.overrideAttrs (old: {
34+
configureFlags = old.configureFlags ++ [ "--disable-fixincludes" ];
35+
});
36+
bintools = pkgs.wrapBintoolsWith {
37+
bintools = pkgs.binutils-unwrapped;
38+
libc = glibc;
39+
};
40+
extraPackages = [ runtime ];
41+
libcxx = runtime;
42+
nixSupport = {
43+
cc-cflags = [
44+
"-isystem${pkgs.linuxHeaders}/include"
45+
"-static-libgcc"
46+
"-B${runtime}/lib"
47+
];
48+
}
49+
// pkgs.lib.optionalAttrs (ldflags != null) { cc-ldflags = ldflags; };
50+
}
51+
)
52+
);
53+
libgcc =
54+
(pkgs.gccNGPackages.libgcc.override {
55+
stdenv = mkStdenv { };
56+
}).overrideAttrs
57+
(old: {
58+
makeFlags = old.makeFlags ++ [ "SHLIB_LC=-lc" ];
59+
});
60+
libssp =
61+
(pkgs.gccNGPackages.libssp.override {
62+
stdenv = mkStdenv { libraryPaths = [ libgcc ]; };
63+
}).overrideAttrs
64+
{
65+
dontDisableStatic = true;
66+
};
67+
libstdcxxStdenv = mkStdenv {
68+
libraryPaths = [
69+
libgcc
70+
libssp
71+
];
72+
};
73+
libstdcxx =
74+
(pkgs.gccNGPackages.libstdcxx.override {
75+
stdenv = libstdcxxStdenv;
76+
inherit libgcc;
77+
libbacktrace = pkgs.libbacktrace.override {
78+
stdenv = libstdcxxStdenv;
79+
};
80+
}).overrideAttrs
81+
{
82+
dontDisableStatic = true;
83+
};
84+
sharedRuntime = pkgs.buildEnv {
85+
name = "gcc-shared-runtime";
86+
paths = [
87+
libgcc
88+
libstdcxx
89+
];
90+
pathsToLink = [ "/lib" ];
91+
};
92+
stdenv = mkStdenv {
93+
libraryPaths = [
94+
libgcc
95+
libssp
96+
libstdcxx
97+
];
98+
ldflags = [ "-lssp" ];
99+
};
100+
in
101+
{
102+
inherit sharedRuntime stdenv;
103+
}

0 commit comments

Comments
 (0)