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;
default = {};
};
arrival = lib.mkOption {
type = markerType;
default = {};
};
};
config = {
departure.style.label = lib.mkDefault (firstUpperAlnum name);
arrival.style.label = lib.mkDefault (firstUpperAlnum name);
};
});
@ -69,6 +75,10 @@ let
]);
in
{
imports = [
./path.nix
];
options = {
users = lib.mkOption {
type = lib.types.attrsOf userType;
@ -81,9 +91,15 @@ in
config = {
users = {
manuel.departure = {
location = "Switzerland";
style.size = "small";
manuel = {
departure = {
location = "Switzerland";
style.size = "small";
};
arrival = {
location = "Prague";
};
};
ganondorf.departure = {
@ -101,6 +117,7 @@ in
(
lib.concatMap (user: [
user.departure
user.arrival
]) (lib.attrValues config.users));
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;
};
}