Generate pin labels automatically

This commit is contained in:
Manuel Thalmann 2024-04-28 18:04:17 +02:00
parent c9dd4abb28
commit 6c134d9878

View file

@ -1,5 +1,25 @@
{ lib, config, ... }: { lib, config, ... }:
let let
# Returns the uppercased first label or number of a string
firstUpperAlnum =
str:
lib.mapNullable
lib.head (builtins.match "[^A-Z0-9]*([A-Z0-9]).*" (lib.toUpper str));
userType = lib.types.submodule (
{ name, ... }: {
options = {
departure = lib.mkOption {
type = markerType;
default = {};
};
};
config = {
departure.style.label = lib.mkDefault (firstUpperAlnum name);
};
});
markerType = lib.types.submodule { markerType = lib.types.submodule {
options = { options = {
location = lib.mkOption { location = lib.mkOption {
@ -14,15 +34,6 @@ let
}; };
}; };
}; };
userType = lib.types.submodule {
options = {
departure = lib.mkOption {
type = markerType;
default = {};
};
};
};
in in
{ {
options = { options = {
@ -39,12 +50,10 @@ in
users = { users = {
manuel.departure = { manuel.departure = {
location = "Switzerland"; location = "Switzerland";
style.label = "M";
}; };
ganondorf.departure = { ganondorf.departure = {
location = "Argentinia"; location = "Argentinia";
style.label = "G";
}; };
}; };