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.

nixos-module.nix 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. { pkgs, config, lib, ... }:
  2. with import ./. { inherit pkgs; };
  3. let
  4. inherit (pkgs.lib) mkOption types;
  5. cfg = config.services.ticker;
  6. defaultTickerConfig = {
  7. db_url = "postgres:///ticker";
  8. calendars = {};
  9. weekdays = [
  10. "Montag" "Dienstag" "Mittwoch" "Donnerstag"
  11. "Freitag" "Sonnabend" "Sonntag"
  12. ];
  13. months = [
  14. "Januar" "Februar" "März" "April"
  15. "Mai" "Juni" "Juli" "August"
  16. "September" "Oktober" "November" "Dezember"
  17. ];
  18. };
  19. tickerConfig = defaultTickerConfig // cfg.config;
  20. configFile = pkgs.writeText "config.yaml" (lib.generators.toYAML {} tickerConfig);
  21. workDir = pkgs.runCommandLocal "ticker-env" {} ''
  22. mkdir $out
  23. ln -s ${ticker-serve}/shared/ticker-serve/static $out/
  24. ln -s ${configFile} $out/config.yaml
  25. '';
  26. in
  27. {
  28. options.services.ticker = {
  29. stateDir = mkOption {
  30. type = types.str;
  31. default = "/var/lib/ticker";
  32. description = ''
  33. Directory where ticker files will be placed by default.
  34. '';
  35. };
  36. user = mkOption {
  37. type = types.str;
  38. default = "ticker";
  39. description = "User account under which ticker runs.";
  40. };
  41. group = mkOption {
  42. type = types.str;
  43. default = "ticker";
  44. description = "Group account under which ticker runs.";
  45. };
  46. config = mkOption {
  47. type = types.attrs;
  48. default = defaultTickerConfig;
  49. };
  50. updateInterval = mkOption {
  51. type = types.str;
  52. default = "hourly";
  53. description = "Timer interval";
  54. };
  55. };
  56. config = {
  57. users.users.${cfg.user} = {
  58. inherit (cfg) group;
  59. isSystemUser = true;
  60. };
  61. users.groups.${cfg.group} = {};
  62. services.postgresql = {
  63. enable = true;
  64. };
  65. systemd.services.ticker-setup = {
  66. wantedBy = [ "multi-user.target" ];
  67. after = [ "postgresql.service" ];
  68. preStart = let
  69. pgsu = config.services.postgresql.superUser;
  70. psql = config.services.postgresql.package;
  71. in ''
  72. mkdir -p ${cfg.stateDir}
  73. chown ${cfg.user}:${cfg.group} -R ${cfg.stateDir}
  74. if ! test -e "${cfg.stateDir}/db-created"; then
  75. ${pkgs.sudo}/bin/sudo -u ${pgsu} ${psql}/bin/createuser --no-superuser --no-createdb --no-createrole ${cfg.user}
  76. ${pkgs.sudo}/bin/sudo -u ${pgsu} ${psql}/bin/createdb --owner ${cfg.user} ticker
  77. ${pkgs.sudo}/bin/sudo -u ${cfg.user} ${psql}/bin/psql -f ${ticker-serve}/shared/libticker/schema.sql ticker
  78. touch "${cfg.stateDir}/db-created"
  79. fi
  80. '';
  81. serviceConfig = {
  82. Type = "oneshot";
  83. ExecStart = "${pkgs.coreutils}/bin/test -f ${cfg.stateDir}/db-created";
  84. };
  85. };
  86. systemd.services.ticker-update = {
  87. wantedBy = [ "multi-user.target" ];
  88. after = [ "postgresql.service" "ticker-setup.service" ];
  89. serviceConfig = {
  90. Type = "oneshot";
  91. ExecStart = "${ticker-update}/bin/ticker-update";
  92. WorkingDirectory = "${workDir}";
  93. User = cfg.user;
  94. Group = cfg.group;
  95. };
  96. };
  97. systemd.timers.ticker-update = {
  98. wantedBy = [ "multi-user.target" ];
  99. partOf = [ "ticker-update.service" ];
  100. timerConfig = {
  101. OnCalendar = cfg.updateInterval;
  102. };
  103. };
  104. systemd.services.ticker-serve = {
  105. wantedBy = [ "multi-user.target" ];
  106. after = [ "postgresql.service" "ticker-setup.service" ];
  107. serviceConfig = {
  108. Type = "simple";
  109. ExecStart = "${ticker-serve}/bin/ticker-serve";
  110. WorkingDirectory = "${workDir}";
  111. User = cfg.user;
  112. Group = cfg.group;
  113. };
  114. };
  115. };
  116. }