NixTutorial/marker.nix

86 lines
1.8 KiB
Nix
Raw Normal View History

2024-04-26 16:17:35 +00:00
{ lib, config, ... }:
let
markerType = lib.types.submodule {
options = {
location = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
2024-04-26 22:30:42 +00:00
style.label = lib.mkOption {
type = lib.types.nullOr
(lib.types.strMatching "[0-9A-Z]");
default = null;
};
2024-04-26 16:17:35 +00:00
};
};
userType = lib.types.submodule {
options = {
departure = lib.mkOption {
type = markerType;
default = {};
};
};
};
2024-04-26 16:17:35 +00:00
in
{
options = {
users = lib.mkOption {
type = lib.types.attrsOf userType;
};
2024-04-26 16:17:35 +00:00
map.markers = lib.mkOption {
type = lib.types.listOf markerType;
};
};
config = {
users = {
2024-04-26 22:30:42 +00:00
manuel.departure = {
location = "Switzerland";
style.label = "M";
};
ganondorf.departure = {
location = "Argentinia";
style.label = "G";
};
};
2024-04-26 16:17:35 +00:00
map = {
markers = lib.filter
(marker: marker.location != null)
(
lib.concatMap (user: [
user.departure
]) (lib.attrValues config.users));
center = lib.mkIf
(lib.length config.map.markers >= 1)
null;
zoom = lib.mkIf
(lib.length config.map.markers >= 2)
null;
2024-04-26 16:17:35 +00:00
};
requestParams =
let
2024-04-26 22:30:42 +00:00
paramForMarker =
marker:
let
attributes =
lib.optional (marker.style.label != null)
"label:${marker.style.label}"
++ [
"$(${config.scripts.geocode}/bin/geocode ${
lib.escapeShellArg marker.location
})"
];
in
"markers=\"${lib.concatStringsSep "|" attributes}\"";
in builtins.map paramForMarker config.map.markers;
2024-04-26 16:17:35 +00:00
};
}