scanservjs: 2.27.0 -> 3.0.3

This commit is contained in:
chayleaf 2023-11-19 01:31:01 +07:00
parent 7f829af357
commit ebab2df5c1
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
2 changed files with 30 additions and 80 deletions

View file

@ -1,83 +1,38 @@
{ lib
, fetchFromGitHub
, buildNpmPackage
, fetchNpmDeps
, nodejs
}:
let
version = "2.27.0";
src = fetchFromGitHub {
owner = "sbs20";
repo = "scanservjs";
rev = "v${version}";
hash = "sha256-GFpfH7YSXFRNRmx8F2bUJsGdPW1ECT7AQquJRxiRJEU=";
};
depsHashes = {
server = "sha256-V4w4euMl67eS4WNIFM8j06/JAEudaq+4zY9pFVgTmlY=";
client = "sha256-r/uYaXpQnlI90Yn6mo2KViKDMHE8zaCAxNFnEZslnaY=";
};
serverDepsForClient = fetchNpmDeps {
inherit src nodejs;
sourceRoot = "${src.name}/packages/server";
name = "scanservjs-server";
hash = depsHashes.server or lib.fakeHash;
};
# static client files
client = buildNpmPackage ({
pname = "scanservjs-static";
inherit version src nodejs;
sourceRoot = "${src.name}/packages/client";
npmDepsHash = depsHashes.client or lib.fakeHash;
preBuild = ''
cd ../server
chmod +w package-lock.json . /build/source/
npmDeps=${serverDepsForClient} npmConfigHook
cd ../client
'';
env.NODE_OPTIONS = "--openssl-legacy-provider";
dontNpmInstall = true;
installPhase = ''
mv /build/source/dist/client $out
'';
});
in buildNpmPackage {
buildNpmPackage {
pname = "scanservjs";
inherit version src nodejs;
version = "3.0.3";
sourceRoot = "${src.name}/packages/server";
npmDepsHash = depsHashes.server or lib.fakeHash;
src = fetchFromGitHub {
# owner = "sbs20";
owner = "chayleaf";
repo = "scanservjs";
# rev = "v${version}";
rev = "bf41a95c9cd6bd924d6e14a28da6d33ddc64ef2e";
hash = "sha256-ePg8spI1rlWYcpjtax7gaZp2wUX4beHzMd71b8XKNG8=";
};
inherit nodejs;
npmDepsHash = "sha256-bigIFAQ2RLk6yxbUcMnmXwgaEkzFFUYn+hE7RIiFm8Y=";
preBuild = ''
chmod +w /build/source
substituteInPlace src/server.js --replace "express.static('client')" "express.static('${client}')"
substituteInPlace src/api.js --replace \
'`''${config.previewDirectory}/default.jpg`' \
"'$out/lib/node_modules/scanservjs-api/data/preview/default.jpg'"
substituteInPlace src/application.js --replace \
"'../../config/config.local.js'" \
"process.env.NIX_SCANSERVJS_CONFIG_PATH"
substituteInPlace src/classes/user-options.js --replace \
"const localPath = path.join(__dirname, localConfigPath);" \
"const localPath = localConfigPath;"
substituteInPlace src/configure.js --replace \
"fs.mkdirSync(config.outputDirectory, { recursive: true });" \
"fs.mkdirSync(config.outputDirectory, { recursive: true }); fs.mkdirSync(config.previewDirectory, { recursive: true });"
npm run build
'';
postInstall = ''
mv $out/lib/node_modules/scanservjs/node_modules dist/
rm -rf $out/lib/node_modules/scanservjs
mv dist $out/lib/node_modules/scanservjs
mkdir -p $out/bin
makeWrapper ${nodejs}/bin/node $out/bin/scanservjs \
--set NODE_ENV production \
--add-flags "'$out/lib/node_modules/scanservjs-api/src/server.js'"
--add-flags "'$out/lib/node_modules/scanservjs/server/server.js'"
'';
meta = with lib; {

View file

@ -5,19 +5,13 @@
let
cfg = config.services.scanservjs;
/*
substituteInPlace src/classes/config.js \
--replace '/usr/bin/scanimage' '${sane-backends}/bin/scanimage' \
--replace '/usr/bin/convert' '${imagemagick}/bin/convert' \
--replace '/usr/bin/tesseract' '${tesseract}/bin/tesseract'
*/
settings = {
scanimage = "${pkgs.sane-backends}/bin/scanimage";
convert = "${pkgs.imagemagick}/bin/convert";
tesseract = "${pkgs.tesseract}/bin/tesseract";
# it defaults to config/devices.json, but "config" dir doesn't exist and scanservjs doesn't create it
devicesPath = "devices.json";
} // cfg.settings;
settingsFormat = pkgs.formats.json { };
leafs = attrs:
@ -58,7 +52,7 @@ let
},
actions: [
${builtins.concatStringsSep ",\n" cfg.extraActions}
${builtins.concatStringsSep ",\n" (map (x: "(${x})") cfg.extraActions)}
],
};
'';
@ -119,6 +113,7 @@ in {
description = "Actions to add to config.local.js's `actions`";
};
};
config = lib.mkIf cfg.enable {
hardware.sane.enable = true;
users.users.scanservjs = {
@ -126,7 +121,7 @@ in {
extraGroups = [ "scanner" "lp" ];
home = cfg.stateDir;
isSystemUser = true;
createHome = true;
createHome = lib.mkIf (cfg.stateDir != "/var/lib/scanservjs") true;
};
users.groups.scanservjs = { };
@ -136,14 +131,14 @@ in {
wantedBy = [ "multi-user.target" ];
# yes, those paths are configurable, but the config option isn't always used...
path = with pkgs; [ coreutils sane-backends imagemagick tesseract ];
environment.NIX_SCANSERVJS_CONFIG_PATH = configFile;
environment.SANE_CONFIG_DIR = "/etc/sane-config";
environment.LD_LIBRARY_PATH = "/etc/sane-libs";
serviceConfig = {
ExecStart = "${package}/bin/scanservjs";
ExecStart = "${package}/bin/scanservjs --config ${configFile}";
Restart = "always";
User = "scanservjs";
Group = "scanservjs";
StateDirectory = lib.mkIf (cfg.stateDir == "/var/lib/scanservjs") "scanservjs";
WorkingDirectory = cfg.stateDir;
};
};