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.
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.
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.
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.
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?