Removing specific default packages in NixOS

Hi everybody,

I managed to figure out how to list default packages in NixOS installation:

nix repl

map (x: x.name) nixosConfigurations.myhost.config.environment.systemPackages

But I can’t figure out how to remove some. I want to use NixOS on tiny VPS and I think I can remove some packages like man-db.

Can anybody please tell me how to do it?

Is there a list of packages that are critical and shouldn’t be removed?

Thank you.

man-db can be removed with documentation.man-db.enable = false, or documentation.man.enable = false

Thank you. That is useful.

But I was really after an example how to remove any package. I’m not saying that I should remove sudo, perl, strace, rsync… But if I really wanted… How to do it? :wink:

You can use nixos-option command to view which modules define environment.systemPackages option, and then look into their source code to find out how to disable them. Or just grep the nixos/ directory in the Nixpkgs repo for the packages you want to remove to find those modules.

Thank you @jtojnar . Is it not possible to:

config = {

    environment.systemPackages = someFilteringCode config.environment.systemPackages

}

run some kind of map/filter code like in the example?

It might be technically possible with mkForce, but this is definitely not recommended

you can disable sudo with security.sudo.enable = false;
perl, strace, and rsync can be disabled with environment.defaultPackages

Understand.

So it is OK to add packages into environment.systemPackages list but to remove it, I should rather disable module that added the package in the first place.

Thanks!