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 { lib
, fetchFromGitHub , fetchFromGitHub
, buildNpmPackage , buildNpmPackage
, fetchNpmDeps
, nodejs , nodejs
}: }:
let buildNpmPackage {
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 {
pname = "scanservjs"; pname = "scanservjs";
inherit version src nodejs; version = "3.0.3";
sourceRoot = "${src.name}/packages/server"; src = fetchFromGitHub {
npmDepsHash = depsHashes.server or lib.fakeHash; # owner = "sbs20";
owner = "chayleaf";
repo = "scanservjs";
# rev = "v${version}";
rev = "bf41a95c9cd6bd924d6e14a28da6d33ddc64ef2e";
hash = "sha256-ePg8spI1rlWYcpjtax7gaZp2wUX4beHzMd71b8XKNG8=";
};
inherit nodejs;
npmDepsHash = "sha256-bigIFAQ2RLk6yxbUcMnmXwgaEkzFFUYn+hE7RIiFm8Y=";
preBuild = '' preBuild = ''
chmod +w /build/source npm run build
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 });"
''; '';
postInstall = '' 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 mkdir -p $out/bin
makeWrapper ${nodejs}/bin/node $out/bin/scanservjs \ makeWrapper ${nodejs}/bin/node $out/bin/scanservjs \
--set NODE_ENV production \ --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; { meta = with lib; {

View file

@ -5,25 +5,19 @@
let let
cfg = config.services.scanservjs; 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 = { settings = {
scanimage = "${pkgs.sane-backends}/bin/scanimage"; scanimage = "${pkgs.sane-backends}/bin/scanimage";
convert = "${pkgs.imagemagick}/bin/convert"; convert = "${pkgs.imagemagick}/bin/convert";
tesseract = "${pkgs.tesseract}/bin/tesseract"; 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; } // cfg.settings;
settingsFormat = pkgs.formats.json { }; settingsFormat = pkgs.formats.json { };
leafs = attrs: leafs = attrs:
builtins.concatLists builtins.concatLists
(lib.mapAttrsToList (lib.mapAttrsToList
(k: v: if builtins.isAttrs v then leafs v else [v]) (k: v: if builtins.isAttrs v then leafs v else [ v ])
attrs); attrs);
package = pkgs.scanservjs; package = pkgs.scanservjs;
@ -58,7 +52,7 @@ let
}, },
actions: [ actions: [
${builtins.concatStringsSep ",\n" cfg.extraActions} ${builtins.concatStringsSep ",\n" (map (x: "(${x})") cfg.extraActions)}
], ],
}; };
''; '';
@ -74,7 +68,7 @@ in {
''; '';
}; };
settings = lib.mkOption { settings = lib.mkOption {
default = {}; default = { };
description = lib.mdDoc '' description = lib.mdDoc ''
Config to set in config.local.js's `afterConfig` Config to set in config.local.js's `afterConfig`
''; '';
@ -114,11 +108,12 @@ in {
''; '';
}; };
extraActions = lib.mkOption { extraActions = lib.mkOption {
default = []; default = [ ];
type = lib.types.listOf lib.types.lines; type = lib.types.listOf lib.types.lines;
description = "Actions to add to config.local.js's `actions`"; description = "Actions to add to config.local.js's `actions`";
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
hardware.sane.enable = true; hardware.sane.enable = true;
users.users.scanservjs = { users.users.scanservjs = {
@ -126,9 +121,9 @@ in {
extraGroups = [ "scanner" "lp" ]; extraGroups = [ "scanner" "lp" ];
home = cfg.stateDir; home = cfg.stateDir;
isSystemUser = true; isSystemUser = true;
createHome = true; createHome = lib.mkIf (cfg.stateDir != "/var/lib/scanservjs") true;
}; };
users.groups.scanservjs = {}; users.groups.scanservjs = { };
systemd.services.scanservjs = { systemd.services.scanservjs = {
description = "scanservjs"; description = "scanservjs";
@ -136,14 +131,14 @@ in {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
# yes, those paths are configurable, but the config option isn't always used... # yes, those paths are configurable, but the config option isn't always used...
path = with pkgs; [ coreutils sane-backends imagemagick tesseract ]; path = with pkgs; [ coreutils sane-backends imagemagick tesseract ];
environment.NIX_SCANSERVJS_CONFIG_PATH = configFile;
environment.SANE_CONFIG_DIR = "/etc/sane-config"; environment.SANE_CONFIG_DIR = "/etc/sane-config";
environment.LD_LIBRARY_PATH = "/etc/sane-libs"; environment.LD_LIBRARY_PATH = "/etc/sane-libs";
serviceConfig = { serviceConfig = {
ExecStart = "${package}/bin/scanservjs"; ExecStart = "${package}/bin/scanservjs --config ${configFile}";
Restart = "always"; Restart = "always";
User = "scanservjs"; User = "scanservjs";
Group = "scanservjs"; Group = "scanservjs";
StateDirectory = lib.mkIf (cfg.stateDir == "/var/lib/scanservjs") "scanservjs";
WorkingDirectory = cfg.stateDir; WorkingDirectory = cfg.stateDir;
}; };
}; };