From 6c134d9878faed3b2d7bfe37d1cc11309fe708c5 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sun, 28 Apr 2024 18:04:17 +0200 Subject: [PATCH] Generate pin labels automatically --- marker.nix | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/marker.nix b/marker.nix index 1a69602..f604539 100644 --- a/marker.nix +++ b/marker.nix @@ -1,5 +1,25 @@ { lib, config, ... }: 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 { options = { location = lib.mkOption { @@ -14,15 +34,6 @@ let }; }; }; - - userType = lib.types.submodule { - options = { - departure = lib.mkOption { - type = markerType; - default = {}; - }; - }; - }; in { options = { @@ -39,12 +50,10 @@ in users = { manuel.departure = { location = "Switzerland"; - style.label = "M"; }; ganondorf.departure = { location = "Argentinia"; - style.label = "G"; }; };