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.