How to configure SDDM sugar-candy theme declaratively

Hello, I am very new to Nixos, and with the help of many same topic on this site, I managed to change to sddm and got sugar-candy running:
Apply an custom theme to SDDM
Fetch package from github

But the problem is that I don’t know how to configure it, because the packages installed is pretty much untouchable, even with sudo privilege.

Here’s my setup:

In configuration.nix:

{ config, pkgs, ... }:

{

environment.systemPackages = with pkgs; [
  # Get sugar-candy from github in sugar-candy.nix then call it here
  (callPackage ./sugar-candy.nix{}).sddm-sugar-candy-theme
  libsForQt5.qt5.qtgraphicaleffects #required for sugar candy
  ];

  # Enable sddm and use theme sugar-candy
  services.xserver.displayManager.sddm = {
    enable = true;
    theme = "sugar-candy";
  };
}

In ./sugar-candy.nix

{ stdenv, fetchFromGitHub }:
{
  sddm-sugar-candy-theme = stdenv.mkDerivation rec {
    pname = "sddm-sugar-candy-theme";
    version = "1.6";
    dontBuild = true;
    installPhase = ''
      mkdir -p $out/share/sddm/themes
      cp -aR $src $out/share/sddm/themes/sugar-candy
    '';
    src = fetchFromGitHub {
      owner = "Kangie";
      repo = "sddm-sugar-candy";
      rev = "v1.6";
      sha256 = "sha256-p2d7I0UBP63baW/q9MexYJQcqSmZ0L5rkwK3n66gmqM=";
    };
  };
}

Now that I got it running, I realize that I need to configure it somehow. But I’m obviously can’t touch it even with sudo privilege.

How do I configure it now that I have it running?

Hello,
I tried something new

{pkgs, stdenv, fetchFromGitHub }:
{
  sddm-sugar-candy-theme = stdenv.mkDerivation rec {
    pname = "sddm-sugar-candy-theme";
    version = "1.6";
    dontBuild = true;
    installPhase = ''
      mkdir -p $out/share/sddm/themes
      cp -aR $src $out/share/sddm/themes/sugar-candy
      cp ${pkgs.writeText "$out/share/sddm/themes/sugar-candy/theme.conf" ''
[General]

Background="$HOME/Pictures/background.*"
      ''} $out/share/sddm/themes/sugar-candy/theme.conf
    '';
    src = fetchFromGitHub {
      owner = "Kangie";
      repo = "sddm-sugar-candy";
      rev = "v1.6";
      sha256 = "sha256-p2d7I0UBP63baW/q9MexYJQcqSmZ0L5rkwK3n66gmqM=";
    };
  };
}

and got

cp: cannot create regular file '/nix/store/84bc0zahsfl41f8dxakgznf9jsz8d1g4-sddm-sugar-candy-theme-1.6/share/sddm/themes/sugar-candy/theme.conf': Permission denied

pretty much predicted that, but is there another way to write to a file that’s fetched from github?
or any alternative wayat all?

In case if you stil needed.

  1. Clone repo to location on your pc/laptop
  2. Edit theme as you like
  3. Change in original sugar-theme.nix (top one)
    fetchFromGitHub to fetchurl
    replace src=fetchFromGitHub to
    src = /path/to_edited_theme/sddm-sugar-candy;
    meta = with stdenv.lib; {
    try rebuild

Linking to my post from a few years ago that might be of help: SDDM background image - #2 by peterhoeg

Full disclosure - I am no longer using that, as my life became infinitely easier when I decided to simply use the stock themes that come with sddm and kde (and stuff in general).

This caused me many hours of headache because I did not want the bloat of having the full theme as part of my configuration, and only wanted to change some parts of the theme.conf. The solution is painfully simple.

The following does not work, and gives a permission error, as established:

{ stdenvNoCC, fetchFromGitHub, lib, libsForQt5, pkgs }:

stdenvNoCC.mkDerivation rec {
  pname = "sddm-rose-pine-theme";
  version = "1.2";
  dontBuild = true;

  propagatedUserEnvPkgs = [ libsForQt5.qt5.qtgraphicaleffects ];

  src = fetchFromGitHub {
    owner = "lwndhrst";
    repo = "sddm-rose-pine";
    rev = "v${version}";
    sha256 = "+WOdazvkzpOKcoayk36VLq/6lLOHDWkDykDsy8p87JE=";
  };

  configOverride = builtins.readFile ./sddm-overrides.conf;

  installPhase = ''
    mkdir -p $out/share/sddm/themes/rose-pine
    cp -R $src/* $out/share/sddm/themes/rose-pine/
    # This is where we get the error, whether we use echo, cp or anything else
    echo "${configOverride}" > $out/share/sddm/themes/rose-pine/theme.conf
  '';
}

this is because fetchFromGitHub gives the file it fetches read-only permissions. We could change those permissions, except we can’t because something else throws an error, probably for good reason. So we can’t overwrite the file after we’ve copied it to $out from source. Here’s what we can do though:

{ ... }:

stdenvNoCC.mkDerivation rec {
  pname = ...

  src = fetchFromGitHub {
    ...
  };

  configOverride = builtins.readFile ./sddm-overrides.conf;

  installPhase = ''
    mkdir -p $out/share/sddm/themes/rose-pine
    # First copy the cutom config,
    # because once the source is copied the permissions are screwed up
    echo "${configOverride}" > $out/share/sddm/themes/rose-pine/theme.conf
    # Then copy the source without overriding existing files,
    # Leaving our custom config in place
    cp -Rn $src/* $out/share/sddm/themes/rose-pine/
  '';
}

Simply copy / write the files you want to “overwrite” first, then copy the source files with -n to not overwrite the ones you just copied. I hope this saves some poor soul the hours I spent fiddling with the different phases of the packaging process.