swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.65k stars 1.31k forks source link

Add support for NixOS #7528

Open malaow3 opened 2 months ago

malaow3 commented 2 months ago

When trying to invoke sourcekit-lsp on Nix, I get an error:

2024-05-03 14:47:53.510 sourcekit-lsp[25781:4ffff6c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension

Is adding NixOS support a possibility / planned for the future?

ahoppen commented 2 months ago

Looks like we are not detecting NixOS as a Linux OS here: https://github.com/apple/swift-package-manager/blob/32442c6604bebdeac45e3433aa7690967bb1170c/Sources/PackageLoading/Platform.swift#L43-L53.

What does uname output on NixOS?

malaow3 commented 2 months ago

Here are the results:

uname
Linux

uname -a
Linux nixos 5.15.146.1-microsoft-standard-WSL2 apple/sourcekit-lsp#1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 GNU/Linux
ahoppen commented 2 months ago

Synced to Apple’s issue tracker as rdar://127491941

ahoppen commented 2 months ago

Interesting, that definitely is what we are expecting uname to return. In practice, the log message probably shouldn’t cause any issues because we’re falling back to using .so, which is correct for Linux.

Which version of SourceKit-LSP are you using? Ie. which Swift toolchain do you have installed? If it’s some Swift 5 version, could you try if the issue still reproduces with a Swift 6 development snapshot from https://www.swift.org/download/#swift-60-development? I’ve made a lot of improvements to SourceKit-LSP during the Swift 6 development cycle and I vaguely remember seeing that log message before but can’t remember when or if I fixed it.

malaow3 commented 2 months ago

I can definitely give that a try, might take me a little bit to figure out how to get everything all set up though

ahoppen commented 2 months ago

Ah, I remember now: I was seeing a similar issue at some point because for some reasons (I can’t remember the details) uname was not in PATH. But that must have been a few years ago and fixed now, even though I don’t remember the fix.

The problem here is that we only detect debian and fedora as Linux distributions here

https://github.com/apple/swift-package-manager/blob/32442c6604bebdeac45e3433aa7690967bb1170c/Sources/PackageLoading/Platform.swift#L57-L77

With that information, it’s not necessary for you to test the Swift 6 snapshot since it also won’t have support for NixOS. I’ll move the issue over to SwiftPM because that’s where the platform detection logic lives.

malaow3 commented 6 days ago

Hey there was wondering if there's been any movement on this?