From 1dd53e35af4dcd1503bdb74116b2196f86d99d77 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 21 Oct 2024 18:46:42 +0200 Subject: [PATCH 1/3] fix(darwin): do not use zig for darwin2darwin Signed-off-by: Roman Volosatovs --- lib/rust/mkAttrs.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/rust/mkAttrs.nix b/lib/rust/mkAttrs.nix index 507078dd..0a34cd22 100644 --- a/lib/rust/mkAttrs.nix +++ b/lib/rust/mkAttrs.nix @@ -334,9 +334,21 @@ with self.lib.rust.targets; # Removing vendor references here invalidates the signature, which is required on aarch64-darwin doNotRemoveReferencesToVendorDir = true; } - # Use `rust-lld` linker and Zig C compiler for Darwin targets + // optionalAttrs pkgsCross.stdenv.hostPlatform.isDarwin { + preBuild = '' + export SDKROOT="${macos-sdk}" + ''; + + # Use `rust-lld` linker for Darwin targets + "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "rust-lld"; + } // ( - if pkgsCross.stdenv.hostPlatform.isDarwin + if final.stdenv.buildPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin + then { + # use defaults for Darwin-to-Darwin builds + } + # Use Zig C compiler and `rust-lld` linker for Darwin targets on non-Darwin platforms + else if pkgsCross.stdenv.hostPlatform.isDarwin then { depsBuildBuild = [ crossZigCC From f9e6192c984329173520e12842bf1e91c03e887f Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 21 Oct 2024 18:52:03 +0200 Subject: [PATCH 2/3] feat!: switch to `nixpkgs-unstable` Signed-off-by: Roman Volosatovs --- examples/rust-complex/flake.nix | 3 +-- flake.lock | 33 ++++++++------------------------- flake.nix | 7 +++---- lib/mkFlake.nix | 9 ++------- lib/rust/defaultPkgsFor.nix | 9 ++------- 5 files changed, 16 insertions(+), 45 deletions(-) diff --git a/examples/rust-complex/flake.nix b/examples/rust-complex/flake.nix index c94f96d6..fec10a77 100644 --- a/examples/rust-complex/flake.nix +++ b/examples/rust-complex/flake.nix @@ -1,6 +1,5 @@ { - inputs.nixify.inputs.nixpkgs-darwin.follows = "nixpkgs"; - inputs.nixify.inputs.nixpkgs-nixos.follows = "nixpkgs"; + inputs.nixify.inputs.nixpkgs.follows = "nixpkgs"; inputs.nixify.url = "github:rvolosatovs/nixify"; inputs.nixpkgs.url = "github:NixOS/nixpkgs"; diff --git a/flake.lock b/flake.lock index ef7cc6d2..e3cebf56 100644 --- a/flake.lock +++ b/flake.lock @@ -68,7 +68,7 @@ "fenix": { "inputs": { "nixpkgs": [ - "nixpkgs-nixos" + "nixpkgs" ], "rust-analyzer-src": "rust-analyzer-src" }, @@ -321,34 +321,18 @@ "type": "github" } }, - "nixpkgs-darwin": { + "nixpkgs_2": { "locked": { - "lastModified": 1729242558, - "narHash": "sha256-VgcLDu4igNT0eYua6OAl9pWCI0cYXhDbR+pWP44tte0=", + "lastModified": 1729265718, + "narHash": "sha256-4HQI+6LsO3kpWTYuVGIzhJs1cetFcwT7quWCk/6rqeo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4a3f2d3195b60d07530574988df92e049372c10e", + "rev": "ccc0c2126893dd20963580b6478d1a10a4512185", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixpkgs-24.05-darwin", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-nixos": { - "locked": { - "lastModified": 1729181673, - "narHash": "sha256-LDiPhQ3l+fBjRATNtnuDZsBS7hqoBtPkKBkhpoBHv3I=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "4eb33fe664af7b41a4c446f87d20c9a0a6321fa3", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-24.05", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } @@ -363,8 +347,7 @@ "nix-filter": "nix-filter", "nix-log": "nix-log", "nixlib": "nixlib_3", - "nixpkgs-darwin": "nixpkgs-darwin", - "nixpkgs-nixos": "nixpkgs-nixos", + "nixpkgs": "nixpkgs_2", "rust-overlay": "rust-overlay_2" } }, @@ -432,7 +415,7 @@ "rust-overlay_2": { "inputs": { "nixpkgs": [ - "nixpkgs-nixos" + "nixpkgs" ] }, "locked": { diff --git a/flake.nix b/flake.nix index 43f65402..dac2e853 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ inputs.advisory-db.flake = false; inputs.advisory-db.url = "github:rustsec/advisory-db"; inputs.crane.url = "github:ipetkov/crane"; - inputs.fenix.inputs.nixpkgs.follows = "nixpkgs-nixos"; + inputs.fenix.inputs.nixpkgs.follows = "nixpkgs"; inputs.fenix.url = "github:nix-community/fenix"; inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.macos-sdk.url = "https://github.com/roblabla/MacOSX-SDKs/releases/download/macosx14.0/MacOSX14.0.sdk.tar.xz"; @@ -27,9 +27,8 @@ inputs.nix-filter.url = "github:numtide/nix-filter"; inputs.nix-log.url = "github:rvolosatovs/nix-log"; inputs.nixlib.url = "github:nix-community/nixpkgs.lib"; - inputs.nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-24.05-darwin"; - inputs.nixpkgs-nixos.url = "github:nixos/nixpkgs/nixos-24.05"; - inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs-nixos"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; inputs.rust-overlay.url = "github:oxalica/rust-overlay"; outputs = inputs: let diff --git a/lib/mkFlake.nix b/lib/mkFlake.nix index 5db22a0a..43a6b500 100644 --- a/lib/mkFlake.nix +++ b/lib/mkFlake.nix @@ -2,8 +2,7 @@ self, flake-utils, nixlib, - nixpkgs-darwin, - nixpkgs-nixos, + nixpkgs, ... }: { defaultExcludePaths, @@ -61,11 +60,7 @@ with self.lib; ( system: let pkgs = - import ( - if system == aarch64-darwin || system == x86_64-darwin - then nixpkgs-darwin - else nixpkgs-nixos - ) { + import nixpkgs { inherit overlays system diff --git a/lib/rust/defaultPkgsFor.nix b/lib/rust/defaultPkgsFor.nix index 9a363a45..1caf0f48 100644 --- a/lib/rust/defaultPkgsFor.nix +++ b/lib/rust/defaultPkgsFor.nix @@ -2,8 +2,7 @@ { self, flake-utils, - nixpkgs-darwin, - nixpkgs-nixos, + nixpkgs, ... }: with flake-utils.lib.system; @@ -88,11 +87,7 @@ with self.lib.rust.targets; else if target == wasm32-unknown-unknown || target == wasm32-wasip1 then pkgs.pkgsCross.wasi32 else - import ( - if pkgs.stdenv.buildPlatform.isDarwin - then nixpkgs-darwin - else nixpkgs-nixos - ) { + import nixpkgs { crossSystem.config = if target == riscv64gc-unknown-linux-musl then "riscv64-unknown-linux-musl" From 58c672d14086891286bc4b1be8352c25396cdd09 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 21 Oct 2024 19:03:21 +0200 Subject: [PATCH 3/3] feat: switch to new Darwin SDK Signed-off-by: Roman Volosatovs --- flake.lock | 28 +++++++-------- flake.nix | 2 +- lib/rust/mkAttrs.nix | 84 ++++++++++++++++++-------------------------- 3 files changed, 50 insertions(+), 64 deletions(-) diff --git a/flake.lock b/flake.lock index e3cebf56..afb617f0 100644 --- a/flake.lock +++ b/flake.lock @@ -73,11 +73,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1729375822, - "narHash": "sha256-bRo4xVwUhvJ4Gz+OhWMREFMdBOYSw4Yi1Apj01ebbug=", + "lastModified": 1729492502, + "narHash": "sha256-d6L4bBlUWr4sHC+eRXo+4acFPEFXKmqHpM/BfQ5gQQw=", "owner": "nix-community", "repo": "fenix", - "rev": "2853e7d9b5c52a148a9fb824bfe4f9f433f557ab", + "rev": "4002a1ec3486b855f341d2b864ba06b61e73af28", "type": "github" }, "original": { @@ -161,7 +161,7 @@ "macos-sdk": { "flake": false, "locked": { - "lastModified": 1694769349, + "lastModified": 1693509154, "narHash": "sha256-TEvVJy+NMPyzgWSk/6S29ZMQR+ICFxSdS3tw247uhFc=", "type": "tarball", "url": "https://github.com/roblabla/MacOSX-SDKs/releases/download/macosx14.0/MacOSX14.0.sdk.tar.xz" @@ -323,16 +323,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1729265718, - "narHash": "sha256-4HQI+6LsO3kpWTYuVGIzhJs1cetFcwT7quWCk/6rqeo=", + "lastModified": 1729519136, + "narHash": "sha256-6/hRRcendHWPsRHwrQD692XIJX/qKE+RQtUlk+7kbbE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ccc0c2126893dd20963580b6478d1a10a4512185", + "rev": "3576b958e4397bcfbf8d664286fca8f418c906be", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixpkgs-unstable", + "ref": "staging", "repo": "nixpkgs", "type": "github" } @@ -354,11 +354,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1729255720, - "narHash": "sha256-yODOuZxBkS0UfqMa6nmbqNbVfIbsu0tYLbV5vZzmsqI=", + "lastModified": 1729454508, + "narHash": "sha256-1W5B/CnLgdC03iIFG0wtawO1+dGDWDpc84PeOHo2ecU=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "72b214fbfbe6f7b95a7877b962783bd42062cc0a", + "rev": "9323b5385863739d1c113f02e4cf3f2777c09977", "type": "github" }, "original": { @@ -419,11 +419,11 @@ ] }, "locked": { - "lastModified": 1729391507, - "narHash": "sha256-as0I9xieJUHf7kiK2a9znDsVZQTFWhM1pLivII43Gi0=", + "lastModified": 1729477859, + "narHash": "sha256-r0VyeJxy4O4CgTB/PNtfQft9fPfN1VuGvnZiCxDArvg=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "784981a9feeba406de38c1c9a3decf966d853cca", + "rev": "ada8266712449c4c0e6ee6fcbc442b3c217c79e1", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index dac2e853..85b10e8b 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ inputs.nix-filter.url = "github:numtide/nix-filter"; inputs.nix-log.url = "github:rvolosatovs/nix-log"; inputs.nixlib.url = "github:nix-community/nixpkgs.lib"; - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/staging"; inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; inputs.rust-overlay.url = "github:oxalica/rust-overlay"; diff --git a/lib/rust/mkAttrs.nix b/lib/rust/mkAttrs.nix index 0a34cd22..1e375a05 100644 --- a/lib/rust/mkAttrs.nix +++ b/lib/rust/mkAttrs.nix @@ -334,21 +334,9 @@ with self.lib.rust.targets; # Removing vendor references here invalidates the signature, which is required on aarch64-darwin doNotRemoveReferencesToVendorDir = true; } - // optionalAttrs pkgsCross.stdenv.hostPlatform.isDarwin { - preBuild = '' - export SDKROOT="${macos-sdk}" - ''; - - # Use `rust-lld` linker for Darwin targets - "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "rust-lld"; - } // ( - if final.stdenv.buildPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin - then { - # use defaults for Darwin-to-Darwin builds - } # Use Zig C compiler and `rust-lld` linker for Darwin targets on non-Darwin platforms - else if pkgsCross.stdenv.hostPlatform.isDarwin + if !final.stdenv.buildPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin then { depsBuildBuild = [ crossZigCC @@ -358,51 +346,49 @@ with self.lib.rust.targets; crossZigCC ]; - preBuild = - '' - export HOME=$(mktemp -d) - '' - + optionalString pkgsCross.stdenv.hostPlatform.isDarwin '' - export SDKROOT="${macos-sdk}" - ''; + preBuild = '' + export HOME=$(mktemp -d) + export SDKROOT="${macos-sdk}" + ''; "CC_${target}" = "${target}-zigcc"; "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "rust-lld"; } else - ( - { - depsBuildBuild = - [ - pkgsCross.stdenv.cc - ] - ++ optional pkgsCross.stdenv.hostPlatform.isWindows pkgsCross.windows.pthreads; - - disallowedReferences = [ + { + depsBuildBuild = + [ pkgsCross.stdenv.cc - ]; + ] + ++ optional pkgsCross.stdenv.hostPlatform.isWindows pkgsCross.windows.pthreads; - "AR_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}ar"; - "CC_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; - } - # Use `mold` linker for Linux targets - // optionalAttrs pkgsCross.stdenv.hostPlatform.isLinux { - nativeBuildInputs = [ - final.mold - ]; + disallowedReferences = [ + pkgsCross.stdenv.cc + ]; - "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Clink-arg=-fuse-ld=mold"; - } - # Always build static binaries for Windows targets - // optionalAttrs pkgsCross.stdenv.hostPlatform.isWindows { - "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Ctarget-feature=+crt-static"; - } - # Use default linker for Wasm targets - // optionalAttrs (!pkgsCross.stdenv.hostPlatform.isWasm) { - "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; - } - ) + "AR_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}ar"; + "CC_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; + } + # Use `mold` linker for Linux targets + // optionalAttrs pkgsCross.stdenv.hostPlatform.isLinux { + nativeBuildInputs = [ + final.mold + ]; + + "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Clink-arg=-fuse-ld=mold"; + } + # Always build static binaries for Windows targets + // optionalAttrs pkgsCross.stdenv.hostPlatform.isWindows { + "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Ctarget-feature=+crt-static"; + } + // optionalAttrs pkgsCross.stdenv.hostPlatform.isDarwin { + "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "rust-lld"; + } + # Use default linker for Wasm targets + // optionalAttrs (!pkgsCross.stdenv.hostPlatform.isWasm) { + "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; + } ) // optionalAttrs (final.stdenv.buildPlatform.config != pkgsCross.stdenv.hostPlatform.config) ( {