# Installing only packages explicitly listed

**URL:** https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048
**Category:** Help
**Created:** [September 27, 2022, 8:30pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048 "2022-09-27T20:30:12Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![cebaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cebaa/32/7431_2.png) [@cebaa](https://discourse.nixos.org/u/cebaa)
#### Post date: [September 27, 2022, 8:30pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/1 "2022-09-27T20:30:12Z")

</div>

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

```auto
{
  inputs = {
  };

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

```

I tried running this:

```auto
$ 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.

---

<div class="post-metadata">

### Author: ![aanderse](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aanderse/32/1420_2.png) [@aanderse](https://discourse.nixos.org/u/aanderse)
#### Post date: [September 28, 2022, 3:21am UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/2 "2022-09-28T03:21:04Z")

</div>

Probably not as thorough as you want, but take a look at [environment.defaultPackages](https://search.nixos.org/options?channel=22.05&from=0&size=50&sort=relevance&type=packages&query=environment.defaultPackages).

---

<div class="post-metadata">

### Author: ![cebaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cebaa/32/7431_2.png) [@cebaa](https://discourse.nixos.org/u/cebaa)
#### Post date: [September 28, 2022, 6:17pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/3 "2022-09-28T18:17:23Z")

</div>

Thanks @aanderse - unfortunately, adding these two:

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

```

reduced it only to:

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

```

That’s still way too much…

---

<div class="post-metadata">

### Author: ![tejing](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tejing/32/4566_2.png) [@tejing](https://discourse.nixos.org/u/tejing)
#### Post date: [September 29, 2022, 1:56pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/4 "2022-09-29T13:56:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![cebaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cebaa/32/7431_2.png) [@cebaa](https://discourse.nixos.org/u/cebaa)
#### Post date: [September 29, 2022, 2:58pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/5 "2022-09-29T14:58:11Z")

</div>

@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:

```auto
[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.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [September 29, 2022, 7:14pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/6 "2022-09-29T19:14:43Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![tejing](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tejing/32/4566_2.png) [@tejing](https://discourse.nixos.org/u/tejing)
#### Post date: [September 29, 2022, 7:18pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/7 "2022-09-29T19:18:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![cebaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cebaa/32/7431_2.png) [@cebaa](https://discourse.nixos.org/u/cebaa)
#### Post date: [September 30, 2022, 2:34pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/8 "2022-09-30T14:34:56Z")

</div>

> It does only download packages installed/mentioned/configured.

Apparently it is downloading way more than I _explicitly_ configured, because I configured none 🙂 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.

---

<div class="post-metadata">

### Author: ![cebaa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cebaa/32/7431_2.png) [@cebaa](https://discourse.nixos.org/u/cebaa)
#### Post date: [September 30, 2022, 2:49pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/9 "2022-09-30T14:49:34Z")

</div>

> 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](https://cdimage.ubuntu.com/) as an example:

```auto
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.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [September 30, 2022, 3:05pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/10 "2022-09-30T15:05:08Z")

</div>

> [@cebaa](#):
>
> I want to build the smallest possible NixOS system

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

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

---

<div class="post-metadata">

### Author: ![jtojnar](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jtojnar/32/70_2.png) [@jtojnar](https://discourse.nixos.org/u/jtojnar)
#### Post date: [September 30, 2022, 3:32pm UTC](https://discourse.nixos.org/t/installing-only-packages-explicitly-listed/22048/11 "2022-09-30T15:32:45Z")

</div>

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:

> <https://github.com/NixOS/nixpkgs/blob/a5a5849f27b5053b717bbf482f2897ded1126d5a/nixos/modules/profiles/minimal.nix>

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:

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

```

and then stop loading them with [`disabledModules`](https://nixos.org/manual/nixos/unstable/#sec-replace-modules).

Finally, something like [not-os](https://github.com/cleverca22/not-os) might be a better choice for you than NixOS.
