KDE: Difference between revisions

From NixOS Wiki
imported>Flexagoon
No edit summary
Eliasp (talk | contribs)
m →‎Using a single diff from a remote URL: Fix formatting (command on separate line)
 
(62 intermediate revisions by 33 users not shown)
Line 1: Line 1:
[https://kde.org/de/plasma-desktop/ KDE Plasma] is a desktop environment that aims to be simple by default, powerful when needed.
== Installation ==
== Installation ==
=== Plasma 6 ===
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.xserver.desktopManager.plasma5.enable = true;
{
  services.xserver.enable = true; # optional
  services.displayManager.sddm.enable = true;
  services.displayManager.sddm.wayland.enable = true;
  services.desktopManager.plasma6.enable = true;
}
</nowiki>}}
</nowiki>}}


== Enable GTK themes in KDE ==
=== Plasma 5 ===


=== Enable GTK themes in KDE in KDE System Settings ===
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  services.xserver.enable = true;
  services.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma5.enable = true;
}
</nowiki>}}


Nixpkgs now provides the GTK configuration module for KDE system settings, which you can install with:
== Configuration ==


<syntaxhighlight lang="console">$ nix-env -i kde-gtk-config</syntaxhighlight>
=== Rootless X11 ===


You should also install any GTK themes you like. You can choose a GTK theme and set related options in <code>System Settings > Application Appearance > GTK</code>.
{{ic|sddm}} launches X11 as a root user by default. For better security, X11 can be run as a non-root user, but using Wayland is better tested and thus preferred:


=== Enable GTK themes in KDE manually ===
<syntaxHighlight lang=nix>
services.xserver.displayManager.sddm.settings.General.DisplayServer = "x11-user";
</syntaxHighlight>


As a normal nix user you can install the Oxygen GTK theme:
=== Excluding applications from the default install ===


<syntaxhighlight lang="console">$ nix-env -i oxygen-gtk</syntaxhighlight>
Some optional packages can be excluded if they are not needed at the cost of functionality.


KDE will run any scripts you place in ~/.kde/env on startup so this is a good place to set the GTK_PATH so that applications can find the theme engine. If the path is wrong/unset you will see errors like this:
==== Plasma 6 ====


<code>Gtk-WARNING **: Unable to locate theme engine in module_path</code>
Optional packages: [https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/desktop-managers/plasma6.nix#L136-L149 plasma6.nix]


To set Oxygen-GTK as the gtk theme create the following file and make it executable: ~/.kde/env/set-gtk-theme.sh
<syntaxHighlight lang=nix>
<syntaxhighlight lang="bash">
environment.plasma6.excludePackages = with pkgs.kdePackages; [
#!/bin/sh
  plasma-browser-integration
  konsole
  elisa
];
</syntaxHighlight>


export GTK_PATH=$GTK_PATH:~/.nix-profile/lib/gtk-2.0
==== Plasma 5 ====
export GTK2_RC_FILES=$GTK2_RC_FILES:~/.nix-profile/share/themes/oxygen-gtk/gtk-2.0/gtkrc
 
Optional packages: [https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/x11/desktop-managers/plasma5.nix#L278-L282 plasma5.nix]
 
<syntaxHighlight lang=nix>
environment.plasma5.excludePackages = with pkgs.libsForQt5; [
  plasma-browser-integration
  konsole
  oxygen
];
</syntaxHighlight>
 
=== GNOME desktop integration ===
 
Using the following example configuration, QT applications will have a look similar to the [[GNOME]] desktop, using a dark theme.
 
<syntaxhighlight lang="nix">
qt = {
  enable = true;
  platformTheme = "gnome";
  style = "adwaita-dark";
};
</syntaxhighlight>
</syntaxhighlight>


Alternatively, on NixOS:
For other themes, you may need the packages <code>libsForQt5.qt5ct</code> and <code>libsForQt5.qtstyleplugin-kvantum</code> and a symlink from <code>~/.config/Kvantum/</code> to your theme package. Here is an example using Arc-Dark and [[Home Manager]]. In the Home Manager configuration:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment = {
qt = {
   systemPackages = [ pkgs.oxygen_gtk ];
   enable = true;
   shellInit = ''
  platformTheme = "qtct";
    export GTK_PATH=$GTK_PATH:${pkgs.oxygen_gtk}/lib/gtk-2.0
   style = "kvantum";
    export GTK2_RC_FILES=$GTK2_RC_FILES:${pkgs.oxygen_gtk}/share/themes/oxygen-gtk/gtk-2.0/gtkrc
};
  '';
 
xdg.configFile = {
  "Kvantum/ArcDark".source = "${pkgs.arc-kde-theme}/share/Kvantum/ArcDark";
  "Kvantum/kvantum.kvconfig".text = "[General]\ntheme=ArcDark";
};
</syntaxhighlight>
 
For more details, see [https://discourse.nixos.org/t/guide-to-installing-qt-theme/35523/2 this] forum post.
 
=== Default Wayland/X11 session ===
 
==== Plasma 6 ====
 
Plasma 6 runs on Wayland by default. To launch an X11 session by default:
 
<syntaxHighlight lang=nix>
services.xserver.displayManager.defaultSession = "plasmax11";
</syntaxHighlight>
 
==== SDDM on Wayland ====
 
<syntaxHighlight lang=nix>
services.xserver.displayManager.sddm.wayland.enable = true;
</syntaxHighlight>
 
==== Plasma 5 ====
 
Plasma 5 runs on X11 by default and it is recommended to use Wayland with Plasma 6 instead. To launch a Wayland session by default anyway:
 
<syntaxHighlight lang=nix>
services.xserver.displayManager.defaultSession = "plasmawayland";
</syntaxHighlight>
 
== Troubleshooting ==
 
=== Qt/KDE applications segfault on start ===
 
This is caused by a stale QML cache [https://github.com/NixOS/nixpkgs/issues/177720 (see this issue)]. A dirty way to fix this is by running on a terminal the following command:
 
<syntaxHighlight lang=sh>
find ${XDG_CACHE_HOME:-$HOME/.cache}/**/qmlcache -type f -delete
</syntaxHighlight>
 
=== GTK themes are not applied in Wayland applications / Window Decorations missing / Cursor looks different ===
This affects GTK applications including Firefox and Thunderbird.
 
You may need to set a GTK theme ''Breeze'' imitating the KDE theme with the same name in ''System Settings -> Application Style -->Configure GNOME/GTK Application Style''.
 
[https://github.com/NixOS/nixpkgs/issues/180720 (See this issue)]
 
== Tips and tricks ==
 
=== Plasma-Manager ===
 
{{note|  [https://github.com/pjones/plasma-manager Plasma-Manager] is an unofficial community project and is not yet mature}}
By default, the Plasma configuration can be handled like on [https://wiki.archlinux.org/title/KDE traditional systems].
With [https://github.com/pjones/plasma-manager plasma-manager], it is possible to make Plasma configurations via nix by providing [https://github.com/nix-community/home-manager home-manager] modules.
 
=== User icon (avatar) ===
You can add a profile picture to your user by using a png file in <code>~/.face.icon</code>.
 
== Hacking ==
There are many reasons to modify the KDE packages, such as testing patches from other KDE developers, applying a fix before it is officially released and finds its way into ''nixpkgs'' or developing contributions for the KDE project.
 
=== Customizing ''nixpkgs'' ===
To override KDE packages, the common way using <code>overrideAttrs</code> won't work, since they are part of the <code>kdePackages</code>scope, which requires the usage of <code>overrideScope</code> first:<syntaxhighlight lang="nix">
nixpkgs-overlay = final: prev: {
  kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
    somepackage = kdePrev.somepackage.overrideAttrs(prevPkgAttrs: {
      someattribute = …;
    };
  };
};
};
</syntaxhighlight>The following examples will demonstrate various ways how to achieve the customization of the KDE package <code>powerdevil</code> in different scenarios:
==== Using a single diff from a remote URL ====
A KDE developer might have provided a diff that one wants to utilize locally to test it or to make use of it until it's included in an upcoming release.
# Generate the SRI hash of the file: <code>nix store prefetch-file <nowiki>https://invent.kde.org/plasma/powerdevil/-/commit/f731c18e377b87c57f7205d9c1812a34f588c577.diff</nowiki> --json --name toggle-nightlight.diff</code>
# Override the <code>patches</code> attribute of the <code>powerdevil</code>package:<syntaxhighlight lang="nix">
kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
  powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
    patches = prevPdAttrs.patches or [] ++ [
      (prev.fetchpatch {
        name = "toggle-nightlight.diff";
        url = "https://invent.kde.org/plasma/powerdevil/-/commit/f731c18e377b87c57f7205d9c1812a34f588c577.diff";
        sha256 = "sha256-X0ZHSRnSLqmp2fcLGx9DUTn7F9BFh5puh9Q4YAj6/5o=";
      })
    ];
  });
});
</syntaxhighlight>
==== Using commits of a repository ====
Either a local clone or remote repository might provide the code that should be used to build the package in question instead.
===== Remote repository =====
<syntaxhighlight lang="nix">
kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
  powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
    src = builtins.fetchGit {
      url = "https://invent.kde.org/plasma/powerdevil";
      rev = "f731c18e377b87c57f7205d9c1812a34f588c577";
    };
  });
});
</syntaxhighlight>
</syntaxhighlight>


Or alternatively, copy the themes folder in the home directory
===== Local repository =====
{{Note|This will ignore files that are present in the worktree, but not committed yet.}}
<syntaxhighlight lang="nix">
kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
  powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
    src = builtins.fetchGit {
      url = "file:///home/eliasp/code-repositories/public/KDE/plasma/powerdevil";
      rev = "f731c18e377b87c57f7205d9c1812a34f588c577";
    };
  });
});


<syntaxhighlight lang="console">
$ cp -R ~/.nix-profile/share/themes/ ~/.themes
</syntaxhighlight>
</syntaxhighlight>


[[Category:Desktop environments]]
==== Using the worktree of a local repository ====
Now one might not want to commit each and every change during development to iterate more quickly, but to just rebuild after having saved the latest changes.
 
By just redirecting <code>src</code>to the path of the working directory, where the required code resides, quick & dirty rebuilds are possible:<syntaxhighlight lang="nix">
kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
  powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
    src = /home/eliasp/code-repositories/public/KDE/plasma/powerdevil;
  });
});
 
</syntaxhighlight>
{{Note|Since this relies on reading directly from the filesystem during the build, the impure mode has to be used, e.g.: <code>nixos-rebuild --impure …</code>}}
[[Category:Desktop environment]]
[[Category:Applications]]
[[Category:KDE]]

Latest revision as of 20:21, 19 November 2024

KDE Plasma is a desktop environment that aims to be simple by default, powerful when needed.

Installation

Plasma 6

/etc/nixos/configuration.nix
{
  services.xserver.enable = true; # optional
  services.displayManager.sddm.enable = true;
  services.displayManager.sddm.wayland.enable = true;
  services.desktopManager.plasma6.enable = true;
}

Plasma 5

/etc/nixos/configuration.nix
{
  services.xserver.enable = true;
  services.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma5.enable = true;
}

Configuration

Rootless X11

sddm launches X11 as a root user by default. For better security, X11 can be run as a non-root user, but using Wayland is better tested and thus preferred:

services.xserver.displayManager.sddm.settings.General.DisplayServer = "x11-user";

Excluding applications from the default install

Some optional packages can be excluded if they are not needed at the cost of functionality.

Plasma 6

Optional packages: plasma6.nix

environment.plasma6.excludePackages = with pkgs.kdePackages; [
  plasma-browser-integration
  konsole
  elisa
];

Plasma 5

Optional packages: plasma5.nix

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

GNOME desktop integration

Using the following example configuration, QT applications will have a look similar to the GNOME desktop, using a dark theme.

qt = {
  enable = true;
  platformTheme = "gnome";
  style = "adwaita-dark";
};

For other themes, you may need the packages libsForQt5.qt5ct and libsForQt5.qtstyleplugin-kvantum and a symlink from ~/.config/Kvantum/ to your theme package. Here is an example using Arc-Dark and Home Manager. In the Home Manager configuration:

qt = {
  enable = true;
  platformTheme = "qtct";
  style = "kvantum";
};

xdg.configFile = {
  "Kvantum/ArcDark".source = "${pkgs.arc-kde-theme}/share/Kvantum/ArcDark";
  "Kvantum/kvantum.kvconfig".text = "[General]\ntheme=ArcDark";
};

For more details, see this forum post.

Default Wayland/X11 session

Plasma 6

Plasma 6 runs on Wayland by default. To launch an X11 session by default:

services.xserver.displayManager.defaultSession = "plasmax11";

SDDM on Wayland

services.xserver.displayManager.sddm.wayland.enable = true;

Plasma 5

Plasma 5 runs on X11 by default and it is recommended to use Wayland with Plasma 6 instead. To launch a Wayland session by default anyway:

services.xserver.displayManager.defaultSession = "plasmawayland";

Troubleshooting

Qt/KDE applications segfault on start

This is caused by a stale QML cache (see this issue). A dirty way to fix this is by running on a terminal the following command:

find ${XDG_CACHE_HOME:-$HOME/.cache}/**/qmlcache -type f -delete

GTK themes are not applied in Wayland applications / Window Decorations missing / Cursor looks different

This affects GTK applications including Firefox and Thunderbird.

You may need to set a GTK theme Breeze imitating the KDE theme with the same name in System Settings -> Application Style -->Configure GNOME/GTK Application Style.

(See this issue)

Tips and tricks

Plasma-Manager

Note: Plasma-Manager is an unofficial community project and is not yet mature

By default, the Plasma configuration can be handled like on traditional systems. With plasma-manager, it is possible to make Plasma configurations via nix by providing home-manager modules.

User icon (avatar)

You can add a profile picture to your user by using a png file in ~/.face.icon.

Hacking

There are many reasons to modify the KDE packages, such as testing patches from other KDE developers, applying a fix before it is officially released and finds its way into nixpkgs or developing contributions for the KDE project.

Customizing nixpkgs

To override KDE packages, the common way using overrideAttrs won't work, since they are part of the kdePackagesscope, which requires the usage of overrideScope first:

nixpkgs-overlay = final: prev: {
  kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
    somepackage = kdePrev.somepackage.overrideAttrs(prevPkgAttrs: {
      someattribute = ;
    };
  };
};

The following examples will demonstrate various ways how to achieve the customization of the KDE package powerdevil in different scenarios:

Using a single diff from a remote URL

A KDE developer might have provided a diff that one wants to utilize locally to test it or to make use of it until it's included in an upcoming release.

  1. Generate the SRI hash of the file: nix store prefetch-file https://invent.kde.org/plasma/powerdevil/-/commit/f731c18e377b87c57f7205d9c1812a34f588c577.diff --json --name toggle-nightlight.diff
  2. Override the patches attribute of the powerdevilpackage:
    kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
      powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
        patches = prevPdAttrs.patches or [] ++ [
          (prev.fetchpatch {
            name = "toggle-nightlight.diff";
            url = "https://invent.kde.org/plasma/powerdevil/-/commit/f731c18e377b87c57f7205d9c1812a34f588c577.diff";
            sha256 = "sha256-X0ZHSRnSLqmp2fcLGx9DUTn7F9BFh5puh9Q4YAj6/5o=";
          })
        ];
      });
    });
    

Using commits of a repository

Either a local clone or remote repository might provide the code that should be used to build the package in question instead.

Remote repository
kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
  powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
    src = builtins.fetchGit {
      url = "https://invent.kde.org/plasma/powerdevil";
      rev = "f731c18e377b87c57f7205d9c1812a34f588c577";
    };
  });
});
Local repository
Note: This will ignore files that are present in the worktree, but not committed yet.
kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
  powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
    src = builtins.fetchGit {
      url = "file:///home/eliasp/code-repositories/public/KDE/plasma/powerdevil";
      rev = "f731c18e377b87c57f7205d9c1812a34f588c577";
    };
  });
});

Using the worktree of a local repository

Now one might not want to commit each and every change during development to iterate more quickly, but to just rebuild after having saved the latest changes.

By just redirecting srcto the path of the working directory, where the required code resides, quick & dirty rebuilds are possible:

kdePackages = prev.kdePackages.overrideScope(kdeFinal: kdePrev: {
  powerdevil = kdePrev.powerdevil.overrideAttrs (prevPdAttrs: {
    src = /home/eliasp/code-repositories/public/KDE/plasma/powerdevil;
  });
});
Note: Since this relies on reading directly from the filesystem during the build, the impure mode has to be used, e.g.: nixos-rebuild --impure …