context: I did a minimal install and installs xserver lightdm qtile as desktop environment. Running nixos as a guest os inside kvm.
I tried writing a service as follows in configuration.nix but get can’t open display.
systemd.services.screensetter = {
enable = true;
description = "sets correct screen resolution";
wantedBy = [ "multi-user.target"];
# Add this line in your nixos configuration (E.G. the "configuration.nix" file or a module imported into it)
# this allows you to use `xrandr` inside of scripts called by this service
# https://www.reddit.com/r/NixOS/comments/w4fj6p/comment/ih1oa5e/?utm_source=reddit&utm_medium=web2x&context=3
path = [ pkgs.xorg.xrandr ];
unitConfig = {
type = "simple";
};
serviceConfig = {
ExecStart = "/home/<this_user>/.screenlayout/nixos-screenlayout.sh";
};
};
then I tried spice-autorandr and that doesn’t work proper, sets a resolution bigger than my display’s native resolution.
services.spice-autorandr.enable = true;
finally after some trial and error I found a sketchy way to do it:
services.xserver = {
enable = true;
windowManager.qtile.enable = true;
displayManager.sessionCommands = ''
xrandr --output Virtual-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal
xwallpaper --zoom ~/walls/jk.png
xet r rate 200 35 &
'';
};
now I wanted someone came up with a correct way to set screen resolution based on my arandr generated script