Debian Codegraph @

crt/s2n/nix/devshells.nix

raw symbols SCIP
1 { pkgs, system, common_packages, openssl_1_0_2, openssl_1_1_1, openssl_3_0
2 , aws-lc, aws-lc-fips-2022, aws-lc-fips-2024, writeScript }:
3
4 let
5 # --- rustup-driven toolchain selection (from rust-toolchain.toml) ---
6 rustToolchainToml =
7 builtins.fromTOML (builtins.readFile ./rust-toolchain.toml);
8 RUSTC_VERSION = rustToolchainToml.toolchain.channel or "stable";
9 # rustup uses a target triple in the toolchain directory name
10 RUSTUP_TARGET = pkgs.stdenv.hostPlatform.rust.rustcTarget;
11 # The toolchain folder name rustup creates is "${channel}-${target}"
12 RUSTUP_TOOLCHAIN = "${RUSTC_VERSION}-${RUSTUP_TARGET}";
13 # Ensure rustup-installed cargo/rustc take precedence in path
14 rustupPathHook = ''
15 export RUSTC_VERSION="${RUSTC_VERSION}"
16 export RUSTUP_TOOLCHAIN="${RUSTUP_TOOLCHAIN}"
17 export PATH="''${CARGO_HOME:-$HOME/.cargo}/bin:$PATH"
18 export PATH="''${RUSTUP_HOME:-$HOME/.rustup}/toolchains/$RUSTUP_TOOLCHAIN/bin:$PATH"
19 '';
20
21 rustShellHook = ''
22 # rust-bindgen uses libclang directly instead of calling the system's cc compiler wrapper.
23 # This means it doesn't automatically get the include paths and flags that Nix's gcc-wrapper provides.
24 # We need to explicitly configure bindgen with the correct libclang path and compiler flags.
25 # See: https://hoverbear.org/blog/rust-bindgen-in-nix/
26 # Set LIBCLANG_PATH so clang-sys (used by bindgen) can locate libclang in the Nix store.
27 export LIBCLANG_PATH="${pkgs.lib.getLib pkgs.llvmPackages_18.libclang}/lib"
28 # Pass the same CFLAGS that cc-wrapper would normally provide to bindgen via BINDGEN_EXTRA_CLANG_ARGS
29 export BINDGEN_EXTRA_CLANG_ARGS="\
30 $((< ${pkgs.stdenv.cc}/nix-support/libc-crt1-cflags)) \
31 $((< ${pkgs.stdenv.cc}/nix-support/libc-cflags)) \
32 $((< ${pkgs.stdenv.cc}/nix-support/cc-cflags)) \
33 $((< ${pkgs.stdenv.cc}/nix-support/libcxx-cxxflags)) \
34 ${
35 pkgs.lib.optionalString pkgs.stdenv.cc.isClang
36 "-idirafter ${pkgs.stdenv.cc.cc}/lib/clang/${
37 pkgs.lib.getVersion pkgs.stdenv.cc.cc
38 }/include"
39 } \
40 ${
41 pkgs.lib.optionalString pkgs.stdenv.cc.isGNU ''
42 -isystem ${pkgs.stdenv.cc.cc}/include/c++/${
43 pkgs.lib.getVersion pkgs.stdenv.cc.cc
44 }
45 -isystem ${pkgs.stdenv.cc.cc}/include/c++/${
46 pkgs.lib.getVersion pkgs.stdenv.cc.cc
47 }/${pkgs.stdenv.hostPlatform.config}
48 -idirafter ${pkgs.stdenv.cc.cc}/lib/gcc/${pkgs.stdenv.hostPlatform.config}/${
49 pkgs.lib.getVersion pkgs.stdenv.cc.cc
50 }/include''
51 }"
52 '';
53
54 # Base tool inputs for different development scenarios
55 rustToolInputs = [
56 pkgs.llvmPackages_18.clang
57 pkgs.llvmPackages_18.libclang
58 pkgs.llvmPackages_18.bintools
59 pkgs.cmake
60 pkgs.rustup
61 pkgs.go
62 ];
63
64 # Helper function to create base shell configurations
65 mkBaseShell =
66 { withRustTools ? false, cryptoLib, libcryptoName, extraCMakeFlags ? "" }:
67 pkgs.mkShell {
68 inherit system;
69 buildInputs = [ pkgs.cmake cryptoLib ]
70 ++ (if withRustTools then rustToolInputs else [ ]);
71 packages = if withRustTools then [ ] else common_packages;
72 S2N_LIBCRYPTO = libcryptoName;
73 # Environment variables for all crypto libraries
74 OPENSSL_1_0_2_INSTALL_DIR = "${openssl_1_0_2}";
75 OPENSSL_1_1_1_INSTALL_DIR = "${openssl_1_1_1}";
76 OPENSSL_3_0_INSTALL_DIR = "${openssl_3_0}";
77 AWSLC_INSTALL_DIR = "${aws-lc}";
78 AWSLC_FIPS_2022_INSTALL_DIR = "${aws-lc-fips-2022}";
79 AWSLC_FIPS_2024_INSTALL_DIR = "${aws-lc-fips-2024}";
80 GNUTLS_INSTALL_DIR = "${pkgs.gnutls}";
81 LIBRESSL_INSTALL_DIR = "${pkgs.libressl}";
82 shellHook = ''
83 echo Setting up $S2N_LIBCRYPTO${
84 if withRustTools then " + Rust" else ""
85 } environment from flake.nix...
86 export PATH=${openssl_1_1_1}/bin:$PATH
87 export PS1="[nix${
88 if withRustTools then " rust" else ""
89 } $S2N_LIBCRYPTO] $PS1"
90
91 ${extraCMakeFlags}
92
93 # Use rustup instead of nixpkgs rustc/cargo to avoid rustc-wrapper MSRV mismatches
94 ${pkgs.lib.optionalString withRustTools rustupPathHook}
95
96 ${rustShellHook}
97 source ${writeScript ./shell.sh}
98 '';
99 };
100
101 # By default, AWS-LC’s flake build produces shared libraries (.so).
102 # However, s2n-tls’s “intern libcrypto” mode statically links AWS-LC into the binary
103 # instead of dynamically linking at runtime. To support that, we override the default
104 # AWS-LC build to produce static libraries
105 awsLcStatic = aws-lc.overrideAttrs (old: {
106 cmakeFlags = (old.cmakeFlags or [ ]) ++ [ "-DBUILD_SHARED_LIBS=OFF" ];
107 });
108
109 awsLcFips2024Static = aws-lc-fips-2024.overrideAttrs (old: {
110 cmakeFlags = (old.cmakeFlags or [ ]) ++ [ "-DBUILD_SHARED_LIBS=OFF" ];
111 });
112
113 # Standard devshells (common_packages only)
114 default = mkBaseShell {
115 cryptoLib = openssl_3_0;
116 libcryptoName = "openssl-3.0";
117 };
118
119 openssl102 = mkBaseShell {
120 cryptoLib = openssl_1_0_2;
121 libcryptoName = "openssl-1.0.2";
122 };
123
124 openssl111 = mkBaseShell {
125 cryptoLib = openssl_1_1_1;
126 libcryptoName = "openssl-1.1.1";
127 };
128
129 libressl_shell = mkBaseShell {
130 cryptoLib = pkgs.libressl;
131 libcryptoName = "libressl";
132 };
133
134 awslc_shell = mkBaseShell {
135 cryptoLib = aws-lc;
136 libcryptoName = "awslc";
137 };
138
139 awslcfips2022_shell = mkBaseShell {
140 cryptoLib = aws-lc-fips-2022;
141 libcryptoName = "awslc-fips-2022";
142 };
143
144 awslcfips2024_shell = mkBaseShell {
145 cryptoLib = aws-lc-fips-2024;
146 libcryptoName = "awslc-fips-2024";
147 };
148
149 # Rust-enabled devshells (common_packages + rustToolInputs)
150 rust_openssl102 = mkBaseShell {
151 withRustTools = true;
152 cryptoLib = openssl_1_0_2;
153 libcryptoName = "openssl-1.0.2";
154 };
155
156 rust_openssl111 = mkBaseShell {
157 withRustTools = true;
158 cryptoLib = openssl_1_1_1;
159 libcryptoName = "openssl-1.1.1";
160 };
161
162 rust_openssl30 = mkBaseShell {
163 withRustTools = true;
164 cryptoLib = openssl_3_0;
165 libcryptoName = "openssl-3.0";
166 };
167
168 rust_awslc = mkBaseShell {
169 withRustTools = true;
170 cryptoLib = awsLcStatic;
171 libcryptoName = "awslc";
172 extraCMakeFlags = ''
173 export CMAKE_PREFIX_PATH="${awsLcStatic}''${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}"'';
174 };
175
176 rust_awslcfips2024 = mkBaseShell {
177 withRustTools = true;
178 cryptoLib = awsLcFips2024Static;
179 libcryptoName = "awslc-fips-2024";
180 extraCMakeFlags = ''
181 export CMAKE_PREFIX_PATH="${awsLcFips2024Static}''${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}"'';
182 };
183
184 in {
185 # Standard devshells (common_packages only)
186 default = default;
187 openssl102 = openssl102;
188 openssl111 = openssl111;
189 libressl = libressl_shell;
190 awslc = awslc_shell;
191 awslcfips2022 = awslcfips2022_shell;
192 awslcfips2024 = awslcfips2024_shell;
193
194 # Rust-enabled devshells (common_packages + rustToolInputs)
195 rust_openssl102 = rust_openssl102;
196 rust_openssl111 = rust_openssl111;
197 rust_openssl30 = rust_openssl30;
198 rust_awslc = rust_awslc;
199 rust_awslcfips2024 = rust_awslcfips2024;
200 }