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.

documize.nix 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. { pkgs, lib, config, ... }:
  2. with lib;
  3. let
  4. cfg = config.services.documize;
  5. mkParams = optional: concatMapStrings (name: let
  6. predicate = optional -> cfg.${name} != null;
  7. template = " -${name} '${toString cfg.${name}}'";
  8. in optionalString predicate template);
  9. in {
  10. options.services.documize = {
  11. enable = mkEnableOption "Documize Wiki";
  12. stateDirectoryName = mkOption {
  13. type = types.str;
  14. default = "documize";
  15. description = ''
  16. The name of the directory below <filename>/var/lib/private</filename>
  17. where documize runs in and stores, for example, backups.
  18. '';
  19. };
  20. package = mkOption {
  21. type = types.package;
  22. default = pkgs.documize-community;
  23. description = ''
  24. Which package to use for documize.
  25. '';
  26. };
  27. salt = mkOption {
  28. type = types.nullOr types.str;
  29. default = null;
  30. example = "3edIYV6c8B28b19fh";
  31. description = ''
  32. The salt string used to encode JWT tokens, if not set a random value will be generated.
  33. '';
  34. };
  35. cert = mkOption {
  36. type = types.nullOr types.str;
  37. default = null;
  38. description = ''
  39. The <filename>cert.pem</filename> file used for https.
  40. '';
  41. };
  42. key = mkOption {
  43. type = types.nullOr types.str;
  44. default = null;
  45. description = ''
  46. The <filename>key.pem</filename> file used for https.
  47. '';
  48. };
  49. port = mkOption {
  50. type = types.port;
  51. default = 5001;
  52. description = ''
  53. The http/https port number.
  54. '';
  55. };
  56. forcesslport = mkOption {
  57. type = types.nullOr types.port;
  58. default = null;
  59. description = ''
  60. Redirect given http port number to TLS.
  61. '';
  62. };
  63. offline = mkOption {
  64. type = types.bool;
  65. default = false;
  66. description = ''
  67. Set <literal>true</literal> for offline mode.
  68. '';
  69. apply = v: if true == v then 1 else 0;
  70. };
  71. dbtype = mkOption {
  72. type = types.enum [ "mysql" "percona" "mariadb" "postgresql" "sqlserver" ];
  73. default = "postgresql";
  74. description = ''
  75. Specify the database provider:
  76. <simplelist type='inline'>
  77. <member><literal>mysql</literal></member>
  78. <member><literal>percona</literal></member>
  79. <member><literal>mariadb</literal></member>
  80. <member><literal>postgresql</literal></member>
  81. <member><literal>sqlserver</literal></member>
  82. </simplelist>
  83. '';
  84. };
  85. db = mkOption {
  86. type = types.str;
  87. description = ''
  88. Database specific connection string for example:
  89. <itemizedlist>
  90. <listitem><para>MySQL/Percona/MariaDB:
  91. <literal>user:password@tcp(host:3306)/documize</literal>
  92. </para></listitem>
  93. <listitem><para>MySQLv8+:
  94. <literal>user:password@tcp(host:3306)/documize?allowNativePasswords=true</literal>
  95. </para></listitem>
  96. <listitem><para>PostgreSQL:
  97. <literal>host=localhost port=5432 dbname=documize user=admin password=secret sslmode=disable</literal>
  98. </para></listitem>
  99. <listitem><para>MSSQL:
  100. <literal>sqlserver://username:password@localhost:1433?database=Documize</literal> or
  101. <literal>sqlserver://sa@localhost/SQLExpress?database=Documize</literal>
  102. </para></listitem>
  103. </itemizedlist>
  104. '';
  105. };
  106. location = mkOption {
  107. type = types.nullOr types.str;
  108. default = null;
  109. description = ''
  110. reserved
  111. '';
  112. };
  113. };
  114. config = mkIf cfg.enable {
  115. systemd.services.documize-server = {
  116. description = "Documize Wiki";
  117. documentation = [ https://documize.com/ ];
  118. wantedBy = [ "multi-user.target" ];
  119. serviceConfig = {
  120. ExecStart = concatStringsSep " " [
  121. "${cfg.package}/bin/documize"
  122. (mkParams false [ "db" "dbtype" "port" ])
  123. (mkParams true [ "offline" "location" "forcesslport" "key" "cert" "salt" ])
  124. ];
  125. Restart = "always";
  126. DynamicUser = "yes";
  127. StateDirectory = cfg.stateDirectoryName;
  128. WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}";
  129. };
  130. };
  131. };
  132. }