Converting NixOS to a (fully local-build) source distribution

What’s all this then?

I’ve seen multiple places where it’s mentioned that Nix{,OS}[1] can act as a source distribution where all building is done locally and no binaries are fetched online, but I had trouble finding search hits for what properties you set to ensure this occurs, so I am starting this thread to pull some loose ends together (puns about fabric threads unintended). Hopefully it helps others, and I can gain some agreement that I didn’t follow the wrong garden path.

Recap of The Noise

If it helps, I’d like to point out that there’s actually a significant amount of noise vs. signal when trying to find out how to do this. Here’s what I mean and some of my suggestions, for which I’d be interested to hear if anyone agrees with the suggestions:

Searching for threads did not immediately generate a clear solution

  1. A web search resulted in me finding the thread Is NixOS a source distro or a binary distro, or both? - NixOS Discourse among other threads, but there seem to be no threads talking about how to actually enforce NixOS to avoid binary downloads and rely on local buliding. I was going to post there, but this is now more of a “how can we make NixOS a fully local-build source distribution post” and that thread is old and the system gives me a warning about it, so I’m creating a new thread.
  2. Based on How to make a version compatable config for nix.binaryCaches or nix.settings.substituters?, it seems that you disable nix.binaryCaches somehow? I see the second property mentioned there, nix.settings.substituters, on the search, but not the other.

The NixOS wiki doesn’t yet return clear and helpful results for this question

  • Specifically, the NixOS wiki search for binary cache doesn’t return with much.
    The top page does seem to address substituters, but it would be great to see a section detailing how to explicitly disable all substituters, if for nothing else than improving searchability on this topic.
    • Especially if there’s no substituters.disable, then it’s worth pointing that out and detailing how to set the list to empty with an example, etc. The section could explain why you would or wouldn’t want to do this (could highlight the paranoid, binary-averse, or otherwise super-geek lifestyles).

The NixOS Option search for binary cache doesn’t yet returns clear results

It does have a lot of results, but none of them immediately look right or shout out at someone who doesn’t already know the answer.

  • If the substituters tip from above is true, then for searchability, I wager the word substituters needs to show up in far more places[2] in order to get that to be the term people search.
    • If still true, and there’s any way to promote that setting to number one, it would help. I’m not sure how the best match algorithm works.
  • The stable NixOS Manual’s nearest heading does provides a CLI option, but I’d want it in my system configuration file, permanently, so as not to forget or need to type it each time. I’d rather not get hacky with an alias or function for some sort of nixos-rebuild override.
    • There’s actually no mention of the word substituters in the whole unstable manual.

Request for Signal

So, I have some good stuff to try and dig into, but I may as well ask after having written up the notes…

  1. Is there an easy disable option to get Nix{,OS} to build everything locally? In the recent verbiage, is it the same to say “how do you disable substituters globally”?
  2. If not, do you just configure an empty substituters list?
  3. Have I missed the obvious web-pages where this is already discussed? Threads where this was hammered time and time again that I should have caught? If so, let’s get them linked here and future web-searchers may arrive to those instead.

Further Curiosities

So let’s say it’s just a matter of disabling the substituters and you are officially building locally.

What actually happens under the hood when you decide to switch to this? Is anyone already running a system this way? I expect NixOS may just grab tarballs and build them?

Setting the goal post

My goal is to have the source code repositories of all the software I use available locally, does NixOS or any other source distribution do that? If you’re familiar with the foo-git style packages in the AUR[3], that’s not far from what I’m imagining.

The system would have all software as some clone or meta-clone of the upstream repos, and the user would just git pull and make, more or less. Nix{,OS} still seems like it would serve this sort of need handily, and may already do it. I’ve recently come across Guix and it seems to be GNU flavored Nix that does something like this, but I’m still on the opening pages of the manual.

Any thoughts?

There’s a lot here so don’t fret to pick a tiny piece. I’m listening :ear:

Cheers.


Footnotes

  • [1] (both, either, I won’t distinguish here too much)
  • [2] (docs, wikis, searches, threads, etc. – oh, hey – look – I’m doing my part :laughing: )
  • [3] Sample: AUR (en) - whipper-git
2 Likes

What you’re looking for is the Nix configuration setting substitute. For the first run you should be able to pass it as a flag: nixos-rebuild switch --substitute false, since all additonal arguments go to Nix.

All the Nix options should be translated to NixOS module options, but maybe that’s not properly explained in the NixOS manual.

Thanks for pointing out the issue. I always wondered what the exact problem is with NixOS documentation, but didn’t have time to investigate it. Nix-related option documentation no not linking to the Nix manual, and no mention that there is a 1:1 mapping might indeed be a major factor in people being confused about where the boundaries lie.

4 Likes

Ah! That looks like the property!

So the CLI command should work, and I’m following you that I didn’t really get the mapping over to the NixOS module option. Is there a way to set it in configuration.nix for a NixOS system, too?

I’d definitely agree you bring up some great points I have been and am still a bit confused about regarding where the boundaries lie :smile:

1 Like

It seems there is no dedicated option, but you can put it in nix.extraOptions.

1 Like

Use nix.settings.substitute = false. The settings option allows setting arbitrary Nix options, see NixOS Search :slight_smile:

4 Likes

Excellent! I’ll give that a shot and mark as solved.

The theoretical extensions are still of interest to me. Does it work via nixpkgs -> tarball.gz -> tar zvxf -> make sort of flow?

I’m interested in getting the actual repos, like the AUR does, but I don’t think Nix{,OS} does this, correct?

I’m not exactly sure which question you’re asking here.

Will NixOS fetch all the source tarballs into the Nix store before building the system? Yes, if all URLs work. That’s one cool thing about the public cache: it keeps sources around even if upstream goes down.

Can you package up the entire system configuration and expand it somewhere else? Yes, along the lines of Copying Closures via SSH - Nix Reference Manual

nix-store --export $(nix-store --query --requisites /nix/var/nix/profiles/system) > nixos-system.closure

Can you do the same with just the sources? Sure:

nix-store --export $(nix-store --query --requisites $(nix-store --query --deriver /nix/var/nix/profiles/system)) > nixos-system.closure
3 Likes

No worries, you got the right answer for the question!

Nix goes for tarballs, not rich history source repos.
So, if I cd into those directories, I wouldn’t have entire git repos, just the one cut of the project.

I think that satisfies the further curiosities. If I wanted to have the full rich history of a given project, I still need to clone it.

This seems to works for nixos-rebuild switch! Thank you!

For home-manager, I need to use home-manager switch --no-substitutes independently of this setting, it appears. I don’t see anything in the code regarding that, so it might not be possible to set this extremely globally.

If anyone knows how to tell the Nix daemon more generally to never accept substitutes, that would be a good thing to tack on here, but the initial questions set is complete. :white_check_mark:

Thanks all :blush: