perrygeo
4 days ago
I've been trying to get a reasonable Linux-based audio setup on my desktop. Linux audio is a confusing disaster and I'd basically given up on Ubuntu, having run through so many debugging steps I had no idea how my system even got to this state.
I figured what the hell, let's try NixOS and see if I can set it up declaratively. At least that way if it fails, I have documentation about what exactly is failing.
I discovered the audio packages I needed easily enough. But things weren't great, there was occasional noticeable lag on the mic and midi devices. Ok, let's try to compile a realtime linux kernel... Wait there's an entire project dedicated to Nix audio setup! (https://github.com/musnix/musnix) After a few minutes integrating with my config, and about an hour to compile the kernel. Rebooted and bam. It's almost like working with analog in terms of perceivable lag.
I know this says more about Musnix than Nix, but I think it highlights the advantages of configuring your system with a real programming language. All the "audio stuff" was able to fit behind a well-designed abstraction barrier.
Going back to a "do this, now do this" tutorial feels like the dark ages. The only thing keeping me from going all-in on Nix is that it's package management strategy starts bleeding into your software project's dependency management. This is a huge problem IMO, I can't run C/C++ or Python projects the "old way" and no one is willing to upend their build system and lock it into nix. Some languages work great and allow a clean barrier between system<>app. I use Clojure, Rust, Gleam, Go, Lua on nix without any issues, it does seem to be the C/C++ ecosystem and dynamic linked shared libraries that are the problem.
codethief
4 days ago
> This is a huge problem IMO, I can't run C/C++ or Python projects the "old way" and no one is willing to upend their build system and lock it into nix.
For Python I use uv to download & set up Python binaries outside Nix. To make them work I enabled nix-ld in my Nix config, so there's a default linker & libc they can access. Works well so far.
grep_name
4 days ago
C/C++ is a PITA and I'm not a C/C++ developer, but I do find that I'm able to get around the issue 90% of the time using steam-run (although that feels kludgy as hell and I really wish there were a better option for getting linked libraries working normally). I think the real answer is to get good enough with nix to build a flake quickly for the project you're working with, but that seems like a lot to learn. Maybe easier if you're more familiar with C/C++ dependencies and build tools than me though.
Musnix looks really interesting. My whole audio setup looks like this in my nixconfig:
hardware.pulseaudio.enable = false;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
jack.enable = true;
};
hardware.bluetooth.enable = true;
hardware.bluetooth.powerOnBoot = true;
services.blueman.enable = true;
This works great for my workflow of using headphones + BT 100% of the time, but weirdly it almost never works for the built-in speakers on my framework. I might try musnix if that ever bothers me, but it's actually kind of a feature for me since my laptop can never just start blaring whatever I was watching / listening to into publicnextos
4 days ago
FWIW, I think pipewire has been enabled by default for some time in Nix right now?
Cloudef
4 days ago
nix-ld is the better way
grep_name
4 days ago
This looks interesting, just speed-read the readme. Is there a way to use this from the commandline, similar to steam-run, if you're just trying to sloppily check out some repo without building a whole flake?
Cloudef
3 days ago
It only works with nixos, it replaces the system ld that normally says "nix cant run dynamic binaries blah blah". Not sure if you can run it as cli tool.
jjmarr
4 days ago
> I think the real answer is to get good enough with nix to build a flake quickly for the project you're working with
I just have AI do it. Any of the coding assistants with terminal access can write and test flakes for you.
grep_name
4 days ago
I tried doing it for awhile but wasn't able to ever get it to work for the main project I was trying to build, which was a VR project called LÖVR. I could have made and submitted a package using one of their appimage releases, but was doing it as an exercise to see how far I could push things.
I also went through a phase where I had AI write a lot of simpler flakes, but they turned out surprisingly different from each other, enough so that I wasn't able to learn a pattern as a base to grok what was happening. At some point I'll try again from first principles, but for some reason the AI flakes hindered more than helping
jjmarr
4 days ago
I don't bother with flakes I just create ephemeral nix shells and a `shell.nix` with the dependencies.
riehwvfbk
4 days ago
It's most likely not C/C++ per se, but rather the eleventy billion ways different projects build these libraries.
Bazel for example builds everything in a well-contained sandbox and it all works, but only for the C/C++ libraries it builds natively. The magic ingredient is RPATH, but most Makefiles do not set it. However, one can add an extra build step with patchelf and inject an RPATH.
jchw
4 days ago
> This is a huge problem IMO, I can't run C/C++ or Python projects the "old way" and no one is willing to upend their build system and lock it into nix. Some languages work great and allow a clean barrier between system<>app. I use Clojure, Rust, Gleam, Go, Lua on nix without any issues, it does seem to be the C/C++ ecosystem and dynamic linked shared libraries that are the problem.
Depending on your individual use case you might find it sufficient to simply work on and compile software inside of Distrobox. It integrates nicely enough with the host system I think.
Personally, I usually do a small bit of hackery to get a good dev environment for C++ projects, using a combination of flakes and envrc. It's not exactly elegant, but you can re-use the Nixpkgs derivation for the actual dev shell. If you need to, you can even reuse the Nix patchPhase from the real derivation to apply NixOS-specific patches to your local tree temporarily.
The fact that it's possible to get a decent experience with not really that much effort kind of signals to me that it probably could be a lot better. On the other hand, maybe in a better Nix world, Nix could become even more integrated into both the dev and build process: with dynamic derivations the build process could be broken up into many smaller derivations and give Bazel-like behavior.
One thing I really enjoy about Nix is how easy it is to have different shells to use for different things without needing to pollute the system with tons of packages you needed for only one thing, but on the other hand the rest of the world doesn't integrate perfectly with this. For example, a lot of GUI text editors manage their own processes, so you can't just start a new window already inside of a shell. For VS Code derivatives the envrc extension kind of works, but it's a bit of a hack. A good improvement would be developer tools explicitly supporting this model, and as Nix seems positioned to continue to be gradually more relevant over time, I am hopeful it will become important enough for tools like VS Code to consider.
I have had a decent time, though. I have a mostly automated approach to getting working clangd and incremental compilation with pretty much any project, with just a little bit of mucking about with boilerplate.
whateveracct
4 days ago
> I know this says more about Musnix than Nix, but I think it highlights the advantages of configuring your system with a real programming language. All the "audio stuff" was able to fit behind a well-designed abstraction barrier.
I think it's a testament to Nix's promise. Abstraction with capital A!
MuffinFlavored
4 days ago
> Linux audio is a confusing disaster and I'd basically given up on Ubuntu
Have you considered buying a MacBook and valuing your free time more?
rowanG077
3 days ago
Pretty wild to say osx and valuing free time. Everytime I have to do anything that is one millimeter of the beaten path it turns into a momentous time sink. And than more often than not you figure it's impossible to do what you want.
MuffinFlavored
3 days ago
You're lying to yourself if you think people spend time playing with audio drivers/configuration to get sound working on Mac.
rowanG077
3 days ago
Drivers? No. Audio config? Most definitely. I would actually say the same on linux. By a significant margin no audio linux person is out there developing custom drivers for their stuff. Stuff just works OOB. It's more the userspace stuff that is problematic on either platform. With the caveat that latency issues have spiked A LOT on OSX in more recent years. Whereas on linux this mostly solved.
uselesswords
3 days ago
Some of us also value having freedom in what we use for the majority of our day.