scanservjs: 2.27.0 -> 3.0.3
This commit is contained in:
parent
7f829af357
commit
ebab2df5c1
|
@ -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; {
|
||||||
|
|
|
@ -5,19 +5,13 @@
|
||||||
|
|
||||||
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:
|
||||||
|
@ -58,7 +52,7 @@ let
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: [
|
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`";
|
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,7 +121,7 @@ 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 = { };
|
||||||
|
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue