Web-based Calendar Aggregator https://ticker.c3d2.de/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

115 lines
3.3 KiB

{ pkgs, config, lib, ... }:
with import ./. { inherit pkgs; };
let
inherit (pkgs.lib) mkOption types;
cfg = config.services.ticker;
defaultTickerConfig = {
db_url = "postgres:///ticker";
calendars = {};
weekdays = [
"Montag" "Dienstag" "Mittwoch" "Donnerstag"
"Freitag" "Sonnabend" "Sonntag"
];
months = [
"Januar" "Februar" "März" "April"
"Mai" "Juni" "Juli" "August"
"September" "Oktober" "November" "Dezember"
];
};
tickerConfig = defaultTickerConfig // cfg.config;
configFile = pkgs.writeText "config.yaml" (lib.generators.toYAML {} tickerConfig);
workDir = pkgs.runCommandLocal "ticker-env" {} ''
mkdir $out
ln -s ${ticker-serve}/shared/ticker-serve/static $out/
ln -s ${configFile} $out/config.yaml
'';
in
{
options.services.ticker = {
stateDir = mkOption {
type = types.str;
default = "/var/lib/ticker";
description = ''
Directory where ticker files will be placed by default.
'';
};
user = mkOption {
type = types.str;
default = "ticker";
description = "User account under which ticker runs.";
};
group = mkOption {
type = types.str;
default = "ticker";
description = "Group account under which ticker runs.";
};
config = mkOption {
type = types.attrs;
default = defaultTickerConfig;
};
updateInterval = mkOption {
type = types.str;
default = "1h";
description = "Timer interval";
};
};
config = {
users.users.${cfg.user} = {
inherit (cfg) group;
};
users.groups.${cfg.group} = {};
services.postgresql = {
enable = true;
};
systemd.services.ticker-setup = {
wantedBy = [ "multi-user.target" ];
after = [ "postgresql.service" ];
preStart = let
pgsu = config.services.postgresql.superUser;
psql = config.services.postgresql.package;
in ''
mkdir -p ${cfg.stateDir}
chown ${cfg.user}:${cfg.group} -R ${cfg.stateDir}
if ! test -e "${cfg.stateDir}/db-created"; then
${pkgs.sudo}/bin/sudo -u ${pgsu} ${psql}/bin/createuser --no-superuser --no-createdb --no-createrole ${cfg.user}
${pkgs.sudo}/bin/sudo -u ${pgsu} ${psql}/bin/createdb --owner ${cfg.user} ticker
${pkgs.sudo}/bin/sudo -u ${cfg.user} ${psql}/bin/psql -f ${ticker-serve}/shared/libticker/schema.sql ticker
touch "${cfg.stateDir}/db-created"
fi
'';
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.coreutils}/bin/test -f ${cfg.stateDir}/db-created";
};
};
systemd.services.ticker-update = {
wantedBy = [ "multi-user.target" ];
after = [ "postgresql.service" "ticker-setup.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${ticker-update}/bin/ticker-update";
WorkingDirectory = "${workDir}";
User = cfg.user;
Group = cfg.group;
};
};
systemd.services.ticker-serve = {
wantedBy = [ "multi-user.target" ];
after = [ "postgresql.service" "ticker-setup.service" ];
serviceConfig = {
Type = "simple";
ExecStart = "${ticker-serve}/bin/ticker-serve";
WorkingDirectory = "${workDir}";
User = cfg.user;
Group = cfg.group;
};
};
};
}