KDE Ni! OS – installing packages from source – Plasma Pass

Wait 5 sec.

KDE Ni! OS is acustom flavour of NixOS that showcasesKDE software. It builds on NixOS with the aim to reimplement the samefeatures other popular immutable distributions have while providing afirst-class KDE Plasma setup.This post will show the NixOS way of adding a custom packageand explain the benefits of this approach in the context of systemimmutability.Plasma PassKDE Ni! OS recently got a new package installed by default – DanielVrátil’s Plasma Pass applet.Plasma Pass is a Plasma applet to access passwords frompass, the standard UNIX password manager. You can find moreinformation about the applet in Dan’s blog post.As NixOS doesn’t currently offer Plasma Pass in its repositories, thepackage is installed in Ni! OS from the sources as in some otherBTW, I use … distributions.In NixOS, this is easily done via overlays. We can create an overlaythat defines the plasma-pass package so that it can beinstalled as if it were a real NixOS package.Package definitionThis is the overlay definition used in Ni! (ni/packages/plasma-pass.nix):self: prev: { kdePackages = prev.kdePackages.overrideScope (kdeSelf: kdeSuper: { plasma-pass = kdeSelf.mkKdeDerivation rec { pname = "plasma-pass"; version = "1.3.0-git-59be3d64"; src = prev.fetchFromGitLab { domain = "invent.kde.org"; owner = "plasma"; repo = "plasma-pass"; rev = "59be3d6440b6afbacf466455430707deed2b2358"; hash = "sha256-DocHlnF9VJyM1xqZx/hoQVMA/wLY+4RzAbVOGb293ME="; }; buildInputs = [ kdeSelf.plasma-workspace kdeSelf.qgpgme self.oath-toolkit ]; meta = with prev.lib; { description = "Plasma applet for the Pass password manager"; license = licenses.lgpl21Plus; platforms = platforms.linux; }; }; });}Most of this file is self-explanatory (except for the strange lookingsyntax of the Nix language :) ).Since Plasma Pass is a KDE project, we want it visible as a part ofkdePackages collection, and as it uses the common buildsetup that all KDE projects use (or should use), it usesmkKdeDerivation to define the plasma-passpackage. This defines some basic dependencies, commonly used by KDEprojects and adaptations needed for them to work properly in NixOS. Fornon-KDE-friendly packages, you’d base your package on the standardmkDerivation instead.The project sources are located on the KDE’s GitLab instance at invent.kde.org,therefore the package definition uses fetchFromGitLab toretrieve the sources. It is also possible to clone repositories onGitHub, fetch and use source tarballs, etc. All fetchers are describedat NixOSManual > Fetchers.The buildInputs part defines additional dependenciesneeded by Plasma Pass, and meta defines some metainformation about the package such as the description and thelicense.Using the definitionAfter defining the package, we have to add it tonixpkgs.overlays in any of our NixOS configuration files.In the case of Ni! OS, this is done in ni/modules/base.nixwhich defines the UI software that Ni! OS installs by default.nixpkgs.overlays = [ (import ../packages/plasma-pass.nix) ];With this overlay, plasma-pass can be used as if it wasa normal NixOS package.environment.systemPackages = with pkgs; [ ... kdePackages.plasma-pass ... ];When plasma-pass gets added to the nixpkgsrepository, the only action that will be needed in Ni! OS to switch tothe official version is to remove theimport...plasma-pass.nix from the overlays (this is thereason why we explicitly placed it in kdePackagescollection – otherwise, we could have just put it top-level).Custom packages andimmutabilityThe main point of this post is not really to announce that a singlenew package is added to the Ni! OS setup. Even if it is a cool one likePlasma Pass.The point is to show how a custom package that is not available inthe vast collection of nixpkgs can be added to aNixOS-based system.The custom package becomes a proper regular Nix package and gets allthe benefits of Nix’s particular approach to immutability. If PlasmaPass gets broken after an update (either if new Plasma version breaksPlasma Pass, or if the new version of Plasma Pass no longer works asexpected), you can always boot into the version before the badupdate.With distributions with immutable core and custom applicationsinstalled as Flatpaks, downgrading is possible, but a bit more involvedand relies on 3rdparty keeping the old package versions still availablefor download.With NixOS, all the previous versions remain on your system until youdecide to remove them.P.S. Patches welcome. If you like the merge operator in Nix and thinkthe overlay definition would benefit from it, … :)