tl;dr: Can anyone help with a working code snippet that allows for the declarative setting of the user profile image under Gnome?
I am trying to declaratively set the user profile image under Gnome. I’ve read a number of postings which all say that it should be possible by creating a file called .face (png or jpg file) in the home directory. Some relevant post include:
This successfully creates the .face file but there is no change to the user profile. Logging out or restarting does not impact the session.
Further research shows that the file located at /var/lib/AccountsService/users/user needs to point to the profile image. However the file does not, instead its contents points to a different file:
Can anyone help with a working code snippet that allows for the declarative setting of the user profile image or code that how allow me to replace the image file pointer referenced at /var/lib/AccountsService/users/user?
I’ve accomplished this by having a script run before the display manager. This script tries to either add or update the profile image in the user’s config file.
@jakehamilton, thank you for the pointer. I have tried to apply your suggestion by creating a separate function with your code. For the purpose of aiding my understanding I stripped out a few variables and hard-coded some values. The function builds with no errors when I do a nixos-rebuild swithch --flake .# but there is no effect on the image. Again I tried restarting the machine just in case caches needed to be flushed but there was no success. Would you please be able to cast an eye over the following code. It should be straight forward as it is a direct clone of your code, with the exception that a few variables have been hard coded:
{ config, lib, pkgs, ... } :
{
systemd.services.orion-user-icon = {
before = ["display-manager.service"];
wantedBy = ["display-manager.service"];
serviceConfig = {
Type = "simple";
User = "root";
Group = "root";
};
script = ''
config_file=/var/lib/AccountsService/users/orion
icon_file=/home/orion/Pictures/face.png
if ! [ -d "$(dirname "$config_file")"]; then
mkdir -p "$(dirname "$config_file")"
fi
if ! [ -f "$config_file" ]; then
echo "[User]
Session=gnome
SystemAccount=false
Icon=$icon_file" > "$config_file"
else
icon_config=$(sed -E -n -e "/Icon=.*/p" $config_file)
if [[ "$icon_config" == "" ]]; then
echo "Icon=$icon_file" >> $config_file
else
sed -E -i -e "s#^Icon=.*$#Icon=$icon_file#" $config_file
fi
fi
'';
};
}
As mentioned above, the code builds with no errors but does not seem to get executed. I am of course importing it via “imports” in my configuration.nix file. Thank you for your help.
For anyone else looking for a working solution to this issue, I have implemented the following hack. It’s ugly but it works. Just add the following to your configuration.nix file:
Note that if the folder holding the picture is a home.persistence mount done with impermanence, you have to give the source path because the script run before the path is mounted