Unable to nixos-rebuild after changing KDE settings using the GUI

Unable to nixos-rebuild after changing KDE settings using the GUI.

I changed some font settings using the GUI and that changed the 10-hm-fonts.conf file inside the .config folder according to my investigation.

Before (also the contents of /nix/store/wwrpv7asn1md5izislwpyq3p9i4wks0q-home-manager-files/.config/fontconfig/conf.d/10-hm-fonts.conf):
<?xml version='1.0'?>

<!-- Generated by Home Manager. -->

<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
  <description>Add fonts in the Nix user profile</description>

  <include ignore_missing="yes">/nix/store/dklxishdaqr1s2dghi13525h7rw11whl-home-manager-path/etc/fonts/conf.d</include>
  <include ignore_missing="yes">/nix/store/dklxishdaqr1s2dghi13525h7rw11whl-home-manager-path/etc/fonts/fonts.conf</include>


<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
<!-- Generated by Home Manager. -->
 <description>Add fonts in the Nix user profile</description>
 <include ignore_missing="yes">/nix/store/bbbf330zjg84shn08y4rqxhzldpfrqkf-home-manager-path/etc/fonts/conf.d</include>
 <include ignore_missing="yes">/nix/store/bbbf330zjg84shn08y4rqxhzldpfrqkf-home-manager-path/etc/fonts/fonts.conf</include>
 <match target="font">
  <edit mode="assign" name="rgba">
 <match target="font">
  <edit mode="assign" name="hinting">
 <match target="font">
  <edit mode="assign" name="hintstyle">
 <match target="font">
  <edit mode="assign" name="antialias">

Command used: sudo nixos-rebuild switch
Terminal Output:

sudo nixos-rebuild switch
building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for nixuser...
setting up tmpfiles
restarting the following units: home-manager-nixuser.service
Job for home-manager-nixuser.service failed because the control process exited with error code.
See "systemctl status home-manager-nixuser.service" and "journalctl -xeu home-manager-nixuser.service" for details.
warning: the following units failed: home-manager-nixuser.service

× home-manager-nixuser.service - Home Manager environment for nixuser
     Loaded: loaded (/etc/systemd/system/home-manager-nixuser.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Tue 2024-03-19 17:44:01 +06; 136ms ago
   Duration: 6min 42.464s
    Process: 27100 ExecStart=/nix/store/b7zkhbiryc17dfi1f9bg2lznm1lzb87l-hm-setup-env /nix/store/5gq26lag1dzd3b7gzswqbyyx63bvx32j-home-manager-generation (code=exited, status=1/FAILURE)
   Main PID: 27100 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 103ms

Mar 19 17:44:01 nixos systemd[1]: Starting Home Manager environment for nixuser...
Mar 19 17:44:01 nixos hm-activate-nixuser[27100]: Starting Home Manager activation
Mar 19 17:44:01 nixos hm-activate-nixuser[27100]: Activating checkFilesChanged
Mar 19 17:44:01 nixos hm-activate-nixuser[27100]: Activating checkLinkTargets
Mar 19 17:44:01 nixos hm-activate-nixuser[27186]: Existing file '/home/nixuser/.config/fontconfig/conf.d/10-hm-fonts.conf' is in the way of '/nix/store/wwrpv7asn1md5izislwpyq3p9i4wks0q-home-manager-files/.config/fontconfig/conf.d/10-hm-fonts.conf'
Mar 19 17:44:01 nixos hm-activate-nixuser[27186]: Please move the above files and try again or use 'home-manager switch -b backup' to back up existing files automatically.
Mar 19 17:44:01 nixos systemd[1]: home-manager-nixuser.service: Main process exited, code=exited, status=1/FAILURE
Mar 19 17:44:01 nixos systemd[1]: home-manager-nixuser.service: Failed with result 'exit-code'.
Mar 19 17:44:01 nixos systemd[1]: Failed to start Home Manager environment for nixuser.
warning: error(s) occurred while switching to the new configuration

I’ve confirmed that this the issue as restoring the 10-hm-fonts.conf back to it’s original state causes no error and the rebuild to succeed.

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.1.82, NixOS, 23.11 (Tapir), 23.11.20240316.8ac30a3`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

I think you should be able to just delete (or move) the ~/.config/fontconfig/conf.d/10-hm-fonts.conf file. I think when you changed the setting it created a new file, so home manager fails because it won’t override files by default. If you want to keep the changes of the file, you’ll have to set up your home manager config to properly install the modified file and keep that within your system config.

@DarkKronicle thank you for the reply.
Yes, deleting the file does cause the rebuild to be successful, but the settings do get deleted along with it.

Can you give me some pointers to any resources on how I might prevent from creating a new file, or setup my home manager to deal with this properly? I’m still learning about NixOS so websites with detailed explanations for noobs that weigh in the pros and cons and best practices are much appreciated.

I haven’t done much with fontconfig, so this may be wrong, but:

Looking at nixpkgs fontconfig options, there seems to be a lot more configuration here than in home manager’s options. So you could configure fontconfig in your system config rather than your home manager config.

Another option (less elegant imo, but allows you to keep using home manager) is to copy home manager’s fontconfig setup and add your other options here.

The unofficial wiki also has some good information Fonts - NixOS Wiki.

In general, looking through options of both home manager and nixpkgs is where I start. I can’t think of any good resources other than this on the top of my head.

Thank you for the suggestion. I’ve decided to go with the configuration route using nix options instead of home manager as I couldn’t figure out how to setup up home-manager to read the configs from the .config folder and incorporate that into the build by overriding xdg.configFile in fontconfig.nix.

This is what I came up with.

# configuration.nix
fonts.fontconfig = {
  enable = true;
  subpixel.rgba = "bgr";
  subpixel.lcdfilter = "legacy";
  hinting.style = "full";