NixTutorial/default.nix

74 lines
1.4 KiB
Nix
Raw Normal View History

{ pkgs, lib, config, ... }:
{
2024-04-26 16:17:35 +00:00
imports = [
./marker.nix
];
options = {
2024-04-26 06:28:25 +00:00
scripts = {
output = lib.mkOption {
type = lib.types.package;
};
geocode = lib.mkOption {
type = lib.types.package;
};
};
map = {
zoom = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = 2;
};
2024-04-26 06:28:25 +00:00
center = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "Switzerland";
};
};
requestParams = lib.mkOption {
type = lib.types.listOf lib.types.str;
};
};
config = {
2024-04-26 06:28:25 +00:00
scripts = {
output = pkgs.writeShellApplication {
name = "map";
2024-04-26 06:28:25 +00:00
runtimeInputs = with pkgs; [
curl
imagemagick
];
2024-04-26 06:28:25 +00:00
text = ''
convert <(${./map} ${lib.concatStringsSep " " config.requestParams}) sixel:-
'';
};
geocode = pkgs.writeShellApplication {
name = "geocode";
runtimeInputs = with pkgs; [
curl
jq
];
text = ''exec ${./geocode} "$@"'';
};
};
requestParams = [
"size=640x300"
"scale=2"
(lib.mkIf (config.map.zoom != null)
"zoom=${toString config.map.zoom}")
2024-04-26 06:28:25 +00:00
(lib.mkIf (config.map.center != null)
"center=\"${config.scripts.geocode}/bin/geocode ${
lib.escapeShellArg config.map.center
}\"")
];
};
}