From 2ee9c181c53878896458b0a111945df6567565af Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sun, 3 Nov 2024 16:01:28 +0200 Subject: [PATCH 1/2] fider: init at 0.24.0 Co-authored-by: Niklas Korz --- .../fi/fider/0001-disable-etc-copy.patch | 12 +++ pkgs/by-name/fi/fider/frontend.nix | 42 ++++++++ pkgs/by-name/fi/fider/package.nix | 101 ++++++++++++++++++ pkgs/by-name/fi/fider/server.nix | 30 ++++++ 4 files changed, 185 insertions(+) create mode 100644 pkgs/by-name/fi/fider/0001-disable-etc-copy.patch create mode 100644 pkgs/by-name/fi/fider/frontend.nix create mode 100644 pkgs/by-name/fi/fider/package.nix create mode 100644 pkgs/by-name/fi/fider/server.nix diff --git a/pkgs/by-name/fi/fider/0001-disable-etc-copy.patch b/pkgs/by-name/fi/fider/0001-disable-etc-copy.patch new file mode 100644 index 0000000000000..f35c626621fcc --- /dev/null +++ b/pkgs/by-name/fi/fider/0001-disable-etc-copy.patch @@ -0,0 +1,12 @@ +diff --git a/app/cmd/server.go b/app/cmd/server.go +index fcfbeec2..71f01c9d 100644 +--- a/app/cmd/server.go ++++ b/app/cmd/server.go +@@ -46,7 +46,6 @@ func RunServer() int { + }) + } + +- copyEtcFiles(ctx) + startJobs(ctx) + + e := routes(web.New()) diff --git a/pkgs/by-name/fi/fider/frontend.nix b/pkgs/by-name/fi/fider/frontend.nix new file mode 100644 index 0000000000000..1361c3f5bee0d --- /dev/null +++ b/pkgs/by-name/fi/fider/frontend.nix @@ -0,0 +1,42 @@ +{ + lib, + esbuild, + buildNpmPackage, + + pname, + version, + src, + npmDepsHash, +}: + +buildNpmPackage { + inherit version src npmDepsHash; + pname = "${pname}-frontend"; + + nativeBuildInputs = [ esbuild ]; + + buildPhase = '' + runHook preBuild + + npx lingui extract public/ + npx lingui compile + NODE_ENV=production node esbuild.config.js + NODE_ENV=production npx webpack-cli + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp -r dist ssr.js favicon.png robots.txt $out/ + + runHook postInstall + ''; + + env = { + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1; + ESBUILD_BINARY_PATH = lib.getExe esbuild; + }; +} diff --git a/pkgs/by-name/fi/fider/package.nix b/pkgs/by-name/fi/fider/package.nix new file mode 100644 index 0000000000000..3fc6a3864efce --- /dev/null +++ b/pkgs/by-name/fi/fider/package.nix @@ -0,0 +1,101 @@ +{ + lib, + stdenvNoCC, + fetchFromGitHub, + callPackage, + esbuild, + buildGoModule, +}: + +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "fider"; + version = "0.24.0"; + + src = fetchFromGitHub { + owner = "getfider"; + repo = "fider"; + tag = "v${finalAttrs.version}"; + hash = "sha256-nzOplwsE0ppmxbTrNAgePnIQIAD/5Uu4gXlebFKWGfc="; + }; + + dontConfigure = true; + dontBuild = true; + + # Allow easier version overrides, e.g.: + # pkgs.fider.overrideAttrs (prev: { + # version = "..."; + # src = prev.src.override { + # hash = "..."; + # }; + # vendorHash = "..."; + # npmDepsHash = "..."; + # }) + vendorHash = "sha256-CfopU72fpXiTaBtdf9A57Wb+flDu2XEtTISxImeJLL0="; + npmDepsHash = "sha256-gnboT5WQzftOCZ2Ouuza7bqpxJf+Zs7OWC8OHMZNHvw="; + + server = callPackage ./server.nix { + inherit (finalAttrs) + pname + version + src + vendorHash + ; + }; + frontend = callPackage ./frontend.nix { + inherit (finalAttrs) + pname + version + src + npmDepsHash + ; + # We specify the esbuild override here instead of in frontend.nix so end users can + # again easily override it if necessary, for example when changing to an unreleased + # version of fider requiring a newer esbuild than specified here: + # pkgs.fider.overrideAttrs (prev: { + # frontend = prev.frontend.override { + # esbuild = ...; + # }; + # }) + esbuild = esbuild.override { + buildGoModule = + args: + buildGoModule ( + args + // rec { + version = "0.14.38"; + src = fetchFromGitHub { + owner = "evanw"; + repo = "esbuild"; + tag = "v${version}"; + hash = "sha256-rvMi1oC7qGidvi4zrm9KCMMntu6LJGVOGN6VmU2ivQE="; + }; + vendorHash = "sha256-QPkBR+FscUc3jOvH7olcGUhM6OW4vxawmNJuRQxPuGs="; + } + ); + }; + }; + + installPhase = '' + runHook preInstall + + mkdir -p $out/etc + cp -r locale views migrations $out/ + cp -r etc/*.md $out/etc/ + ln -s ${finalAttrs.server}/* $out/ + ln -s ${finalAttrs.frontend}/* $out/ + + runHook postInstall + ''; + + meta = { + description = "Open platform to collect and prioritize feedback"; + homepage = "https://github.com/getfider/fider"; + changelog = "https://github.com/getfider/fider/releases/tag/${finalAttrs.src.tag}"; + license = lib.licenses.agpl3Only; + mainProgram = "fider"; + maintainers = with lib.maintainers; [ + drupol + niklaskorz + ]; + }; +}) diff --git a/pkgs/by-name/fi/fider/server.nix b/pkgs/by-name/fi/fider/server.nix new file mode 100644 index 0000000000000..1d2106949af8c --- /dev/null +++ b/pkgs/by-name/fi/fider/server.nix @@ -0,0 +1,30 @@ +{ + buildGoModule, + + pname, + version, + src, + vendorHash, +}: + +buildGoModule { + inherit version src vendorHash; + pname = "${pname}-server"; + + patches = [ + ./0001-disable-etc-copy.patch + ]; + + ldflags = [ + "-s" + "-w" + ]; + + doCheck = false; # requires a running PostgreSQL database + + # preCheck = '' + # set -o allexport + # source ./.test.env + # set +o allexport + # ''; +} From 54e48b64d144099a96e4a6a3c3a154c6cc111ffa Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sun, 3 Nov 2024 15:54:52 +0100 Subject: [PATCH 2/2] nixos/fider: init Co-authored-by: Niklas Korz --- .../manual/release-notes/rl-2505.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/web-apps/fider.nix | 124 ++++++++++++++++++ nixos/tests/all-tests.nix | 1 + nixos/tests/fider.nix | 33 +++++ pkgs/by-name/fi/fider/package.nix | 9 ++ 6 files changed, 170 insertions(+) create mode 100644 nixos/modules/services/web-apps/fider.nix create mode 100644 nixos/tests/fider.nix diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index 44af739153820..794ce781051fe 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -99,6 +99,8 @@ - [Zipline](https://zipline.diced.sh/), a ShareX/file upload server that is easy to use, packed with features, and with an easy setup. Available as [services.zipline](#opt-services.zipline.enable). +- [Fider](https://fider.io/), an open platform to collect and prioritize feedback. Available as [services.fider](#opt-services.fider.enable). + - [mqtt-exporter](https://github.com/kpetremann/mqtt-exporter/), a Prometheus exporter for exposing messages from MQTT. Available as [services.prometheus.exporters.mqtt](#opt-services.prometheus.exporters.mqtt.enable). - [nvidia-gpu](https://github.com/utkuozdemir/nvidia_gpu_exporter), a Prometheus exporter that scrapes `nvidia-smi` for GPU metrics. Available as [services.prometheus.exporters.nvidia-gpu](#opt-services.prometheus.exporters.nvidia-gpu.enable). diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7364d8c598db3..6d91ad5d6b82e 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1474,6 +1474,7 @@ ./services/web-apps/eintopf.nix ./services/web-apps/engelsystem.nix ./services/web-apps/ethercalc.nix + ./services/web-apps/fider.nix ./services/web-apps/filesender.nix ./services/web-apps/firefly-iii.nix ./services/web-apps/firefly-iii-data-importer.nix diff --git a/nixos/modules/services/web-apps/fider.nix b/nixos/modules/services/web-apps/fider.nix new file mode 100644 index 0000000000000..c716fb7bfd4ec --- /dev/null +++ b/nixos/modules/services/web-apps/fider.nix @@ -0,0 +1,124 @@ +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.services.fider; + fiderCmd = lib.getExe cfg.package; +in +{ + options = { + + services.fider = { + enable = lib.mkEnableOption "the Fider server"; + package = lib.mkPackageOption pkgs "fider" { }; + + dataDir = lib.mkOption { + type = lib.types.str; + default = "/var/lib/fider"; + description = "Default data folder for Fider."; + example = "/mnt/fider"; + }; + + database = { + url = lib.mkOption { + type = lib.types.str; + default = "local"; + description = '' + URI to use for the main PostgreSQL database. If this needs to include + credentials that shouldn't be world-readable in the Nix store, set an + environment file on the systemd service and override the + `DATABASE_URL` entry. Pass the string + `local` to setup a database on the local server. + ''; + }; + }; + + environment = lib.mkOption { + type = lib.types.attrsOf lib.types.str; + default = { }; + example = { + PORT = "31213"; + BASE_URL = "https://fider.example.com"; + EMAIL = "smtp"; + EMAIL_NOREPLY = "fider@example.com"; + EMAIL_SMTP_USERNAME = "fider@example.com"; + EMAIL_SMTP_HOST = "mail.example.com"; + EMAIL_SMTP_PORT = "587"; + BLOB_STORAGE = "fs"; + }; + description = '' + Environment variables to set for the service. Secrets should be + specified using {option}`environmentFiles`. + Refer to + and + for available options. + ''; + }; + + environmentFiles = lib.mkOption { + type = lib.types.listOf lib.types.path; + default = [ ]; + example = "/run/secrets/fider.env"; + description = '' + Files to load environment variables from. Loaded variables override + values set in {option}`environment`. + ''; + }; + }; + }; + + config = lib.mkIf cfg.enable { + services.postgresql = lib.mkIf (cfg.database.url == "local") { + enable = true; + ensureUsers = [ + { + name = "fider"; + ensureDBOwnership = true; + } + ]; + ensureDatabases = [ "fider" ]; + }; + + systemd.services.fider = { + description = "Fider server"; + wantedBy = [ "multi-user.target" ]; + after = [ + "network.target" + ] ++ lib.optionals (cfg.database.url == "local") [ "postgresql.service" ]; + requires = lib.optionals (cfg.database.url == "local") [ "postgresql.service" ]; + environment = + let + localPostgresqlUrl = "postgres:///fider?host=/run/postgresql"; + in + { + DATABASE_URL = if (cfg.database.url == "local") then localPostgresqlUrl else cfg.database.url; + BLOB_STORAGE_FS_PATH = "${cfg.dataDir}"; + } + // cfg.environment; + serviceConfig = { + ExecStartPre = "${fiderCmd} migrate"; + ExecStart = fiderCmd; + StateDirectory = "fider"; + DynamicUser = true; + PrivateTmp = "yes"; + Restart = "on-failure"; + RuntimeDirectory = "fider"; + RuntimeDirectoryPreserve = true; + CacheDirectory = "fider"; + WorkingDirectory = "${cfg.package}"; + EnvironmentFile = cfg.environmentFiles; + }; + }; + }; + + meta = { + maintainers = with lib.maintainers; [ + drupol + niklaskorz + ]; + # doc = ./fider.md; + }; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 622d43d4080bd..10e591adcf710 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -336,6 +336,7 @@ in { fenics = handleTest ./fenics.nix {}; ferm = handleTest ./ferm.nix {}; ferretdb = handleTest ./ferretdb.nix {}; + fider = runTest ./fider.nix; filesender = handleTest ./filesender.nix {}; filesystems-overlayfs = runTest ./filesystems-overlayfs.nix; firefly-iii = handleTest ./firefly-iii.nix {}; diff --git a/nixos/tests/fider.nix b/nixos/tests/fider.nix new file mode 100644 index 0000000000000..6db4777ce2bd7 --- /dev/null +++ b/nixos/tests/fider.nix @@ -0,0 +1,33 @@ +{ lib, ... }: + +{ + name = "fider-server"; + + nodes = { + machine = + { pkgs, ... }: + { + services.fider = { + enable = true; + environment = { + JWT_SECRET = "not_so_secret"; + BASE_URL = "/"; + EMAIL_NOREPLY = "noreply@fider.io"; + EMAIL_SMTP_HOST = "mailhog"; + EMAIL_SMTP_PORT = "1025"; + }; + }; + }; + }; + + testScript = '' + machine.start() + machine.wait_for_unit("fider.service") + machine.wait_for_open_port(3000) + ''; + + meta.maintainers = with lib.maintainers; [ + drupol + niklaskorz + ]; +} diff --git a/pkgs/by-name/fi/fider/package.nix b/pkgs/by-name/fi/fider/package.nix index 3fc6a3864efce..5efe096109fdc 100644 --- a/pkgs/by-name/fi/fider/package.nix +++ b/pkgs/by-name/fi/fider/package.nix @@ -5,6 +5,8 @@ callPackage, esbuild, buildGoModule, + nixosTests, + nix-update-script, }: stdenvNoCC.mkDerivation (finalAttrs: { @@ -87,6 +89,13 @@ stdenvNoCC.mkDerivation (finalAttrs: { runHook postInstall ''; + passthru = { + tests = { + inherit (nixosTests) fider; + }; + updateScript = nix-update-script { }; + }; + meta = { description = "Open platform to collect and prioritize feedback"; homepage = "https://github.com/getfider/fider";