Hi everyone,
I have been building the full Swift 6.5 toolchain from source on NixOS: compiler, stdlib, CxxStdlib, libdispatch, and Foundation, with zero patches against upstream. The repo is a Nix flake plus a build script that handles the whole pipeline.
NixOS does not follow the FHS (no /usr/lib, no /lib), so most of the existing build documentation does not apply directly. The interesting part of this project was figuring out how to satisfy the build system's expectations without patching the toolchain itself, just by shaping the Nix environment correctly.
Current state: the test suite passes 257/260 with llvm-lit. The three failures are llvm_link_time_opt.swift, cdecl_official_run.swift / cdecl_implementation_run.swift.
Repo is here: GitHub - lucasly-ba/swift-nixos: Build the Swift toolchain from source on NixOS: compiler, stdlib, C++ interop and Foundation · GitHub
I built this mainly to get a working environment to start contributing to swiftlang/swift; a first PR is the next step for me. Happy to answer questions.
12 Likes
Do you think you could submit this to nixpkgs, which appears to be way behind right now ?
2 Likes
Yes you're right, it's pretty far behind. nixpkgs is still on swift-5.10.1-RELEASE so it's missing the whole 6.x line (6.0 up to 6.3.2), and I've been building 6.5-dev off main.
I'd like to help with this, but I should be honest about how my repo differs from what nixpkgs actually needs, because they're not really the same thing.
Mine is a nix develop dev shell, not a hermetic derivation. It builds main from source with no patches to the toolchain, but the only reason that works is that a dev shell is impure: it can shape the build environment at runtime (sysroot assembly, toolchain/SDK injection, that kind of thing). The nixpkgs derivation is basically the opposite: sandboxed, no network, pure inputs, and it already carries a bunch of patches. So porting my flake over isn't a version bump, it's rewriting all that runtime env-shaping as a proper hermetic derivation, which is a much bigger job and would probably need more patching than the zero I have now.
So I'd treat my repo more as a reference for how to get the build working on a non-FHS system without touching the toolchain, rather than something you can drop in.
That said, I'm up for taking it on, I'd just want to start from what's already there rather than reinventing it. So a couple of questions first:
Is anyone already working on moving nixpkgs swift to 6.x, or is there an open PR?
What's actually kept it on 5.10.1? Build-system churn across the 6.x releases, the patch set going stale, or just nobody having time?
I'm going to take a real run at this. Plan is to try reproducing the 6.x build inside a sandboxed derivation and report back what breaks.
2 Likes
lucasly-ba:
Is anyone already working on moving nixpkgs swift to 6.x, or is there an open PR?
No idea, talk to Stephan or Sam over there and see what they say.
lucasly-ba:
What's actually kept it on 5.10.1? Build-system churn across the 6.x releases, the patch set going stale, or just nobody having time?
I don't use NixOS, you'll have to ask them. I had some minimal contact with Stephan years ago, I suggest you get in touch with him on GitHub.
Thanks ! I will reach out to them
I think reckenrode is working on getting the bootstrap for 6.X working in nixpkgs and has opened a matrix channel to discuss development.
Edit: (Seems like you already had found it )
opened 08:36AM - 20 Sep 24 UTC
9.needs: package (update)
6.topic: swift
- Package name: swift
- Latest released version: 6
- [x ] Checked the [nixpkgs… pull requests](https://github.com/NixOS/nixpkgs/pulls)
**Notify maintainers**
@dtzWill @trepetti @dduan @Trundle @stephank
-----
Note for maintainers: Please tag this issue in your PR.
---
Add a :+1: [reaction] to [issues you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[issues you find important]: https://github.com/NixOS/nixpkgs/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc
https://www.swift.org/install/linux/debian/12/#versions
Swift also supports a static SDK now, it would be truly great to also have support for that.
After trying to update the package myself, I wonder if package updates were not simpler if we would just use the official swift build process instead of hacking together our own. The current version is hopelessly behind the official, with the release of cross-compiling targets such as the static SDK and WASM, which are both highly relevant, it would seem prudent to re-evaluate if `utils/update-checkout` and `utils/build-script` would not simplfy the process to a great extent.
2 Likes
Yes I have been in contact with him, im working on it right now haha thanks !
1 Like
toffaletti
(Jason Toffaletti)
June 23, 2026, 4:11am
8
Very excited by this. Being able to easily get a reproducible dev environment with nix really lowers the barrier to contribution for OSS. The maintenance cost is high, but hopefully worth it.
2 Likes
First bringing Swift 6.x to nixpkgs, then keeping this flake and other packages maintained ! Does Anyone know good places to share this kind of work to get more people involved in Swift on NixOS?
reckenrode
(Randy Eckenrode)
August 30, 2026, 3:47am
10
FWIW, I have an account and can be pinged here.
It took a bit longer than expected, but the PR is up for the 6.2 update. After that, 6.3 (or 6.4) should follow quickly.
staging ← reckenrode:swift-6.2-update
opened 03:42AM - 30 Aug 26 UTC
This has been a long time coming. I seem to have a knack for volunteering to do … big rewrites (the Darwin stdenv, the SDK, and now Swift). 😅
I apologize this took so long. As I [discussed](https://bsky.app/profile/winter.bsky.social/post/3mnd7luaotk2h) on Bluesky, it was a cycle of burnout and long cycles. However, it’s ready, and the foundation is set to make Swift easier to use in Nixpkgs and easier to update and maintain.
I want to thank everyone who joined https://matrix.to/#/%23nixpkgs-swift:matrix.org as well as here and on Discourse who tested, reviewed, and/or provided feedback (@jen20, @booxter, and others). I also want to thank and @lucasly-ba in particular for demonstrating that it is possible to build Swift from an usptream toolchain using a sysroot even if that turned out not to have the right set of trade-offs for building Swift in Nixpkgs.
## And now for the changes themselves …
This PR is a rewrite of the Swift packaging and an update of Swift to Swift 6.2.4. It replaces the single `compiler` derivation that builds LLVM and Swift together with several that build everything separately. The Swift LLVM fork leverages the LLVM packaging already done in Nixpkgs. The Swift bootstrap is now implemented in Nix. The stdlib has been split out into its own package. It should interact with Nixpkgs tooling much better than before.
For the most part, it is compatible with the old Swift packaging except as noted in the packaging changes listed below.
https://www.swift.org/blog/announcing-swift-6/
https://www.swift.org/blog/swift-6.1-released/
https://www.swift.org/blog/swift-6.2-released/
**Note:** This PR has a large number of changes because I wanted to land each part of the rewrite as it is needed, but I also did not want to break eval or existing builds. Until 0c7f9f2589960bd52ffcf4a1186c4fb907e50167, the default Swift is 5.10.1. I confirmed every commit evals using the following `jj run` invocation. It took a while, but it confirmed no evaluation errors. I confirmed that new packages built by doing `jj new <change-id>` and then manually `nix build`ing them.
$ jj run --jobs 4 --clean --root --ignore-changes -r staging@upstream..swift-6.2-update -- nix-build ci -A eval.baseline --no-out-link --arg evalSystems '["aarch64-darwin" "aarch64-linux" "x86_64-linux"]' --system x86_64-linux
## Changes to packaging
- `swiftPackages.swift` is now a Swift toolchain. It is no longer wrapped. This is a **breaking change**, but it’s likely not one that most packages will notice.
- `swiftPackages.swift` now has (more) tests. Yay, tests!
- Packages for `Dispatch`, `Foundation`, and `XCTest` have been moved to their upstream names. The old names are available as aliases. Cleanup was done to prevent warnings (and eval failures in CI) in Nixpkgs.
- The Swift stdlib is now available as `swiftPackages.stdlib`. The stubs and modules have been removed from the Darwin SDKs. To build Swift applications, you must use the stdlib package, which is part of the toolchain.
- It is no longer necessary to use a custom `stdenv` when building Swift packages. This was a common footgun. The default `stdenv` will just work because Swift finds and uses `clang` in the toolchain.
- Swift is bootstrapped in Nix. This is because (as noted in the commit messages) the bootstrap build doesn’t work on Darwin, but it also prepares for using the Swift 6.2 compiler to bootstrap subsequent versions of Swift.
- A `fetchSwiftPMDeps` FOD has been added to make packaging Swift dependencies a lot easier. In most cases, you don’t have to do anything. Just add it to your package, and the dependencies will be made available.
Other than `age-plugin-se`, which used a custom vendoring method, I did not convert any packages outside of the Swift package set to use `fetchSwiftPMDeps`. `swiftpm2nix` is still supported and works. It was updated to use the same vendoring method as `fetchSwiftPMDeps`. Maintainers who would prefer to use `fetchSwiftPMDeps` can update their packages accordingly once this is merged.
## Limitations
- Cross-compilation is not implemented. It’s also not currently implemented, so this is not a regression.
- Some Darwin frameworks require macro dylibs shipped with Xcode. These are not available. Notable users are AppleIntelligence, Swift Data, and SwiftUI in the 27.0 SDK (not available yet in Nixpkgs, but it will be soon).
- I have included a patch to build libdispatch on Musl, but Swift assumes that Musl is static, which is not true in Nixpkgs. Work will be required to support Musl as a non-static platform.
## Future directions
- Once this is open, I plan to start working on the Swift 6.3.2 update (or Swift 6.4 if the release is out by then). It will leverage the Swift 6.2 compiler to bootstrap the new release.
- Packages that are independent of the compiler have update scripts. The toolchain does not have an updater. I will be adding it as part of the Swift 6.3.2 update.
- Cross-compilation needs to be implemented, which I want to use to support the WASM and Android SDKs.
- Determine whether https://github.com/NixOS/nixpkgs/issues/243681, https://github.com/NixOS/nixpkgs/issues/242779, and https://github.com/NixOS/nixpkgs/issues/331943 are still issues.
## Fixes/closes
- Fixes https://github.com/NixOS/nixpkgs/issues/311565
- Closes https://github.com/NixOS/nixpkgs/issues/343210
- Fixes https://github.com/NixOS/nixpkgs/issues/346866
- Fixes https://github.com/NixOS/nixpkgs/issues/379859
## Things done
- Built on platform:
- [x] x86_64-linux
- [ ] aarch64-linux
- [x] aarch64-darwin
- Tested, as applicable:
- [ ] [NixOS tests] in [nixos/tests].
- [x] [Package tests] at `passthru.tests`.
- [ ] Tests in [lib/tests] or [pkgs/test] for functions and "core" functionality.
- [ ] Ran `nixpkgs-review` on this PR. See [nixpkgs-review usage].
- [x] Tested basic functionality of all binary files, usually in `./result/bin/`.
- Nixpkgs Release Notes
- [x] Package update: when the change is major or breaking.
- NixOS Release Notes
- [ ] Module addition: when adding a new NixOS module.
- [ ] Module update: when the change is significant.
- [x] Fits [CONTRIBUTING.md], [pkgs/README.md], [maintainers/README.md] and other READMEs.
- [x] Follows the [automation/AI policy].
[NixOS tests]: https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests
[Package tests]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests
[nixpkgs-review usage]: https://github.com/Mic92/nixpkgs-review#usage
[CONTRIBUTING.md]: https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md
[automation/AI policy]: https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#automationai-policy
[lib/tests]: https://github.com/NixOS/nixpkgs/blob/master/lib/tests
[maintainers/README.md]: https://github.com/NixOS/nixpkgs/blob/master/maintainers/README.md
[nixos/tests]: https://github.com/NixOS/nixpkgs/blob/master/nixos/tests
[pkgs/README.md]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md
[pkgs/test]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/test
4 Likes