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.

zeronet.nix 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. { config, lib, pkgs, ... }:
  2. let
  3. inherit (lib) generators literalExample mkEnableOption mkIf mkOption recursiveUpdate types;
  4. cfg = config.services.zeronet;
  5. dataDir = "/var/lib/zeronet";
  6. configFile = pkgs.writeText "zeronet.conf" (generators.toINI {} (recursiveUpdate defaultSettings cfg.settings));
  7. defaultSettings = {
  8. global = {
  9. data_dir = dataDir;
  10. log_dir = dataDir;
  11. ui_port = cfg.port;
  12. fileserver_port = cfg.fileserverPort;
  13. tor = if !cfg.tor then "disable" else if cfg.torAlways then "always" else "enable";
  14. };
  15. };
  16. in with lib; {
  17. options.services.zeronet = {
  18. enable = mkEnableOption "zeronet";
  19. settings = mkOption {
  20. type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
  21. default = {};
  22. example = literalExample "global.tor = enable;";
  23. description = ''
  24. <filename>zeronet.conf</filename> configuration. Refer to
  25. <link xlink:href="https://zeronet.readthedocs.io/en/latest/faq/#is-it-possible-to-use-a-configuration-file"/>
  26. for details on supported values;
  27. '';
  28. };
  29. port = mkOption {
  30. type = types.int;
  31. default = 43110;
  32. example = 43110;
  33. description = "Optional zeronet web UI port.";
  34. };
  35. fileserverPort = mkOption {
  36. # Not optional: when absent zeronet tries to write one to the
  37. # read-only config file and crashes
  38. type = types.int;
  39. default = 12261;
  40. example = 12261;
  41. description = "Zeronet fileserver port.";
  42. };
  43. tor = mkOption {
  44. type = types.bool;
  45. default = false;
  46. description = "Use TOR for zeronet traffic where possible.";
  47. };
  48. torAlways = mkOption {
  49. type = types.bool;
  50. default = false;
  51. description = "Use TOR for all zeronet traffic.";
  52. };
  53. };
  54. config = mkIf cfg.enable {
  55. services.tor = mkIf cfg.tor {
  56. enable = true;
  57. controlPort = 9051;
  58. extraConfig = ''
  59. CacheDirectoryGroupReadable 1
  60. CookieAuthentication 1
  61. CookieAuthFileGroupReadable 1
  62. '';
  63. };
  64. systemd.services.zeronet = {
  65. description = "zeronet";
  66. after = [ "network.target" (optionalString cfg.tor "tor.service") ];
  67. wantedBy = [ "multi-user.target" ];
  68. serviceConfig = {
  69. User = "zeronet";
  70. DynamicUser = true;
  71. StateDirectory = "zeronet";
  72. SupplementaryGroups = mkIf cfg.tor [ "tor" ];
  73. ExecStart = "${pkgs.zeronet}/bin/zeronet --config_file ${configFile}";
  74. };
  75. };
  76. };
  77. imports = [
  78. (mkRemovedOptionModule [ "services" "zeronet" "dataDir" ] "Zeronet will store data by default in /var/lib/zeronet")
  79. (mkRemovedOptionModule [ "services" "zeronet" "logDir" ] "Zeronet will log by default in /var/lib/zeronet")
  80. ];
  81. meta.maintainers = with maintainers; [ chiiruno ];
  82. }