I'm configuring autorandr with Nix, both with home-manager on arch linux and on NixOS. In both scenarios, the config files for autorandr are linked from a readonly filesystem with a 0 timestamp:
❯ tree /etc/xdg
/etc/xdg
└── autorandr
├── default
│ ├── config -> /etc/static/xdg/autorandr/default/config
│ ├── postswitch.d
│ │ └── kb -> /etc/static/xdg/autorandr/default/postswitch.d/kb
│ └── setup -> /etc/static/xdg/autorandr/default/setup
└── office
├── config -> /etc/static/xdg/autorandr/office/config
├── postswitch.d
│ └── kb -> /etc/static/xdg/autorandr/office/postswitch.d/kb
└── setup -> /etc/static/xdg/autorandr/office/setup
❯ ls -lAL /etc/xdg/autorandr/*
/etc/xdg/autorandr/default:
total 12
-r--r--r-- 1 root root 55 Jan 1 1970 config
drwxr-xr-x 2 root root 4096 Mar 24 12:20 postswitch.d
-r--r--r-- 1 root root 1295 Jan 1 1970 setup
/etc/xdg/autorandr/office:
total 12
-r--r--r-- 1 root root 55 Jan 1 1970 config
drwxr-xr-x 2 root root 4096 Mar 24 12:20 postswitch.d
-r--r--r-- 1 root root 1295 Jan 1 1970 setup
Why it fails
`--cycle will always select the first profile, since:
--cycle depends on sorting by mtime
os.utime will fail if the file is readonly
- the return value indicating success from
update_mtime is ignored, so the current (epoch 0) mtime stays
Here is the relevant code:
# toplevel, return value of update_mtime is ignored
if "--dry-run" not in options:
update_mtime(os.path.join(scripts_path, "config"))
def update_mtime(filename):
"Update a file's mtime"
try:
os.utime(filename, None)
return True
except:
# this will fail
return False
Proposed fixes
Either:
- call
os.utime with follow_symlinks = false, and update and read mtime from the link instead of the destination
- extend symlink profile detection to work with actual dirs for the autorandr and profiles dirs, but when the actual config is a symlink (not entirely sure how this part of the code works atm)
I'm configuring
autorandrwith Nix, both with home-manager on arch linux and on NixOS. In both scenarios, the config files for autorandr are linked from a readonly filesystem with a 0 timestamp:Why it fails
`--cycle will always select the first profile, since:
--cycledepends on sorting bymtimeos.utimewill fail if the file is readonlyupdate_mtimeis ignored, so the current (epoch 0)mtimestaysHere is the relevant code:
Proposed fixes
Either:
os.utimewithfollow_symlinks = false, and update and readmtimefrom the link instead of the destination