9 cfg = config.services.pingvin-share;
21 services.pingvin-share = {
22 enable = mkEnableOption "Pingvin Share, a self-hosted file sharing platform";
28 User account under which Pingvin Share runs.
36 Group under which Pingvin Share runs.
40 openFirewall = mkOption {
44 Whether to open the firewall for the port in {option}`services.pingvin-share.frontend.port`.
50 default = "/var/lib/pingvin-share";
51 example = "/var/lib/pingvin";
53 The path to the data directory in which Pingvin Share will store its data.
59 default = "localhost:${toString cfg.backend.port}";
60 defaultText = lib.literalExpression "localhost:\${options.services.pingvin-share.backend.port}";
61 example = "pingvin-share.domain.tdl";
63 The domain name of your instance. If null, the redirections will be made to localhost.
72 Whether to enable HTTPS for the domain.
77 package = mkPackageOption pkgs [
87 The port that the backend service of Pingvin Share will listen to.
93 package = mkPackageOption pkgs [
103 The port that the frontend service of Pingvin Share will listen to.
109 enable = mkEnableOption "a Nginx reverse proxy for Pingvin Share.";
114 config = mkIf cfg.enable {
116 users.groups = mkIf (cfg.group == "pingvin") { pingvin = { }; };
118 users.users = mkIf (cfg.user == "pingvin") {
121 description = "Pingvin Share daemon user";
126 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.frontend.port ];
128 systemd.services.pingvin-share-backend = {
129 description = "Backend service of Pingvin Share, a self-hosted file sharing platform.";
133 "pingvin-share-frontend.service"
135 before = [ "pingvin-share-frontend.service" ];
138 "network-online.target"
140 wants = [ "network-online.target" ];
143 PRISMA_SCHEMA_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/schema-engine";
144 PRISMA_QUERY_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/query-engine";
145 PRISMA_QUERY_ENGINE_LIBRARY = "${pkgs.prisma-engines}/lib/libquery_engine.node";
146 PRISMA_INTROSPECTION_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/introspection-engine";
147 PRISMA_FMT_BINARY = "${pkgs.prisma-engines}/bin/prisma-fmt";
148 PORT = toString cfg.backend.port;
149 DATABASE_URL = "file:${cfg.dataDir}/pingvin-share.db?connection_limit=1";
150 DATA_DIRECTORY = cfg.dataDir;
163 Restart = "on-failure";
165 "${cfg.backend.package}/node_modules/.bin/prisma migrate deploy"
166 "${cfg.backend.package}/node_modules/.bin/prisma db seed"
168 ExecStart = "${cfg.backend.package}/node_modules/.bin/ts-node dist/src/main";
169 StateDirectory = mkIf (cfg.dataDir == "/var/lib/pingvin-share") "pingvin-share";
170 WorkingDirectory = cfg.backend.package;
174 systemd.services.pingvin-share-frontend = {
175 description = "Frontend service of Pingvin Share, a self-hosted file sharing platform.";
177 wantedBy = [ "multi-user.target" ];
179 "network-online.target"
180 "pingvin-share-backend.service"
183 "network-online.target"
184 "pingvin-share-backend.service"
188 PORT = toString cfg.frontend.port;
189 API_URL = "${if cfg.https then "https" else "http"}://${cfg.hostname}";
191 path = [ cfg.frontend.package ];
197 Restart = "on-failure";
198 ExecStart = "${cfg.frontend.package}/node_modules/.bin/next start";
199 StateDirectory = mkIf (cfg.dataDir == "/var/lib/pingvin-share") "pingvin-share";
200 WorkingDirectory = cfg.frontend.package;
204 services.nginx = mkIf cfg.nginx.enable {
205 enable = lib.mkDefault true;
206 virtualHosts."${cfg.hostname}" = {
207 enableACME = cfg.https;
208 forceSSL = cfg.https;
211 proxyPass = "http://localhost:${toString cfg.frontend.port}";
212 recommendedProxySettings = true;
215 proxyPass = "http://localhost:${toString cfg.backend.port}";
216 recommendedProxySettings = true;
223 maintainers = with lib.maintainers; [ ratcornu ];
224 doc = ./pingvin-share.md;