From 008e87e5c2921c678daf0a11b2a765ea52a1f558 Mon Sep 17 00:00:00 2001 From: Ryan Horiguchi Date: Fri, 20 Feb 2026 01:32:40 +0100 Subject: [PATCH] scanservjs: package the backend with the frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scanservjs has been ignoring the configuration options set by the NixOS module since the v3.0.4 upgrade. This fixes it. Create dirs/files in the NixOS module as needed by the new scanservjs build. Fixes: 7432e50d62f9cfa50e57b72becda220d378a98bd ("scanservjs: 2.27.1 -> 3.0.4") Fixes: https://github.com/NixOS/nixpkgs/issues/475043 ("nixos/scanservjs: settings (host/port) ignored in v3.0.4") Co-authored-by: Bjørn Forsman --- .../modules/services/hardware/scanservjs.nix | 6 ++ .../decouple-from-source-tree.patch | 64 ------------------- .../sc/scanservjs/nix-compatibility.patch | 47 ++++++++++++++ pkgs/by-name/sc/scanservjs/package.nix | 31 ++++++++- 4 files changed, 81 insertions(+), 67 deletions(-) delete mode 100644 pkgs/by-name/sc/scanservjs/decouple-from-source-tree.patch create mode 100644 pkgs/by-name/sc/scanservjs/nix-compatibility.patch diff --git a/nixos/modules/services/hardware/scanservjs.nix b/nixos/modules/services/hardware/scanservjs.nix index 774bff45744b..c923ddb5a7b5 100644 --- a/nixos/modules/services/hardware/scanservjs.nix +++ b/nixos/modules/services/hardware/scanservjs.nix @@ -125,6 +125,12 @@ in }; users.groups.scanservjs = { }; + systemd.tmpfiles.rules = [ + "d ${cfg.stateDir}/data 0755 scanservjs scanservjs - -" + "d ${cfg.stateDir}/data/preview 0755 scanservjs scanservjs - -" + "L+ ${cfg.stateDir}/data/preview/default.jpg - - - - ${package}/lib/data/preview/default.jpg" + ]; + systemd.services.scanservjs = { description = "scanservjs"; after = [ "network.target" ]; diff --git a/pkgs/by-name/sc/scanservjs/decouple-from-source-tree.patch b/pkgs/by-name/sc/scanservjs/decouple-from-source-tree.patch deleted file mode 100644 index d39da70e5c5f..000000000000 --- a/pkgs/by-name/sc/scanservjs/decouple-from-source-tree.patch +++ /dev/null @@ -1,64 +0,0 @@ -diff --git a/packages/server/src/api.js b/packages/server/src/api.js -index bd43842..71ce7c9 100644 ---- a/packages/server/src/api.js -+++ b/packages/server/src/api.js -@@ -105,7 +105,7 @@ module.exports = new class Api { - } - - // If not then it's possible the default image is not quite the correct aspect ratio -- const buffer = FileInfo.create(`${config.previewDirectory}/default.jpg`).toBuffer(); -+ const buffer = FileInfo.create('NIX_OUT_PLACEHOLDER/lib/node_modules/scanservjs-api/data/preview/default.jpg').toBuffer(); - - try { - // We need to know the correct aspect ratio from the device -diff --git a/packages/server/src/application.js b/packages/server/src/application.js -index 2771036..0c2a4c0 100644 ---- a/packages/server/src/application.js -+++ b/packages/server/src/application.js -@@ -26,7 +26,7 @@ module.exports = new class Application { - - userOptions() { - if (this._userOptions === null) { -- this._userOptions = new UserOptions('../../config/config.local.js'); -+ this._userOptions = new UserOptions(process.env.NIX_SCANSERVJS_CONFIG_PATH); - } - return this._userOptions; - } -diff --git a/packages/server/src/classes/user-options.js b/packages/server/src/classes/user-options.js -index f129e3c..c71e754 100644 ---- a/packages/server/src/classes/user-options.js -+++ b/packages/server/src/classes/user-options.js -@@ -4,7 +4,7 @@ const path = require('path'); - module.exports = class UserOptions { - constructor(localConfigPath) { - if (localConfigPath) { -- const localPath = path.join(__dirname, localConfigPath); -+ const localPath = localConfigPath; - if (fs.existsSync(localPath)) { - this.local = require(localPath); - } -diff --git a/packages/server/src/configure.js b/packages/server/src/configure.js -index c9e5ed8..484949c 100644 ---- a/packages/server/src/configure.js -+++ b/packages/server/src/configure.js -@@ -71,6 +71,7 @@ function initialize(rootPath) { - - try { - fs.mkdirSync(config.outputDirectory, { recursive: true }); -+ fs.mkdirSync(config.previewDirectory, { recursive: true }); - fs.mkdirSync(config.tempDirectory, { recursive: true }); - } catch (exception) { - log.warn(`Error ensuring output and temp directories exist: ${exception}`); -diff --git a/packages/server/src/server.js b/packages/server/src/server.js -index e1a9fb0..3d58d37 100644 ---- a/packages/server/src/server.js -+++ b/packages/server/src/server.js -@@ -5,7 +5,7 @@ const configure = require('./configure'); - const config = application.config(); - const app = express(); - --app.use(express.static('client')); -+app.use(express.static('@client@')); - - configure(app); - diff --git a/pkgs/by-name/sc/scanservjs/nix-compatibility.patch b/pkgs/by-name/sc/scanservjs/nix-compatibility.patch new file mode 100644 index 000000000000..3aa8324e4596 --- /dev/null +++ b/pkgs/by-name/sc/scanservjs/nix-compatibility.patch @@ -0,0 +1,47 @@ +diff --git a/app-server/src/application.js b/app-server/src/application.js +index a2c065f..2d594bf 100644 +--- a/app-server/src/application.js ++++ b/app-server/src/application.js +@@ -26,7 +26,7 @@ module.exports = new class Application { + + userOptions() { + if (this._userOptions === null) { +- this._userOptions = new UserOptions('../../config/config.local.js'); ++ this._userOptions = new UserOptions(process.env.NIX_SCANSERVJS_CONFIG_PATH); + } + return this._userOptions; + } +diff --git a/app-server/src/classes/user-options.js b/app-server/src/classes/user-options.js +index f129e3c..c71e754 100644 +--- a/app-server/src/classes/user-options.js ++++ b/app-server/src/classes/user-options.js +@@ -4,7 +4,7 @@ const path = require('path'); + module.exports = class UserOptions { + constructor(localConfigPath) { + if (localConfigPath) { +- const localPath = path.join(__dirname, localConfigPath); ++ const localPath = localConfigPath; + if (fs.existsSync(localPath)) { + this.local = require(localPath); + } +diff --git a/app-server/src/express-configurer.js b/app-server/src/express-configurer.js +index 945dae2..1b456cc 100644 +--- a/app-server/src/express-configurer.js ++++ b/app-server/src/express-configurer.js +@@ -166,6 +166,7 @@ module.exports = class ExpressConfigurer { + + try { + fs.mkdirSync(config.outputDirectory, { recursive: true }); ++ fs.mkdirSync(config.previewDirectory, { recursive: true }); + fs.mkdirSync(config.thumbnailDirectory, { recursive: true }); + fs.mkdirSync(config.tempDirectory, { recursive: true }); + } catch (exception) { +@@ -220,7 +221,7 @@ module.exports = class ExpressConfigurer { + * @returns {ExpressConfigurer} + */ + statics() { +- this.app.use(express.static('client')); ++ this.app.use(express.static('@client@')); + return this; + } + diff --git a/pkgs/by-name/sc/scanservjs/package.nix b/pkgs/by-name/sc/scanservjs/package.nix index c386bf6b3dca..3f152503bb81 100644 --- a/pkgs/by-name/sc/scanservjs/package.nix +++ b/pkgs/by-name/sc/scanservjs/package.nix @@ -18,11 +18,36 @@ buildNpmPackage (finalAttrs: { npmDepsHash = "sha256-HIWT09G8gqSFt9CIjsjJaDRnj2GO0G6JOGeI0p4/1vw="; - postInstall = '' - mkdir $out/bin + patches = [ + ./nix-compatibility.patch + ]; + + postBuild = '' + # Install runtime dependencies + npm install \ + --prefix ./dist \ + --offline \ + --production \ + --ignore-scripts + ''; + + installPhase = '' + runHook preInstall + + rm -rf $out/lib + + mkdir -p $out/lib + cp -r dist/* $out/lib + + substituteInPlace "$out/lib/server/express-configurer.js" \ + --replace-fail "@client@" "$out/lib/client" + + mkdir -p $out/bin makeWrapper ${lib.getExe nodejs} $out/bin/scanservjs \ --set NODE_ENV production \ - --add-flags "'$out/lib/node_modules/scanservjs/app-server/src/server.js'" + --add-flags "$out/lib/server/server.js" + + runHook postInstall ''; meta = {