Installing only packages explicitly listed

I’m trying to test flakes and nixosConfigurations on a non-NixOS system. I’ve created a flake:

{
  inputs = {
  };

  outputs = { nixpkgs, ... }@inputs: {
    nixosConfigurations = {
      joke = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./hardware-configuration.nix
        ];
      };
    };
  };
}

I tried running this:

$ nix -L build .#nixosConfigurations.joke.config.system.build.toplevel --dry-run 2>&1|wc -l
1697

which as expected tries to build the whole NixOS system.

Is there a way for me to trim this down? I.e. tell it not to install any packages except those I explicitly told it to install in the configuration (and perhaps some that are absolutely necessary). I assume there’s some default list of packages somewhere that I should turn off or something.

Probably not as thorough as you want, but take a look at environment.defaultPackages.

Thanks @aanderse - unfortunately, adding these two:

environment.defaultPackages = lib.mkForce [];
environment.systemPackages = lib.mkForce [];

reduced it only to:

$ nix -L build .#nixosConfigurations.joke.config.system.build.toplevel --dry-run 2>&1|wc -l
1573

That’s still way too much…

Keep in mind many derivations are not packages in the traditional sense. That number is going to need to be fairly high just to have a nixos system at all. Every config file, random glue script that holds bits of things together, etc, is going to get its own derivation, generally.

Many such derivations are trivial to build and store, so the number of them is not really indicative of the amount of work involved.

@tejing My problem is that when I do the above without --dry-run it starts downloading packages and says it will download ~2G and install more than 2x that - here’s a snapshot:

[0/1576 built, 1/37/677 copied (4.9/4805.7 MiB), 5.0/2343.7 MiB DL] fetching List-Compare-0.55.tar.gz from https://cache.n

I’m looking for a way to avoid all that if possible.

It does only download packages installed/mentioned/configured.

If you used 22.05 before then of course there will be quite a lot of downloads now that you switch to unstable.

If you used unstable before, you haven’t updated in a while and the same amount of downloads would happen on a regular update.

I’m updating daily, and I get a 2+GiB downlaod at least once a week. At least one 5+ a month.

This is unstable life.

If you don’t want that stick to stable.

An OS is an OS… they take up space. Pretty much any linux distro is going to take up multiple gigabytes on disk these days. I don’t think you can get around that.

1 Like

It does only download packages installed/mentioned/configured.

Apparently it is downloading way more than I explicitly configured, because I configured none :slight_smile: So either I’m not doing this right or there must be a default somewhere. If there’s a way to explicitly tell it to not install anything and start building from there, I’d like to explore that.

If you don’t want that stick to stable.

I don’t see this as a stable / unstable issue. I’m on a non-NixOS OS and just running nix to test the configuration. I’m trying to get it to build the smallest subset possible basically.

I.e. I want to build the smallest possible NixOS system + whatever select packages I’m currently interested in while doing the building itself outside of NixOS, if that makes sense.

Pretty much any linux distro is going to take up multiple gigabytes on disk these days. I don’t think you can get around that.

That really depends on what you need, no? Take Ubuntu images as an example:

ubuntu-core-22-arm64+raspi.img.xz						2022-06-10 12:45	239M
ubuntu-22.04.1-preinstalled-server-armhf+raspi.img.xz	2022-08-09 12:08	884M
ubuntu-22.04.1-preinstalled-desktop-arm64+raspi.img.xz	2022-08-09 14:15	2.0G

So, depending on what you need, there’s almost an order of magnitude difference in size.

I understand why NixOS by default wants to build a lot of packages, that’s a sensible default. I’m looking to trim that down as much as possible basically. To take Ubuntu example, I’d like to go from the 2G desktop to 240M core (and even further if possible!), as for this particular testing I don’t care about most of the packages.

Then you need to explicitely disable some of the convinience defaults.

Check the minimal ISO to see how they achieve it there.

Minimal iso will still be huge for their purposes. But yeah, they will need to disable more of the defaults since this is not really a goal of NixOS.


Minimal profile might help a bit:

Though environment.noXlibs option also overrides Nixpkgs packages so you will not be able to use binary cache for majority of those and most stuff will be broken.

Another thing you can try is to look at what derivations are in your build closure and then guess what module installs them:

nix-store --query --tree $(nix-instantiate -A outputs.nixosConfigurations.joke.config.system.build.toplevel)

and then stop loading them with disabledModules.

Finally, something like not-os might be a better choice for you than NixOS.

1 Like