If you’re like me, and on Gnome (and also on , with Erase your Darlings but that’s not strictly required, you can condense this info out), you may have found it annoying that your login screen in GDM, is not on the correct display. I mean, it might be, but that’s probably more happenstance than anything else.

I strugged with this for a while, I initially found a solution that eventually stopped working - It used to be solved by copying your monitors.xml to /var/lib/gdm/.config/gdm/moitors.xml - But that eventually stopped working. Fair enough.

I also run a system where my root filesystem is actually tmpfs - It’s deleted during shutdown and recreated during boot. There is no stateful data stored that exists outside of /nix/store, /home/krutonium and my various drives I have for games and such.

Given these constraints; I ended up spending way too much time figuring out how to make GDM behave again.

I’m not sure when the switch happened to be honest, but at some point GDM stopped looking in it’s own .config directory. How very of them. Instead, I discovered that they actually read it from /etc/xdg/monitors.xml now - I’m sure no other software will ever trip over that. Nope.

My solution, given how /etc will cease to exist every time I shut down my system, was actually pretty simple, and I am going to share the relevant bit here for anyone on who needs/wants similar functionality.

systemd.services.sync-monitors-to-gdm = {
  description = "Copy Krutonium's GNOME monitor layout to GDM";
  wantedBy = [ "gdm.service" ];
  before = [ "gdm.service" ];
  serviceConfig = {
    Type = "oneshot";
    ExecStart = pkgs.writeShellScript "sync-monitors-to-gdm" ''
      SRC=/home/krutonium/.config/monitors.xml
      DEST=/etc/xdg/monitors.xml

      if [ ! -f "$SRC" ]; then
        echo "No monitors.xml found for krutonium, skipping."
        exit 0
      fi

      mkdir -p /etc/xdg
      install -m 644 "$SRC" "$DEST"
      echo "Copied monitors.xml to $DEST"

    '';
  };
};

I know. Dead simple. And yet, took me ages to figure out. I only ended up solving it because a random reddit post mentioned that path as working.

Obviously, you’ll want to adapt this to your own setup - Or you could go even further, and add the monitors.xml to your nixos config itself, and just have nix symlink into place from the nix store, like this:

environment.etc."xdg/monitors.xml" = {
  source = ./monitors.xml;
  mode = "0644";
};

But that does require you to have a monitors.xml in your repo - Which can make it a bit of pain to maintain if you have more than one computer sharing the configuration; Or if it changes frequently - The first one will update GDM every time you boot the computer.

Permalink to the Implementation in my config

See you next time!