SDDM background image

On of the first things I typically do when setting up a new PC is change the background in sddm.

I haven’t yet found an easy way to do this in nixos.

I found this answer: How to set sddm background on login

However, it seems to suggest that you should package a new theme which seems odd to me since the image is configurable.

Is there an easy way to do this that I am missing?

sddm doesn’t know about the background - it’s only the theme that does, so you will need to create a new theme with the required background but you could simply copy from one of the existing ones.

I use this and you can pass a new background in via themeIni (refer to solarized for an example):

{ config, lib, pkgs, ... }:

let
  buildTheme = { name, version, src, themeIni ? [] }:
    pkgs.stdenv.mkDerivation rec {
      pname = "sddm-theme-${name}";
      inherit version src;

      buildCommand = ''
        dir=$out/share/sddm/themes/${name}
        doc=$out/share/doc/${pname}

        mkdir -p $dir $doc
        if [ -d $src/${name} ]; then
          srcDir=$src/${name}
        else
          srcDir=$src
        fi
        cp -r $srcDir/* $dir/
        for f in $dir/{AUTHORS,COPYING,LICENSE,README,*.md,*.txt}; do
          test -f $f && mv $f $doc/
        done
        chmod 444 $dir/theme.conf

        ${lib.concatMapStringsSep "\n" (e: ''
          ${pkgs.crudini}/bin/crudini --set --inplace $dir/theme.conf \
            "${e.section}" "${e.key}" "${e.value}"
        '') themeIni}
      '';
    };

  customTheme = builtins.isAttrs theme;

  theme = themes.deepin;
  # theme = "breeze";

  themeName = if customTheme
  then theme.pkg.name
  else theme;

  packages = if customTheme
  then [ (buildTheme theme.pkg) ] ++ theme.deps
  else [];

  themes = {
    aerial = {
      pkg = rec {
        name = "aerial";
        version = "20191018";
        src = pkgs.fetchFromGitHub {
          owner = "3ximus";
          repo = "${name}-sddm-theme";
          rev = "1a8a5ba00aa4a98fcdc99c9c1547d73a2a64c1bf";
          sha256 = "0f62fqsr73d6fjpfhsdijin9pab0yn0phdyfqasybk50rn59861y";
        };
      };
      deps = with pkgs; [ qt5.qtmultimedia ];
    };

    abstractdark = {
      pkg = rec {
        name = "abstractdark";
        version = "20161002";
        src = pkgs.fetchFromGitHub {
          owner = "3ximus";
          repo = "${name}-sddm-theme";
          rev = "e817d4b27981080cd3b398fe928619ffa16c52e7";
          sha256 = "1si141hnp4lr43q36mbl3anlx0a81r8nqlahz3n3l7zmrxb56s2y";
        };
      };
      deps = with pkgs; [];
    };

    chili = {
      pkg = rec {
        name = "chili";
        version = "0.1.5";
        src = pkgs.fetchFromGitHub {
          owner = "MarianArlt";
          repo = "sddm-${name}";
          rev = version;
          sha256 = "036fxsa7m8ymmp3p40z671z163y6fcsa9a641lrxdrw225ssq5f3";
        };
      };
      deps = with pkgs; [];
    };

    deepin = {
      pkg = rec {
        name = "deepin";
        version = "20180306";
        src = pkgs.fetchFromGitHub {
          owner = "Match-Yang";
          repo = "sddm-${name}";
          rev = "6d018d2cad737018bb1e673ef4464ccf6a2817e7";
          sha256 = "1ghkg6gxyik4c03y1c97s7mjvl0kyjz9bxxpwxmy0rbh1a6xwmck";
        };
      };
      deps = with pkgs; [];
    };

    simplicity = {
      pkg = rec {
        name = "simplicity";
        version = "20190730";
        src = pkgs.fetchFromGitLab {
          owner = "isseigx";
          repo = "${name}-sddm-theme";
          rev = "d98fc1d03c44689883e27b57cc176b26d3316301";
          sha256 = "14wf62jgrpv4ybizbs57zma6kb4xy76qgl3wa38a5ykfgvpkcmrd";
        };
      };
      deps = with pkgs; [ noto-fonts ];
    };

    solarized = {
      pkg = rec {
        name = "solarized";
        version = "20190103";
        src = pkgs.fetchFromGitHub {
          owner = "MalditoBarbudo";
          repo = "${name}_sddm_theme";
          rev = "2b5bdf1045f2a5c8b880b482840be8983ca06191";
          sha256 = "1n36i4mr5vqfsv7n3jrvsxcxxxbx73yq0dbhmd2qznncjfd5hlxr";
        };
        themeIni = [
          { section = "General"; key = "background"; value = "bars_background.png"; }
        ];
      };
      deps = with pkgs; [ font-awesome ];
    };

    sugar-dark = {
      pkg = rec {
        name = "sugar-dark";
        version = "1.2";
        src = pkgs.fetchFromGitHub {
          owner = "MarianArlt";
          repo = "sddm-${name}";
          rev = "v${version}";
          sha256 = "0gx0am7vq1ywaw2rm1p015x90b75ccqxnb1sz3wy8yjl27v82yhb";
        };
      };
      deps = with pkgs; [];
    };
  };

in
{
  environment.systemPackages = packages;

  services.xserver.displayManager.sddm.theme = themeName;
}

4 Likes

Thanks for the response, just getting back to this now.

I am very new to NixOS and still fairly early in the somewhat substantial learning curve.

I have another question. How do I get the background there in the first place?

For now, using a variation of the above expression, I set a background at a location outside of the nix store such as /sddm/background.png. This has the advantage of being able to import the same expression on all my machines but have a different background for each. However, it doesn’t seem like a very nix-ish way to solve the problem.

Is there a better way?

Let’s say you have a folder called assets with background.png inside where you keep you nixos config. Using solarized as an example, this is what you would do:

    solarized = {
      pkg = rec {
        name = "solarized";
        version = "20190103";
        src = pkgs.fetchFromGitHub {
          owner = "MalditoBarbudo";
          repo = "${name}_sddm_theme";
          rev = "2b5bdf1045f2a5c8b880b482840be8983ca06191";
          sha256 = "1n36i4mr5vqfsv7n3jrvsxcxxxbx73yq0dbhmd2qznncjfd5hlxr";
        };
        themeIni = [
          { section = "General"; key = "background"; value = ./assets/background.png; }
        ];
      };
      deps = with pkgs; [ font-awesome ];
    };

So instead of passing in a string with just the name, pass in an actual file. That should do the trick.

1 Like

I was giving this code a go…

I keep getting:

error: builder for '/nix/store/szfhm6ks9d94brs8bvmjrbj2m56skc5p-sddm-theme-simplicity-20190730.drv' failed with exit code 1;
       last 1 log lines:
       > [Errno 13] Permission denied: '/nix/store/mn86hm95hjgfl34llhkzjya9zai6spya-sddm-theme-simplicity-20190730/share/sddm/themes/simplicity/theme.conf'

I am stumped on this. Running my rebuild with sudo, etc.

Ok, so I have narrowed it down to the themeIni section when I try to set a background. :thinking:

EDIT:

Ok, chmod 444 $dir/theme.conf is the offending line in the build command. If you do something silly like 777 it will build.

I don’t know nix well enough to understand what the permissions require in the nix store.

Editing the file fails with 444, correct. I have 644 on my side. Apologies.