Created
June 19, 2023 20:55
-
-
Save exarkun/6386b35463daa8445ae5e3b32818d8fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
distinctTTY = name: | |
let | |
# Does this systemd service have a TTY? | |
hasTTY = service: (service.serviceConfig.TTYPath or null) != null; | |
# Get only the systemd services that have a TTY. | |
ttyServices = self: services: lib.filterAttrs (name: value: name == self || hasTTY value) services; | |
# Get the names of some systemd services with a stable ordering. | |
serviceNames = services: builtins.sort (a: b: a < b) (builtins.attrNames services); | |
# Get a stable ordinal for a named service in a collection of services. | |
servicePosition = name: services: | |
lib.findSingle | |
(s: s == name) | |
(builtins.error "Could not find service") | |
(builtins.error "Found multiple services sharing a name") | |
(serviceNames (ttyServices name services)); | |
num = servicePosition name config.systemd.services; | |
in | |
"/dev/tty${num}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment