I’m trying to package the dark-mode CLI utility using Nix tools, and I feel defeated.
It’s a tiny little Swift app, but I just don’t have enough knowledge of how Apple’s SDKs, Swift, Xcode, etc work to be able to make the thing build.
Also, I know there’s a lot of active development around making Darwin better on Nix, so maybe things have changed and I wouldn’t even really know where to start. I see there’s some work on Qt and MoltenVK, but those look like huge efforts.
I’m curious if this little example of a program might be a good toy-ish package to help guide others in making Nix better on Mac?
@reckenrode or @emily I know y’all are busy with amazing work, so pardon the ping if you’ve got better stuff to do. But all signs point to you two being the super experts here, and I wonder if you’d be interested in helping.
Do you have a build log where it’s failing to build or a gist with the current derivation?
The current situation with Swift is not great. The version in nixpkgs is old, and there are some non-obvious things you have to do sometimes to get things to build (such as using swiftPackages.stdenv instead of stdenv). There are also some bugs (such as missing CUPS headers breaking the AppKit module).
I was able to build dark-mode using my WIP Swift update branch mentioned here. There are a few non-obvious things (probably due to its using an Xcode project instead of a Package.swift file).
It defaults to a very old deployment target. I had to update it using substituteInPlace in postPatch;
It needs to link libswiftCore.dylib to fix missing symbols. I added it manually to NIX_LDFLAGS;
xcbuild does not support installation targets, so I needed a custom build phase to install the dark-mode binary.
Gist is here if you’re interested. Let me know if you have any questions.
Thanks for the detailed and helpful reply! I used the gist you provided to try building, but (as you predicted), it didn’t build. I’ll include the logs below, but it does seem like there’s some kind of version mismatch with the Swift compiler. Here’s a gist with the build log.
I’m trying to use your branch to build it on my machine, but it’s taking a terribly long time to build everything.
Alright, everything finally stopped building, but I think I’m running into those CUPS errors you mentioned, and I can’t figure out how to fix them. Here’s a gist with the log output from the build, if it helps.
Also, here’s a link to the commit in my flake where I tried these changes out. Just in case I’ve gotten something else wrong about the context here.
Master requires using swiftPackages.stdenv instead of a regular stdenv. The Swift update will change things to use a regular stdenv because this error is a common issue.
My branch targets staging, which has not yet been built by Hydra yet. There is sometimes a stdenv built, but my branch makes changes to the stdenv and the SDK, which will cause a rebuild of Darwin.
Is it not picking up NIX_CFLAGS_LINK? Try setting NIX_LDFLAGS instead.