Allow drawing paths per user

This commit is contained in:
Manuel Thalmann 2024-04-28 18:56:35 +02:00
parent 32904e238f
commit 599529fb03
2 changed files with 64 additions and 3 deletions

View file

@ -13,10 +13,16 @@ let
type = markerType; type = markerType;
default = {}; default = {};
}; };
arrival = lib.mkOption {
type = markerType;
default = {};
};
}; };
config = { config = {
departure.style.label = lib.mkDefault (firstUpperAlnum name); departure.style.label = lib.mkDefault (firstUpperAlnum name);
arrival.style.label = lib.mkDefault (firstUpperAlnum name);
}; };
}); });
@ -69,6 +75,10 @@ let
]); ]);
in in
{ {
imports = [
./path.nix
];
options = { options = {
users = lib.mkOption { users = lib.mkOption {
type = lib.types.attrsOf userType; type = lib.types.attrsOf userType;
@ -81,11 +91,17 @@ in
config = { config = {
users = { users = {
manuel.departure = { manuel = {
departure = {
location = "Switzerland"; location = "Switzerland";
style.size = "small"; style.size = "small";
}; };
arrival = {
location = "Prague";
};
};
ganondorf.departure = { ganondorf.departure = {
location = "Argentinia"; location = "Argentinia";
@ -101,6 +117,7 @@ in
( (
lib.concatMap (user: [ lib.concatMap (user: [
user.departure user.departure
user.arrival
]) (lib.attrValues config.users)); ]) (lib.attrValues config.users));
center = lib.mkIf center = lib.mkIf

44
path.nix Normal file
View file

@ -0,0 +1,44 @@
{ lib, config, ... }:
let
pathType = lib.types.submodule {
options = {
locations = lib.mkOption {
type = lib.types.listOf lib.types.str;
};
};
};
in
{
options = {
map.paths = lib.mkOption {
type = lib.types.listOf pathType;
};
};
config = {
map.paths = builtins.map (
user: {
locations = [
user.departure.location
user.arrival.location
];
}) (lib.filter (
user:
user.departure.location != null
&& user.arrival.location != null
) (lib.attrValues config.users));
requestParams =
let
attrForLocation =
loc: "$(${config.scripts.geocode}/bin/geocode ${lib.escapeShellArg loc})";
paramForPath =
path:
let
attributes = builtins.map attrForLocation path.locations;
in
''path="${lib.concatStringsSep "|" attributes}"'';
in
builtins.map paramForPath config.map.paths;
};
}