How to exclude packages

Hello, I am trying to remove some packages that come with Plasma. this is my config

services.xserver = {
        desktopManager.plasma5.enable = true;
        displayManager = {
            sddm.enable = true;
            autoLogin.enable = true;
            autoLogin.user = "shalva";
            defaultSession = "plasma5";
        };
    };

But it comes with Spectacle and Khotkeys packages. how can I exclude them?

5 Likes

e.g. for Khotkeys
you could use an overlay / overrideAttrs
(you could import plasma/default.nix locally and add a parameter to (de)activate some code parts/packages)

im new to Nix, its been about 4 days since I have started learning it.

All the examples of overlays show modifying or adding other packages. Overlays are very confusing for me, its been a while but still cant figure out what does self: super: means, all I know is that it is a function with 2 arguments. Also cannot find plasma/default.nix, it seems to be just a package collection or something here and im not sure if that is the correct file but I hope so.

my current result is this(which is included inside configuration.nix), nixos-rebuild switch says overlay is already defined :confused:

{ pkgs, ...}:
let
	myPlasma = import <nixpkg/nixos/modules/services/x11/desktop-managers/plasma5.nix>;
        # this function should filter out just the khotkeys package and leave others... but I dont know...
	myPackageFilter = builtins.foldl' (a: b: if b == khotkeys then a else a ++ [ b ] ) [];

	myPlasma.overlay = [ (self: super: {
			super.environment.systemPackages.override = myPackageFilter environment.systemPackages;
		}
	) ];
in
{

    # Enable the X11 windowing system.
    services.xserver.enable = true;
    services.xserver.layout = "us";

    fonts.fontconfig.enable = true;

    environment.systemPackages = with pkgs; [
        vim nnn git bat ranger fish starship home-manager micro
        myPlasma
    ];

    # desktop stuff
    services.xserver = {
        # desktopManager.plasma5.enable = true;
        displayManager = {
            sddm.enable = true;
            autoLogin.enable = true;
            autoLogin.user = "shalva";
            defaultSession = "plasma5";
        };
    };
}

Overlays are very confusing for me, its been a while but still cant figure out what does self: super: means, all I know is that it is a function with 2 arguments.

I recommend final: prev. Thats also easier to explain. The first argument is nixpkgs with your overlay applied, and the second argument is nixpkgs without your overlay. So the “final” nixpkgs and the “previous” nixpkgs. This allows you to access things you defined in your overlay along with things from nixpkgs itself.

final: prev: { f = final.firefox; } would work, but final: prev: { f = prev.firefox; } would make more sense.

This could be useful:

final: prev: {
  firefox = prev.firefox.override { ... };
  myBrowser = final.firefox;
}

And final: prev: firefox = final.firefox.override { ... }; would cause infinite recursion.

3 Likes

thanks for your example, it is helpful.

But how do I actually use it? your firefox example seems simple but in my case it is
services.xserver.desktopManager.plasma5.enable = true; that installs the packages that I do not want.

I have tried that with import <nixpkgs/pkgs/desktop/plasma-5/default.nix> but that seems to be something else, here are some packages I want to exclude, Khotkeys and Spectacle are both there

Ohh sorry I was just addressing your comment on overlays. Your actual issue is separate and I don’t think overlays will be able to resolve it.

So services.xserver.desktopManager.plasma5.enable is part of NixOS, while pkgs.plasma is part of “nixpkgs” or the nixpkgs package set. Overlays directly affect pkgs, but that doesn’t always mean they affect NixOS.

NixOS is a collection of modules to create a nixos system. And the plasma module adds certain packages to environment.systemPackages. You cannot affect the setting of environment.systemPackages through the use of overlays, because its not a package but a module option. You can affect individual packages, but not the option as a whole.

You can, however change it within your configuration.nix(which is also a module) by setting environment.systemPackages there. But the issue is that the module system(the code which evaluates modules) always appends lists. So the setting of environment.systemPackages in the plasma module will only be appended to your setting of environment.systemPackages.

Thus, I don’t actually have a solution for you here. it might be possible, but I don’t know of any way to drop items added to a list in one module(plasma) from another module(configuration.nix).

1 Like

okay, I copied all that plasma5.nix to my configs and commented out packages that I do not want… and it works :smiley: except krunner and khotkeys, they are still there, maybe they are dependency for other packages, I dont know yet.

so lets hope my setup will not break… will create an issue on github, maybe they will add an option to exclude stuff.

1 Like

The WIKI currently has a section called " Excluding some KDE Plasma applications from the default install" and it seems to work pretty well for removing unwanted Plasma packages that were installed by default.
https://nixos.wiki/wiki/KDE
I added the suggested

environment.plasma5.excludePackages = with pkgs.libsForQt5; [
  plasma-browser-integration
  konsole
  oxygen
];

to my configuration.nix and it worked

1 Like