From efc9828af80ecab747edc072b200cc104e6b5ea2 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 22 Jan 2026 10:15:20 -0800 Subject: [PATCH 01/16] Enable static builds --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index 0d04d3b1825d..2d9f1004caed 100644 --- a/flake.nix +++ b/flake.nix @@ -470,6 +470,9 @@ "${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.nixComponents2.${pkgName}; } ) + // { + "${pkgName}-static" = nixpkgsFor.${system}.native.pkgsStatic.nixComponents2.${pkgName}; + } ) // flatMapAttrs (lib.genAttrs stdenvs (_: { })) ( stdenvName: From 491773fa34188ebeca9c53b78f56e79bfb5d4004 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 23 Jan 2026 10:10:46 -0800 Subject: [PATCH 02/16] Fix prelink & libstore embedded shell --- src/libexpr-c/meson.build | 8 +++++++- src/libexpr/meson.build | 8 +++++++- src/libfetchers-c/meson.build | 8 +++++++- src/libfetchers/meson.build | 8 +++++++- src/libflake-c/meson.build | 8 +++++++- src/libflake/meson.build | 8 +++++++- src/libstore-c/meson.build | 8 +++++++- src/libstore/meson.build | 8 +++++++- src/libstore/package.nix | 2 +- src/libutil-c/meson.build | 8 +++++++- src/libutil/meson.build | 8 +++++++- 11 files changed, 71 insertions(+), 11 deletions(-) diff --git a/src/libexpr-c/meson.build b/src/libexpr-c/meson.build index c47704ce4112..c6d213bad7ae 100644 --- a/src/libexpr-c/meson.build +++ b/src/libexpr-c/meson.build @@ -47,6 +47,12 @@ headers = files( subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixexprc', sources, @@ -54,7 +60,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 0f0d7b28a7ff..5ab27a937cf9 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -229,6 +229,12 @@ parser_library = static_library( ], ) +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixexpr', sources, @@ -241,7 +247,7 @@ this_library = library( include_directories : include_dirs, link_args : linker_export_flags + [ '-lwasmtime' ], link_whole : [ parser_library ], - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) diff --git a/src/libfetchers-c/meson.build b/src/libfetchers-c/meson.build index db415d9173e7..b1663f1d50a2 100644 --- a/src/libfetchers-c/meson.build +++ b/src/libfetchers-c/meson.build @@ -50,6 +50,12 @@ headers += files('nix_api_fetchers.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixfetchersc', sources, @@ -57,7 +63,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build index cd04615e52ca..3736822414ac 100644 --- a/src/libfetchers/meson.build +++ b/src/libfetchers/meson.build @@ -65,6 +65,12 @@ sources += gen_header.process( subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixfetchers', sources, @@ -72,7 +78,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) diff --git a/src/libflake-c/meson.build b/src/libflake-c/meson.build index fddb39bdf96b..7379bb7d0f90 100644 --- a/src/libflake-c/meson.build +++ b/src/libflake-c/meson.build @@ -50,6 +50,12 @@ headers += files('nix_api_flake.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixflakec', sources, @@ -57,7 +63,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libflake/meson.build b/src/libflake/meson.build index 58916ecd9ab2..6e9e00e8303d 100644 --- a/src/libflake/meson.build +++ b/src/libflake/meson.build @@ -54,6 +54,12 @@ subdir('include/nix/flake') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixflake', sources, @@ -62,7 +68,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libstore-c/meson.build b/src/libstore-c/meson.build index c81235bf16d4..a078683cf382 100644 --- a/src/libstore-c/meson.build +++ b/src/libstore-c/meson.build @@ -45,6 +45,12 @@ headers += files('nix_api_store_internal.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixstorec', sources, @@ -52,7 +58,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libstore/meson.build b/src/libstore/meson.build index 52d60ad2fda8..c1f121376961 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -374,6 +374,12 @@ endif subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixstore', generated_headers, @@ -383,7 +389,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags + [ '-lwasmtime' ], - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) diff --git a/src/libstore/package.nix b/src/libstore/package.nix index 5a27506e19bb..241a5eb2ef6f 100644 --- a/src/libstore/package.nix +++ b/src/libstore/package.nix @@ -21,7 +21,7 @@ version, - embeddedSandboxShell ? stdenv.hostPlatform.isStatic, + embeddedSandboxShell ? stdenv.hostPlatform.isStatic && !stdenv.hostPlatform.isDarwin, withAWS ? # Default is this way because there have been issues building this dependency diff --git a/src/libutil-c/meson.build b/src/libutil-c/meson.build index 1806dbb6f9a0..0f82055b044a 100644 --- a/src/libutil-c/meson.build +++ b/src/libutil-c/meson.build @@ -49,6 +49,12 @@ headers += files('nix_api_util_internal.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixutilc', sources, @@ -57,7 +63,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 0b4a0841f906..39edc0245f8c 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -196,6 +196,12 @@ endif subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + this_library = library( 'nixutil', sources, @@ -203,7 +209,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) From 6f908212402eefcd403db9825018cf2eca500e23 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 23 Jan 2026 11:03:35 -0800 Subject: [PATCH 03/16] Add nix-cli-static to CI --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd98d0d00f97..1bbe2fb688dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,6 +52,7 @@ jobs: - uses: DeterminateSystems/flakehub-cache-action@main - run: nix build .#packages.${{ inputs.system }}.default .#packages.${{ inputs.system }}.binaryTarball --no-link -L - run: nix build .#packages.${{ inputs.system }}.binaryTarball --out-link tarball + - run: nix build .#packages.${{ inputs.system }}.nix-cli-static --no-link -L - uses: actions/upload-artifact@v4 with: name: ${{ inputs.system }} From 92e43886698ca9890700033d861be980665eca7b Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 23 Jan 2026 15:51:06 -0800 Subject: [PATCH 04/16] Fix static linking with wasmtime --- src/libexpr/meson.build | 13 ++++++++++++- src/libexpr/meson.options | 6 ++++++ src/libexpr/package.nix | 10 ++++++++-- src/libexpr/primops/meson.build | 5 ++++- src/libstore/meson.build | 15 ++++++++++++++- src/libstore/meson.options | 6 ++++++ src/libstore/package.nix | 7 +++++-- src/libstore/unix/build/derivation-builder.cc | 7 ++++++- 8 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 5ab27a937cf9..4bc87b850e48 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -77,6 +77,17 @@ endif # Used in public header. Affects ABI! configdata_pub.set('NIX_USE_BOEHMGC', bdw_gc.found().to_int()) +link_args = [] + +wasmtime_required = get_option('wasm').disable_if( + get_option('default_library') == 'static', + error_message : 'Building with wasmtime and static linking is not supported', +) + +if wasmtime_required.enabled() + link_args += '-lwasmtime' +endif + toml11 = dependency( 'toml11', version : '>=3.7.0', @@ -245,7 +256,7 @@ this_library = library( soversion : nix_soversion, dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, - link_args : linker_export_flags + [ '-lwasmtime' ], + link_args : linker_export_flags + link_args, link_whole : [ parser_library ], prelink : prelink, # For C++ static initializers install : true, diff --git a/src/libexpr/meson.options b/src/libexpr/meson.options index 847bb211d302..2defbf77aaa0 100644 --- a/src/libexpr/meson.options +++ b/src/libexpr/meson.options @@ -3,3 +3,9 @@ option( type : 'feature', description : 'enable garbage collection in the Nix expression evaluator (requires Boehm GC)', ) + +option( + 'wasm', + type : 'feature', + description : 'enable wasmtime integration into the Nix expression evaluator', +) diff --git a/src/libexpr/package.nix b/src/libexpr/package.nix index bd2ca6b4b026..1a9a2e04e332 100644 --- a/src/libexpr/package.nix +++ b/src/libexpr/package.nix @@ -30,6 +30,11 @@ # Temporarily disabled on Windows because the `GC_throw_bad_alloc` # symbol is missing during linking. enableGC ? !stdenv.hostPlatform.isWindows, + + # Whether to use wasmtime for wasm integration in the Nix language evaluator + # + # Temporarily disabled when static linking due to Rust not compiling + enableWasm ? !stdenv.hostPlatform.isStatic, }: let @@ -65,8 +70,8 @@ mkMesonLibrary (finalAttrs: { buildInputs = [ toml11 - wasmtime - ]; + ] + ++ lib.optional enableWasm wasmtime; propagatedBuildInputs = [ nix-util @@ -79,6 +84,7 @@ mkMesonLibrary (finalAttrs: { mesonFlags = [ (lib.mesonEnable "gc" enableGC) + (lib.mesonEnable "wasm" enableWasm) ]; meta = { diff --git a/src/libexpr/primops/meson.build b/src/libexpr/primops/meson.build index ad48eb162de1..d62b6df4ea20 100644 --- a/src/libexpr/primops/meson.build +++ b/src/libexpr/primops/meson.build @@ -9,5 +9,8 @@ sources += files( 'fetchMercurial.cc', 'fetchTree.cc', 'fromTOML.cc', - 'wasm.cc', ) + +if wasmtime_required.enabled() + sources += files('wasm.cc') +endif diff --git a/src/libstore/meson.build b/src/libstore/meson.build index c1f121376961..3a2665184a1c 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -266,6 +266,19 @@ configdata_priv.set_quoted( : 'lsof', ) +link_args = [] + +wasmtime_required = get_option('wasm').disable_if( + get_option('default_library') == 'static', + error_message : 'Building with wasmtime and static linking is not supported', +) + +if wasmtime_required.enabled() + link_args += '-lwasmtime' +endif + +configdata_priv.set('NIX_USE_WASMTIME', wasmtime_required.enabled().to_int()) + config_priv_h = configure_file( configuration : configdata_priv, output : 'store-config-private.hh', @@ -388,7 +401,7 @@ this_library = library( soversion : nix_soversion, dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, - link_args : linker_export_flags + [ '-lwasmtime' ], + link_args : linker_export_flags + link_args, prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], diff --git a/src/libstore/meson.options b/src/libstore/meson.options index c822133df46e..6bae2ab11f17 100644 --- a/src/libstore/meson.options +++ b/src/libstore/meson.options @@ -39,3 +39,9 @@ option( type : 'feature', description : 'build support for AWS authentication with S3', ) + +option( + 'wasm', + type : 'feature', + description : 'enable wasmtime integration into the Nix derivation builder', +) diff --git a/src/libstore/package.nix b/src/libstore/package.nix index 241a5eb2ef6f..a660b9a4646a 100644 --- a/src/libstore/package.nix +++ b/src/libstore/package.nix @@ -26,6 +26,8 @@ withAWS ? # Default is this way because there have been issues building this dependency stdenv.hostPlatform == stdenv.buildPlatform && (stdenv.isLinux || stdenv.isDarwin), + + enableWasm ? !stdenv.hostPlatform.isStatic, }: let @@ -65,10 +67,10 @@ mkMesonLibrary (finalAttrs: { boost curl sqlite - wasmtime ] ++ lib.optional stdenv.hostPlatform.isLinux libseccomp - ++ lib.optional withAWS aws-crt-cpp; + ++ lib.optional withAWS aws-crt-cpp + ++ lib.optional enableWasm wasmtime; propagatedBuildInputs = [ nix-util @@ -79,6 +81,7 @@ mkMesonLibrary (finalAttrs: { (lib.mesonEnable "seccomp-sandboxing" stdenv.hostPlatform.isLinux) (lib.mesonBool "embedded-sandbox-shell" embeddedSandboxShell) (lib.mesonEnable "s3-aws-auth" withAWS) + (lib.mesonEnable "wasm" enableWasm) ] ++ lib.optionals stdenv.hostPlatform.isLinux [ (lib.mesonOption "sandbox-shell" "${busybox-sandbox-shell}/bin/busybox") diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc index d4c7debbf35c..8644965e7500 100644 --- a/src/libstore/unix/build/derivation-builder.cc +++ b/src/libstore/unix/build/derivation-builder.cc @@ -1999,7 +1999,10 @@ StorePath DerivationBuilderImpl::makeFallbackPath(const StorePath & path) #include "linux-derivation-builder.cc" #include "darwin-derivation-builder.cc" #include "external-derivation-builder.cc" -#include "wasi-derivation-builder.cc" + +#if NIX_USE_WASMTIME +# include "wasi-derivation-builder.cc" +#endif namespace nix { @@ -2044,8 +2047,10 @@ std::unique_ptr makeDerivationBuild useSandbox = params.drv.type().isSandboxed() && !params.drvOptions.noChroot; } +#if NIX_USE_WASMTIME if (params.drv.platform == "wasm32-wasip1") return DerivationBuilderUnique(new WasiDerivationBuilder(store, std::move(miscMethods), std::move(params))); +#endif if (store.storeDir != store.config->realStoreDir.get()) { #ifdef __linux__ From e2c4c33d0acf93952cd0bfec3c94625512700512 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 23 Jan 2026 16:06:11 -0800 Subject: [PATCH 05/16] Common prelink check --- nix-meson-build-support/common/meson.build | 6 ++++++ src/libcmd/meson.build | 2 +- src/libexpr-c/meson.build | 6 ------ src/libexpr-test-support/meson.build | 2 +- src/libexpr/meson.build | 6 ------ src/libfetchers-c/meson.build | 6 ------ src/libfetchers/meson.build | 6 ------ src/libflake-c/meson.build | 6 ------ src/libflake/meson.build | 6 ------ src/libmain-c/meson.build | 2 +- src/libmain/meson.build | 2 +- src/libstore-c/meson.build | 6 ------ src/libstore-test-support/meson.build | 2 +- src/libstore/meson.build | 6 ------ src/libutil-c/meson.build | 6 ------ src/libutil-test-support/meson.build | 2 +- src/libutil/meson.build | 6 ------ src/perl/lib/Nix/meson.build | 8 +++++++- 18 files changed, 19 insertions(+), 67 deletions(-) diff --git a/nix-meson-build-support/common/meson.build b/nix-meson-build-support/common/meson.build index 5fcf557e70ba..2185e4b8f35e 100644 --- a/nix-meson-build-support/common/meson.build +++ b/nix-meson-build-support/common/meson.build @@ -65,5 +65,11 @@ endif # Darwin ld doesn't like "X.Y.ZpreABCD+W" nix_soversion = meson.project_version().split('+')[0].split('pre')[0] +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + subdir('assert-fail') subdir('asan-options') diff --git a/src/libcmd/meson.build b/src/libcmd/meson.build index f553afa0ba17..fd24e83839c3 100644 --- a/src/libcmd/meson.build +++ b/src/libcmd/meson.build @@ -99,7 +99,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], ) diff --git a/src/libexpr-c/meson.build b/src/libexpr-c/meson.build index c6d213bad7ae..df1e3c05880c 100644 --- a/src/libexpr-c/meson.build +++ b/src/libexpr-c/meson.build @@ -47,12 +47,6 @@ headers = files( subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixexprc', sources, diff --git a/src/libexpr-test-support/meson.build b/src/libexpr-test-support/meson.build index df28661b7e78..0fae96b47f1e 100644 --- a/src/libexpr-test-support/meson.build +++ b/src/libexpr-test-support/meson.build @@ -50,7 +50,7 @@ this_library = library( # TODO: Remove `-lrapidcheck` when https://github.com/emil-e/rapidcheck/pull/326 # is available. See also ../libutil/build.meson link_args : linker_export_flags + [ '-lrapidcheck' ], - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 4bc87b850e48..9fc0d400280f 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -240,12 +240,6 @@ parser_library = static_library( ], ) -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixexpr', sources, diff --git a/src/libfetchers-c/meson.build b/src/libfetchers-c/meson.build index b1663f1d50a2..c029eb0d1e59 100644 --- a/src/libfetchers-c/meson.build +++ b/src/libfetchers-c/meson.build @@ -50,12 +50,6 @@ headers += files('nix_api_fetchers.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixfetchersc', sources, diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build index 3736822414ac..c1bc8397721d 100644 --- a/src/libfetchers/meson.build +++ b/src/libfetchers/meson.build @@ -65,12 +65,6 @@ sources += gen_header.process( subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixfetchers', sources, diff --git a/src/libflake-c/meson.build b/src/libflake-c/meson.build index 7379bb7d0f90..d0055e5d98fc 100644 --- a/src/libflake-c/meson.build +++ b/src/libflake-c/meson.build @@ -50,12 +50,6 @@ headers += files('nix_api_flake.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixflakec', sources, diff --git a/src/libflake/meson.build b/src/libflake/meson.build index 6e9e00e8303d..4b490f0f9176 100644 --- a/src/libflake/meson.build +++ b/src/libflake/meson.build @@ -54,12 +54,6 @@ subdir('include/nix/flake') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixflake', sources, diff --git a/src/libmain-c/meson.build b/src/libmain-c/meson.build index 36332fdb70a1..dd02c20a4c67 100644 --- a/src/libmain-c/meson.build +++ b/src/libmain-c/meson.build @@ -49,7 +49,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libmain/meson.build b/src/libmain/meson.build index 2ac59924e592..d9d5e9362d5e 100644 --- a/src/libmain/meson.build +++ b/src/libmain/meson.build @@ -81,7 +81,7 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags, - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libstore-c/meson.build b/src/libstore-c/meson.build index a078683cf382..fd5d4990efba 100644 --- a/src/libstore-c/meson.build +++ b/src/libstore-c/meson.build @@ -45,12 +45,6 @@ headers += files('nix_api_store_internal.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixstorec', sources, diff --git a/src/libstore-test-support/meson.build b/src/libstore-test-support/meson.build index 8617225d743f..d3d925d26848 100644 --- a/src/libstore-test-support/meson.build +++ b/src/libstore-test-support/meson.build @@ -51,7 +51,7 @@ this_library = library( # TODO: Remove `-lrapidcheck` when https://github.com/emil-e/rapidcheck/pull/326 # is available. See also ../libutil/build.meson link_args : linker_export_flags + [ '-lrapidcheck' ], - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libstore/meson.build b/src/libstore/meson.build index 3a2665184a1c..f692a2e1e5e0 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -387,12 +387,6 @@ endif subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixstore', generated_headers, diff --git a/src/libutil-c/meson.build b/src/libutil-c/meson.build index 0f82055b044a..93817efd726b 100644 --- a/src/libutil-c/meson.build +++ b/src/libutil-c/meson.build @@ -49,12 +49,6 @@ headers += files('nix_api_util_internal.h') subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixutilc', sources, diff --git a/src/libutil-test-support/meson.build b/src/libutil-test-support/meson.build index 64231107eb6b..f9254b616725 100644 --- a/src/libutil-test-support/meson.build +++ b/src/libutil-test-support/meson.build @@ -47,7 +47,7 @@ this_library = library( # TODO: Remove `-lrapidcheck` when https://github.com/emil-e/rapidcheck/pull/326 # is available. See also ../libutil/build.meson link_args : linker_export_flags + [ '-lrapidcheck' ], - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, ) diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 39edc0245f8c..569110070ade 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -196,12 +196,6 @@ endif subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/windows-version') -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' - prelink = false -else - prelink = true -endif - this_library = library( 'nixutil', sources, diff --git a/src/perl/lib/Nix/meson.build b/src/perl/lib/Nix/meson.build index dd5560e21cc5..675d33b63710 100644 --- a/src/perl/lib/Nix/meson.build +++ b/src/perl/lib/Nix/meson.build @@ -38,13 +38,19 @@ nix_perl_store_cc = custom_target( command : [ xsubpp, '@INPUT@', '-output', '@OUTPUT@' ], ) +if host_machine.system() == 'darwin' and get_option('default_library') == 'static' + prelink = false +else + prelink = true +endif + # Build Nix::Store Library #------------------------------------------------- nix_perl_store_lib = library( 'Store', sources : nix_perl_store_cc, name_prefix : '', - prelink : true, # For C++ static initializers + prelink : prelink, # For C++ static initializers install : true, install_mode : 'rwxr-xr-x', install_dir : join_paths(nix_perl_install_dir, 'auto', 'Nix', 'Store'), From 3614557c669b49c02b00a419e3ad47ece23d9085 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 23 Jan 2026 16:42:20 -0800 Subject: [PATCH 06/16] Disable libpsl in curl on static builds --- packaging/dependencies.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packaging/dependencies.nix b/packaging/dependencies.nix index 24e86c2bca94..9cb532d1eba5 100644 --- a/packaging/dependencies.nix +++ b/packaging/dependencies.nix @@ -82,4 +82,9 @@ scope: { }); wasmtime = pkgs.callPackage ./wasmtime.nix { }; + + curl = pkgs.curl.override { + # libpsl uses a data file needed at runtime, not useful for nix. + pslSupport = !pkgs.stdenv.hostPlatform.isStatic; + }; } From d9ad8e44de8869b76e90990a503bce90cde16677 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 23 Jan 2026 17:57:39 -0800 Subject: [PATCH 07/16] Disable libidn in curl on static builds --- packaging/dependencies.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/dependencies.nix b/packaging/dependencies.nix index 9cb532d1eba5..b89dc36e82ac 100644 --- a/packaging/dependencies.nix +++ b/packaging/dependencies.nix @@ -85,6 +85,7 @@ scope: { curl = pkgs.curl.override { # libpsl uses a data file needed at runtime, not useful for nix. - pslSupport = !pkgs.stdenv.hostPlatform.isStatic; + pslSupport = !stdenv.hostPlatform.isStatic; + idnSupport = !stdenv.hostPlatform.isStatic; }; } From eaa01acc300831ab098501030bbb5fae252196d6 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Wed, 28 Jan 2026 11:36:23 -0800 Subject: [PATCH 08/16] default-system-cpu: fixup macOS static build showing `arm64-darwin` as system --- doc/manual/source/development/building.md | 1 + nix-meson-build-support/default-system-cpu/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/manual/source/development/building.md b/doc/manual/source/development/building.md index da72204107c1..9694183ba82e 100644 --- a/doc/manual/source/development/building.md +++ b/doc/manual/source/development/building.md @@ -143,6 +143,7 @@ For historic reasons and backward-compatibility, some CPU and OS identifiers are |-----------------------------|-------------------------|---------------------| | `x86` | | `i686` | | `arm` | | `host_machine.cpu()`| +| `arm64` | | `host_machine.cpu()`| | `ppc` | `little` | `powerpcle` | | `ppc64` | `little` | `powerpc64le` | | `ppc` | `big` | `powerpc` | diff --git a/nix-meson-build-support/default-system-cpu/meson.build b/nix-meson-build-support/default-system-cpu/meson.build index f63b07975b6e..3e872578efca 100644 --- a/nix-meson-build-support/default-system-cpu/meson.build +++ b/nix-meson-build-support/default-system-cpu/meson.build @@ -14,6 +14,6 @@ if (host_machine.cpu_family() in [ 'ppc64', 'ppc' ]) and host_machine.endian() = nix_system_cpu += 'le' elif host_machine.cpu_family() in [ 'mips64', 'mips' ] and host_machine.endian() == 'little' nix_system_cpu += 'el' -elif host_machine.cpu_family() == 'arm' +elif host_machine.cpu_family() in [ 'arm', 'arm64' ] nix_system_cpu = host_machine.cpu() endif From 19aeca23168797b8766ba18111785e489c5fb7d8 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 30 Jan 2026 09:49:53 -0800 Subject: [PATCH 09/16] libutil-c: start signal handling on unix in init --- src/libutil-c/nix_api_util.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libutil-c/nix_api_util.cc b/src/libutil-c/nix_api_util.cc index f28a9168e30b..23eafa8e8ff3 100644 --- a/src/libutil-c/nix_api_util.cc +++ b/src/libutil-c/nix_api_util.cc @@ -2,6 +2,7 @@ #include "nix/util/config-global.hh" #include "nix/util/error.hh" #include "nix_api_util_internal.h" +#include "nix/util/signals.hh" #include "nix/util/util.hh" #include @@ -111,6 +112,9 @@ nix_err nix_libutil_init(nix_c_context * context) context->last_err_code = NIX_OK; try { nix::initLibUtil(); +#ifndef _WIN32 + nix::unix::startSignalHandlerThread(); +#endif return NIX_OK; } NIXC_CATCH_ERRS From ecce443b35b8fc9174a0759ca45fe35d267c03ae Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 30 Jan 2026 09:50:29 -0800 Subject: [PATCH 10/16] Temporarily disable the interrupt callback for the curl file transfer --- src/libstore/filetransfer.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 35ca62df0e8f..74bbdbeeb72a 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -802,7 +802,9 @@ struct curlFileTransfer : public FileTransfer /* Cause this thread to be notified on SIGINT. */ #ifndef _WIN32 // TODO need graceful async exit support on Windows? - auto callback = createInterruptCallback([&]() { stopWorkerThread(); }); + // FIXME(RossComputerGuy): this causes issues on static builds. + // In particular, it causes a segfault to happen at the end of the program running. + // auto callback = createInterruptCallback([&]() { stopWorkerThread(); }); #endif #ifdef __linux__ From 0e3482b1f9d847dd99852038148041ed4c61ae66 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Fri, 30 Jan 2026 10:27:51 -0800 Subject: [PATCH 11/16] Use libcxx stdenv on static darwin --- flake.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 2d9f1004caed..28654dc654f5 100644 --- a/flake.nix +++ b/flake.nix @@ -241,7 +241,14 @@ otherSplices = renameSplicesTo "self" nixDependenciesSplices; f = import ./packaging/dependencies.nix { inherit inputs pkgs; - stdenv = getStdenv pkgs; + stdenv = + let + stdenv = getStdenv pkgs; + in + if stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic then + pkgs.llvmPackages.libcxxStdenv + else + stdenv; }; }; From b6a79586bd1c3b7ffa632230b0d986a3e4bdee17 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Tue, 3 Feb 2026 02:01:14 -0800 Subject: [PATCH 12/16] Use unity builds --- src/libexpr/meson.build | 27 ++++++++++++++++--- src/libexpr/primops/meson.build | 4 +-- .../include/nix/fetchers/input-cache.hh | 2 ++ src/libfetchers/meson.build | 2 ++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 9fc0d400280f..178be09a127f 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -7,6 +7,8 @@ project( # TODO(Qyriad): increase the warning level 'warning_level=1', 'errorlogs=true', # Please print logs for tests that fail + 'unity=on', + 'unity_size=1024', ], meson_version : '>= 1.1', license : 'LGPL-2.1-or-later', @@ -174,11 +176,9 @@ sources = files( 'function-trace.cc', 'get-drvs.cc', 'json-to-value.cc', - 'lexer-helpers.cc', 'nixexpr.cc', 'parallel-eval.cc', 'paths.cc', - 'primops.cc', 'print-ambiguous.cc', 'print.cc', 'search-path.cc', @@ -189,6 +189,10 @@ sources = files( 'value/context.cc', ) +primops_sources = files( + 'primops.cc', +) + subdir('include/nix/expr') subdir('primops') @@ -227,6 +231,7 @@ parser_library = static_library( 'nixexpr-parser', parser_tab, lexer_tab, + files('lexer-helpers.cc'), cpp_args : parser_library_cpp_args, dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, @@ -234,6 +239,19 @@ parser_library = static_library( # them for this one library when building in a release configuration. # 2. Disable LTO for GCC because then inlining flags won't apply, since LTO in GCC is done # by plonking down GIMPLE in the archive. + override_options : [ + 'b_ndebug=@0@'.format(not get_option('debug')), + 'b_lto=@0@'.format(get_option('b_lto') and cxx.get_id() != 'gcc'), + 'unity=off', + ], +) + +primops_library = static_library( + 'nixexpr-primops', + primops_sources, + generated_headers, + dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, override_options : [ 'b_ndebug=@0@'.format(not get_option('debug')), 'b_lto=@0@'.format(get_option('b_lto') and cxx.get_id() != 'gcc'), @@ -251,10 +269,13 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags + link_args, - link_whole : [ parser_library ], + link_whole : [ parser_library, primops_library ], prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], + override_options : [ + 'unity=off', + ], ) install_headers(headers, subdir : 'nix/expr', preserve_path : true) diff --git a/src/libexpr/primops/meson.build b/src/libexpr/primops/meson.build index d62b6df4ea20..3ffab5d9da7f 100644 --- a/src/libexpr/primops/meson.build +++ b/src/libexpr/primops/meson.build @@ -3,7 +3,7 @@ generated_headers += gen_header.process( preserve_path_from : meson.project_source_root(), ) -sources += files( +primops_sources += files( 'context.cc', 'fetchClosure.cc', 'fetchMercurial.cc', @@ -12,5 +12,5 @@ sources += files( ) if wasmtime_required.enabled() - sources += files('wasm.cc') + primops_sources += files('wasm.cc') endif diff --git a/src/libfetchers/include/nix/fetchers/input-cache.hh b/src/libfetchers/include/nix/fetchers/input-cache.hh index 463927ceaee3..4a6a1dff83c6 100644 --- a/src/libfetchers/include/nix/fetchers/input-cache.hh +++ b/src/libfetchers/include/nix/fetchers/input-cache.hh @@ -1,3 +1,5 @@ +#pragma once + #include "nix/fetchers/fetchers.hh" namespace nix::fetchers { diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build index c1bc8397721d..497a725b7eb7 100644 --- a/src/libfetchers/meson.build +++ b/src/libfetchers/meson.build @@ -7,6 +7,8 @@ project( # TODO(Qyriad): increase the warning level 'warning_level=1', 'errorlogs=true', # Please print logs for tests that fail + 'unity=on', + 'unity_size=1024', ], meson_version : '>= 1.1', license : 'LGPL-2.1-or-later', From 76a53de337758f37c4d8f04ace6cab0b23962032 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 Feb 2026 20:01:10 +0100 Subject: [PATCH 13/16] Remove primops_library --- src/libexpr/meson.build | 26 ++++---------------------- src/libexpr/primops/meson.build | 4 ++-- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 178be09a127f..0edc2ef1daf2 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -169,7 +169,6 @@ sources = files( 'eval-cache.cc', 'eval-error.cc', 'eval-gc.cc', - 'eval-profiler-settings.cc', 'eval-profiler.cc', 'eval-settings.cc', 'eval.cc', @@ -179,6 +178,7 @@ sources = files( 'nixexpr.cc', 'parallel-eval.cc', 'paths.cc', + 'primops.cc', 'print-ambiguous.cc', 'print.cc', 'search-path.cc', @@ -189,10 +189,6 @@ sources = files( 'value/context.cc', ) -primops_sources = files( - 'primops.cc', -) - subdir('include/nix/expr') subdir('primops') @@ -231,7 +227,8 @@ parser_library = static_library( 'nixexpr-parser', parser_tab, lexer_tab, - files('lexer-helpers.cc'), + # Putting eval-profiler-settings.cc here to work around an inscrutable gcc compiler error when doing a unity build. + files('eval-profiler-settings.cc', 'lexer-helpers.cc'), cpp_args : parser_library_cpp_args, dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, @@ -246,18 +243,6 @@ parser_library = static_library( ], ) -primops_library = static_library( - 'nixexpr-primops', - primops_sources, - generated_headers, - dependencies : deps_public + deps_private + deps_other, - include_directories : include_dirs, - override_options : [ - 'b_ndebug=@0@'.format(not get_option('debug')), - 'b_lto=@0@'.format(get_option('b_lto') and cxx.get_id() != 'gcc'), - ], -) - this_library = library( 'nixexpr', sources, @@ -269,13 +254,10 @@ this_library = library( dependencies : deps_public + deps_private + deps_other, include_directories : include_dirs, link_args : linker_export_flags + link_args, - link_whole : [ parser_library, primops_library ], + link_whole : [ parser_library ], prelink : prelink, # For C++ static initializers install : true, cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [], - override_options : [ - 'unity=off', - ], ) install_headers(headers, subdir : 'nix/expr', preserve_path : true) diff --git a/src/libexpr/primops/meson.build b/src/libexpr/primops/meson.build index 3ffab5d9da7f..d62b6df4ea20 100644 --- a/src/libexpr/primops/meson.build +++ b/src/libexpr/primops/meson.build @@ -3,7 +3,7 @@ generated_headers += gen_header.process( preserve_path_from : meson.project_source_root(), ) -primops_sources += files( +sources += files( 'context.cc', 'fetchClosure.cc', 'fetchMercurial.cc', @@ -12,5 +12,5 @@ primops_sources += files( ) if wasmtime_required.enabled() - primops_sources += files('wasm.cc') + sources += files('wasm.cc') endif From 83c2e4f4eef9d2831d704d7508f47a6934fee113 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Wed, 4 Feb 2026 18:14:36 -0800 Subject: [PATCH 14/16] Disable interrupt check in libstore only on static --- src/libstore/filetransfer.cc | 8 ++++---- src/libstore/meson.build | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 74bbdbeeb72a..f7a5d6721032 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -801,10 +801,10 @@ struct curlFileTransfer : public FileTransfer assert(maxQueueSize > 0); /* Cause this thread to be notified on SIGINT. */ -#ifndef _WIN32 // TODO need graceful async exit support on Windows? - // FIXME(RossComputerGuy): this causes issues on static builds. - // In particular, it causes a segfault to happen at the end of the program running. - // auto callback = createInterruptCallback([&]() { stopWorkerThread(); }); +#if !defined(_WIN32) && !defined(IS_STATIC) // TODO need graceful async exit support on Windows? + // FIXME(RossComputerGuy): this causes issues on static builds. + // In particular, it causes a segfault to happen at the end of the program running. + auto callback = createInterruptCallback([&]() { stopWorkerThread(); }); #endif #ifdef __linux__ diff --git a/src/libstore/meson.build b/src/libstore/meson.build index f692a2e1e5e0..2c4b60d995dd 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -24,6 +24,7 @@ configdata_priv = configuration_data() # TODO rename, because it will conflict with downstream projects configdata_priv.set_quoted('PACKAGE_VERSION', meson.project_version()) +configdata_priv.set('IS_STATIC', get_option('default_library') == 'static') configdata_priv.set_quoted( 'DETERMINATE_NIX_VERSION', From 1f2a2426161f537abfa3db8652d4340b7e601fa5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 5 Feb 2026 10:18:01 -0800 Subject: [PATCH 15/16] Minor improvements for static & libcxx --- .github/workflows/build.yml | 2 +- flake.nix | 13 ++--- nix-meson-build-support/common/meson.build | 5 +- packaging/dependencies.nix | 61 +++++++++++++++++++++- src/libexpr/package.nix | 11 ++++ src/nix/package.nix | 26 ++++++++- 6 files changed, 106 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1bbe2fb688dd..cba0b9ab1a40 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: - uses: DeterminateSystems/flakehub-cache-action@main - run: nix build .#packages.${{ inputs.system }}.default .#packages.${{ inputs.system }}.binaryTarball --no-link -L - run: nix build .#packages.${{ inputs.system }}.binaryTarball --out-link tarball - - run: nix build .#packages.${{ inputs.system }}.nix-cli-static --no-link -L + - run: nix build .#packages.${{ inputs.system }}.nix-cli-libcxxStdenv-static .#packages.${{ inputs.system }}.nix-cli-static --no-link -L - uses: actions/upload-artifact@v4 with: name: ${{ inputs.system }} diff --git a/flake.nix b/flake.nix index 28654dc654f5..b32a95b06a23 100644 --- a/flake.nix +++ b/flake.nix @@ -241,14 +241,7 @@ otherSplices = renameSplicesTo "self" nixDependenciesSplices; f = import ./packaging/dependencies.nix { inherit inputs pkgs; - stdenv = - let - stdenv = getStdenv pkgs; - in - if stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic then - pkgs.llvmPackages.libcxxStdenv - else - stdenv; + stdenv = getStdenv pkgs; }; }; @@ -489,6 +482,10 @@ "${pkgName}-${stdenvName}" = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.nixComponents2.${pkgName}; } + // lib.optionalAttrs supportsCross { + "${pkgName}-${stdenvName}-static" = + nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsStatic.nixComponents2.${pkgName}; + } ) ) // lib.optionalAttrs (builtins.elem system linux64BitSystems) { diff --git a/nix-meson-build-support/common/meson.build b/nix-meson-build-support/common/meson.build index 2185e4b8f35e..b192c0d03521 100644 --- a/nix-meson-build-support/common/meson.build +++ b/nix-meson-build-support/common/meson.build @@ -65,7 +65,10 @@ endif # Darwin ld doesn't like "X.Y.ZpreABCD+W" nix_soversion = meson.project_version().split('+')[0].split('pre')[0] -if host_machine.system() == 'darwin' and get_option('default_library') == 'static' +cxx = meson.get_compiler('cpp') + +# Clang does not support prelinking on static builds +if cxx.get_id() == 'clang' and get_option('default_library') == 'static' prelink = false else prelink = true diff --git a/packaging/dependencies.nix b/packaging/dependencies.nix index b89dc36e82ac..f5e39e6e005f 100644 --- a/packaging/dependencies.nix +++ b/packaging/dependencies.nix @@ -16,9 +16,41 @@ in scope: { inherit stdenv; + libblake3 = + (pkgs.libblake3.override { + inherit stdenv; + # Nixpkgs disables tbb on static + useTBB = !stdenv.hostPlatform.isStatic; + }) + # For some reason that is not clear, it is wanting to use libgcc_eh which is not available. + # Force this to be built with compiler-rt & libunwind over libgcc_eh works. + # Issue: https://github.com/NixOS/nixpkgs/issues/177129 + .overrideAttrs + ( + attrs: + lib.optionalAttrs + ( + stdenv.cc.isClang + && stdenv.hostPlatform.isStatic + && stdenv.cc.libcxx != null + && stdenv.cc.libcxx.isLLVM + ) + { + NIX_CFLAGS_COMPILE = [ + "-rtlib=compiler-rt" + "-unwindlib=libunwind" + ]; + + buildInputs = [ + pkgs.llvmPackages.libunwind + ]; + } + ); + boehmgc = (pkgs.boehmgc.override { enableLargeConfig = true; + inherit stdenv; }).overrideAttrs (attrs: { # Increase the initial mark stack size to avoid stack @@ -27,7 +59,33 @@ scope: { # small, run Nix with GC_PRINT_STATS=1 and look for messages # such as `Mark stack overflow`, `No room to copy back mark # stack`, and `Grew mark stack to ... frames`. - NIX_CFLAGS_COMPILE = "-DINITIAL_MARK_STACK_SIZE=1048576"; + NIX_CFLAGS_COMPILE = [ + "-DINITIAL_MARK_STACK_SIZE=1048576" + ] + # For some reason that is not clear, it is wanting to use libgcc_eh which is not available. + # Force this to be built with compiler-rt & libunwind over libgcc_eh works. + # Issue: https://github.com/NixOS/nixpkgs/issues/177129 + ++ + lib.optionals + ( + stdenv.cc.isClang + && stdenv.hostPlatform.isStatic + && stdenv.cc.libcxx != null + && stdenv.cc.libcxx.isLLVM + ) + [ + "-rtlib=compiler-rt" + "-unwindlib=libunwind" + ]; + + buildInputs = + (attrs.buildInputs or [ ]) + ++ lib.optional ( + stdenv.cc.isClang + && stdenv.hostPlatform.isStatic + && stdenv.cc.libcxx != null + && stdenv.cc.libcxx.isLLVM + ) pkgs.llvmPackages.libunwind; }); lowdown = @@ -74,6 +132,7 @@ scope: { "--with-thread" ]; enableIcu = false; + inherit stdenv; }).overrideAttrs (old: { # Need to remove `--with-*` to use `--with-libraries=...` diff --git a/src/libexpr/package.nix b/src/libexpr/package.nix index 1a9a2e04e332..46c617bbcb19 100644 --- a/src/libexpr/package.nix +++ b/src/libexpr/package.nix @@ -87,6 +87,17 @@ mkMesonLibrary (finalAttrs: { (lib.mesonEnable "wasm" enableWasm) ]; + # Fixes a problem with the "nix-expr-libcxxStdenv-static" package output. + # For some reason that is not clear, it is wanting to use libgcc_eh which is not available. + # Force this to be built with compiler-rt over libgcc_eh works. + # Issue: https://github.com/NixOS/nixpkgs/issues/177129 + NIX_CFLAGS_COMPILE = lib.optional ( + stdenv.cc.isClang + && stdenv.hostPlatform.isStatic + && stdenv.cc.libcxx != null + && stdenv.cc.libcxx.isLLVM + ) "-rtlib=compiler-rt"; + meta = { platforms = lib.platforms.unix ++ lib.platforms.windows; }; diff --git a/src/nix/package.nix b/src/nix/package.nix index d362d0923099..9c223bceb2ba 100644 --- a/src/nix/package.nix +++ b/src/nix/package.nix @@ -2,6 +2,7 @@ stdenv, lib, mkMesonExecutable, + llvmPackages, nix-store, nix-expr, @@ -69,7 +70,13 @@ mkMesonExecutable (finalAttrs: { nix-expr nix-main nix-cmd - ]; + ] + ++ lib.optional ( + stdenv.cc.isClang + && stdenv.hostPlatform.isStatic + && stdenv.cc.libcxx != null + && stdenv.cc.libcxx.isLLVM + ) llvmPackages.libunwind; mesonFlags = [ ]; @@ -79,6 +86,23 @@ mkMesonExecutable (finalAttrs: { echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products ''; + # Fixes a problem with the "nix-cli-libcxxStdenv-static" package output. + # For some reason that is not clear, it is wanting to use libgcc_eh which is not available. + # Force this to be built with compiler-rt & libunwind over libgcc_eh works. + # Issue: https://github.com/NixOS/nixpkgs/issues/177129 + NIX_CFLAGS_COMPILE = + lib.optionals + ( + stdenv.cc.isClang + && stdenv.hostPlatform.isStatic + && stdenv.cc.libcxx != null + && stdenv.cc.libcxx.isLLVM + ) + [ + "-rtlib=compiler-rt" + "-unwindlib=libunwind" + ]; + meta = { mainProgram = "nix"; platforms = lib.platforms.unix ++ lib.platforms.windows; From afca2cffdd1f318d836e11bbd1378cdd322ace59 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 6 Feb 2026 12:26:08 +0100 Subject: [PATCH 16/16] Build one static package --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cba0b9ab1a40..1bbe2fb688dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: - uses: DeterminateSystems/flakehub-cache-action@main - run: nix build .#packages.${{ inputs.system }}.default .#packages.${{ inputs.system }}.binaryTarball --no-link -L - run: nix build .#packages.${{ inputs.system }}.binaryTarball --out-link tarball - - run: nix build .#packages.${{ inputs.system }}.nix-cli-libcxxStdenv-static .#packages.${{ inputs.system }}.nix-cli-static --no-link -L + - run: nix build .#packages.${{ inputs.system }}.nix-cli-static --no-link -L - uses: actions/upload-artifact@v4 with: name: ${{ inputs.system }}