From eac5dfd20ff4a618b0b62262bdafcd2245f2c7ea Mon Sep 17 00:00:00 2001 From: TomaSajt <62384384+TomaSajt@users.noreply.github.com> Date: Sun, 5 Nov 2023 13:28:47 +0100 Subject: [PATCH] lanraragi: 0.8.90 -> 0.9.0 --- nixos/modules/services/web-apps/lanraragi.nix | 13 +-- nixos/tests/lanraragi.nix | 8 +- .../lanraragi/fix-minion-redis-password.patch | 34 ------ pkgs/by-name/la/lanraragi/install.patch | 75 +++++++++--- .../la/lanraragi/loosen-dep-reqs.patch | 13 +++ pkgs/by-name/la/lanraragi/package.nix | 107 ++++++++++-------- 6 files changed, 134 insertions(+), 116 deletions(-) delete mode 100644 pkgs/by-name/la/lanraragi/fix-minion-redis-password.patch create mode 100644 pkgs/by-name/la/lanraragi/loosen-dep-reqs.patch diff --git a/nixos/modules/services/web-apps/lanraragi.nix b/nixos/modules/services/web-apps/lanraragi.nix index f1ab8b8b4eb4..6e452e7a3b35 100644 --- a/nixos/modules/services/web-apps/lanraragi.nix +++ b/nixos/modules/services/web-apps/lanraragi.nix @@ -72,11 +72,10 @@ in "HOME" = "/var/lib/lanraragi"; }; preStart = '' - REDIS_PASS=${lib.optionalString (cfg.redis.passwordFile != null) "$(head -n1 ${cfg.redis.passwordFile})"} cat > lrr.conf < "127.0.0.1:${toString cfg.redis.port}", - redis_password => "$REDIS_PASS", + redis_password => "${lib.optionalString (cfg.redis.passwordFile != null) ''$(head -n1 ${cfg.redis.passwordFile})''}", redis_database => "0", redis_database_minion => "1", redis_database_config => "2", @@ -84,15 +83,9 @@ in } EOF '' + lib.optionalString (cfg.passwordFile != null) '' - PASS_HASH=$( - PASS=$(head -n1 ${cfg.passwordFile}) ${cfg.package.perlEnv}/bin/perl -I${cfg.package}/share/lanraragi/lib -e \ - 'use LANraragi::Controller::Config; print LANraragi::Controller::Config::make_password_hash($ENV{PASS})' \ - 2>/dev/null - ) - - ${lib.getExe pkgs.redis} -h 127.0.0.1 -p ${toString cfg.redis.port} -a "$REDIS_PASS" <LRR_CONF->get_redisad . "/" . $self->LRR_CONF->get_miniondb; -+ my $redispassword = $self->LRR_CONF->get_redispassword; -+ -+ # If the password is non-empty, add the required delimiters -+ if ($redispassword) { $redispassword = "x:" . $redispassword . "@"; } -+ - say "Minion will use the Redis database at $miniondb"; -- $self->plugin( 'Minion' => { Redis => "redis://$miniondb" } ); -+ $self->plugin( 'Minion' => { Redis => "redis://$redispassword$miniondb" } ); - $self->LRR_LOGGER->info("Successfully connected to Minion database."); - $self->minion->missing_after(5); # Clean up older workers after 5 seconds of unavailability - -diff --git a/lib/LANraragi/Model/Config.pm b/lib/LANraragi/Model/Config.pm -index f52056d4..63e1f5d3 100644 ---- a/lib/LANraragi/Model/Config.pm -+++ b/lib/LANraragi/Model/Config.pm -@@ -42,8 +42,8 @@ sub get_minion { - my $miniondb = get_redisad . "/" . get_miniondb; - my $password = get_redispassword; - -- # If the password is non-empty, add the required @ -- if ($password) { $password = $password . "@"; } -+ # If the password is non-empty, add the required delimiters -+ if ($password) { $password = "x:" . $password . "@"; } - - return Minion->new( Redis => "redis://$password$miniondb" ); - } diff --git a/pkgs/by-name/la/lanraragi/install.patch b/pkgs/by-name/la/lanraragi/install.patch index 9d260f5a494f..440c9252a727 100644 --- a/pkgs/by-name/la/lanraragi/install.patch +++ b/pkgs/by-name/la/lanraragi/install.patch @@ -1,21 +1,16 @@ -diff --git a/tools/cpanfile b/tools/cpanfile -index 359c61fe..ca3b7ec7 100755 ---- a/tools/cpanfile -+++ b/tools/cpanfile -@@ -20,7 +20,7 @@ requires 'Sort::Naturally', 1.03; - requires 'Authen::Passphrase', 0.008; - requires 'File::ReadBackwards', 1.05; - requires 'URI::Escape', 1.74; --requires 'URI', 5.09; -+requires 'URI', 5.05; - - # Used by Installer - requires 'IPC::Cmd', 1.02; diff --git a/tools/install.pl b/tools/install.pl -index 0cbb847d..1bd61fa0 100755 +index dbeb7c11..06e4c675 100755 --- a/tools/install.pl +++ b/tools/install.pl -@@ -91,32 +91,6 @@ if ( $ENV{HOMEBREW_FORMULA_PREFIX} ) { +@@ -9,6 +9,7 @@ use Config; + + use feature qw(say); + use File::Path qw(make_path); ++use File::Copy qw(copy); + + #Vendor dependencies + my @vendor_css = ( +@@ -91,32 +92,6 @@ if ( $ENV{HOMEBREW_FORMULA_PREFIX} ) { $cpanopt = " -l " . $ENV{HOMEBREW_FORMULA_PREFIX} . "/libexec"; } @@ -48,16 +43,60 @@ index 0cbb847d..1bd61fa0 100755 #Check for PerlMagick say("Checking for ImageMagick/PerlMagick..."); my $imgk; -@@ -154,12 +128,6 @@ if ( $back || $full ) { +@@ -136,36 +111,11 @@ if ($@) { + say("OK!"); + } + +-#Build & Install CPAN Dependencies +-if ( $back || $full ) { +- say("\r\nInstalling Perl modules... This might take a while.\r\n"); +- +- if ( $Config{"osname"} ne "darwin" ) { +- say("Installing Linux::Inotify2 for non-macOS systems... (This will do nothing if the package is there already)"); +- +- install_package( "Linux::Inotify2", $cpanopt ); +- } +- +- if ( system( "cpanm --installdeps ./tools/. --notest" . $cpanopt ) != 0 ) { +- die "Something went wrong while installing Perl modules - Bailing out."; +- } +-} +- #Clientside Dependencies with Provisioning if ( $front || $full ) { - say("\r\nObtaining remote Web dependencies...\r\n"); - -- if ( system("npm install") != 0 ) { +- if ( system("npm ci") != 0 ) { - die "Something went wrong while obtaining node modules - Bailing out."; - } - say("\r\nProvisioning...\r\n"); - #Load File::Copy +- #Load File::Copy +- install_package( "File::Copy", $cpanopt ); +- File::Copy->import("copy"); +- + make_path getcwd . "/public/css/vendor"; + make_path getcwd . "/public/css/webfonts"; + make_path getcwd . "/public/js/vendor"; +@@ -212,19 +162,3 @@ sub cp_node_module { + + } + +-sub install_package { +- +- my $package = $_[0]; +- my $cpanopt = $_[1]; +- +- ## no critic +- eval "require $package"; #Run-time evals are needed here to check if the package has been properly installed. +- ## use critic +- +- if ($@) { +- say("$package not installed! Trying to install now using cpanm$cpanopt"); +- system("cpanm $package $cpanopt"); +- } else { +- say("$package package installed, proceeding..."); +- } +-} diff --git a/pkgs/by-name/la/lanraragi/loosen-dep-reqs.patch b/pkgs/by-name/la/lanraragi/loosen-dep-reqs.patch new file mode 100644 index 000000000000..1b2ec4c1fd81 --- /dev/null +++ b/pkgs/by-name/la/lanraragi/loosen-dep-reqs.patch @@ -0,0 +1,13 @@ +diff --git a/tools/cpanfile b/tools/cpanfile +index 7385aea7..22f9b069 100755 +--- a/tools/cpanfile ++++ b/tools/cpanfile +@@ -20,7 +20,7 @@ requires 'Sort::Naturally', 1.03; + requires 'Authen::Passphrase', 0.008; + requires 'File::ReadBackwards', 1.05; + requires 'URI::Escape', 1.74; +-requires 'URI', 5.09; ++requires 'URI', 5.05; + + # Used by Installer + requires 'IPC::Cmd', 1.02; diff --git a/pkgs/by-name/la/lanraragi/package.nix b/pkgs/by-name/la/lanraragi/package.nix index 74ec38eeae23..8b2ee5ff8c06 100644 --- a/pkgs/by-name/la/lanraragi/package.nix +++ b/pkgs/by-name/la/lanraragi/package.nix @@ -9,16 +9,47 @@ , nixosTests }: -let - perlEnv = perl.withPackages (_: cpanDeps); +buildNpmPackage rec { + pname = "lanraragi"; + version = "0.9.0"; - cpanDeps = with perl.pkgs; [ + src = fetchFromGitHub { + owner = "Difegue"; + repo = "LANraragi"; + rev = "v.${version}"; + hash = "sha256-euZotpXTUSmxlA5rbTUhHpHH0Ojd3AZjGasxYZ+L7NY="; + }; + + patches = [ + (fetchpatch { + name = "fix-redis-auth.patch"; + url = "https://github.com/Difegue/LANraragi/commit/1711b39759ad02ab2a8863ce1f35f6479c9a2917.patch"; + hash = "sha256-WfKeieysIlS64qgVEc75JFKjxXuvZN85M6US/gwjTzw="; + }) + (fetchpatch { + name = "fix-ghostscript-device.patch"; + url = "https://github.com/Difegue/LANraragi/commit/087d63b11c89fda8cb3a30cdb2e86ecd6be66bb7.patch"; + hash = "sha256-Cu9d/dDlO0yuFCTKOyg5A0gIuiA+FcWD9PjexB/BK0U="; + }) + ./install.patch + ./loosen-dep-reqs.patch # Can be removed once perl.pkgs.URI is updated + ./fix-paths.patch + ./expose-password-hashing.patch # Used by the NixOS module + ]; + + npmDepsHash = "sha256-/F/lhQIVGbbFxFuQXXwHUVlV2jhHt0hFf94v0FrTKt8="; + + nativeBuildInputs = [ perl makeBinaryWrapper ]; + + buildInputs = with perl.pkgs; [ + perl ImageMagick locallib Redis Encode ArchiveLibarchiveExtract ArchiveLibarchivePeek + ListMoreUtils NetDNSNative SortNaturally AuthenPassphrase @@ -39,50 +70,17 @@ let FileChangeNotify ModulePluggable TimeLocal + YAMLSyck + StringSimilarity ] ++ lib.optional stdenv.isLinux LinuxInotify2; -in -buildNpmPackage rec { - pname = "lanraragi"; - version = "0.8.90"; - - src = fetchFromGitHub { - owner = "Difegue"; - repo = "LANraragi"; - rev = "v.${version}"; - hash = "sha256-ljnREUGCKvUJvcQ+aJ6XqiMTkVmfjt/0oC47w3PCj/k="; - }; - - patches = [ - (fetchpatch { - name = "add-package-lock-json.patch"; # Can be removed when updating to 0.9.0 - url = "https://github.com/Difegue/LANraragi/commit/c5cd8641795bf7e40deef4ae955ea848dde44050.patch"; - hash = "sha256-XKxRzeugkIe6N4XRN6+O1wEZpxo6OzU0OaG0ywKFv38="; - }) - ./install.patch - ./fix-paths.patch - ./expose-password-hashing.patch - ./fix-minion-redis-password.patch # Should be upstreamed - ]; - - npmFlags = [ "--legacy-peer-deps" ]; - - npmDepsHash = "sha256-UQsChPU5b4+r5Kv6P/3rJCGUzssiUNSKo3w4axNyJew="; - - nativeBuildInputs = [ - perl - makeBinaryWrapper - perl.pkgs.Appcpanminus - ] ++ cpanDeps; - - nativeCheckInputs = with perl.pkgs; [ - TestMockObject - TestTrap - TestDeep - ]; buildPhase = '' runHook preBuild + # Check if every perl dependency was installed + # explicitly call cpanm with perl because the shebang is broken on darwin + perl ${perl.pkgs.Appcpanminus}/bin/cpanm --installdeps ./tools --notest + perl ./tools/install.pl install-full rm -r node_modules public/js/vendor/*.map public/css/vendor/*.map @@ -91,6 +89,12 @@ buildNpmPackage rec { doCheck = true; + nativeCheckInputs = with perl.pkgs; [ + TestMockObject + TestTrap + TestDeep + ]; + checkPhase = '' runHook preCheck @@ -104,19 +108,23 @@ buildNpmPackage rec { runHook preInstall mkdir -p $out/share/lanraragi - cp -r lib public script templates package.json $out/share/lanraragi + chmod +x script/launcher.pl + cp -r lib public script templates package.json lrr.conf $out/share/lanraragi - makeWrapper ${perlEnv}/bin/perl $out/bin/lanraragi \ + makeWrapper $out/share/lanraragi/script/launcher.pl $out/bin/lanraragi \ + --prefix PERL5LIB : $PERL5LIB \ --prefix PATH : ${lib.makeBinPath [ ghostscript ]} \ - --add-flags "$out/share/lanraragi/script/launcher.pl -f $out/share/lanraragi/script/lanraragi" + --run "cp -n --no-preserve=all $out/share/lanraragi/lrr.conf ./lrr.conf 2>/dev/null || true" \ + --add-flags "-f $out/share/lanraragi/script/lanraragi" + + makeWrapper ${lib.getExe perl} $out/bin/helpers/lrr-make-password-hash \ + --prefix PERL5LIB : $out/share/lanraragi/lib:$PERL5LIB \ + --add-flags "-e 'use LANraragi::Controller::Config; print LANraragi::Controller::Config::make_password_hash(@ARGV[0])' 2>/dev/null" runHook postInstall ''; - passthru = { - inherit perlEnv; - tests = { inherit (nixosTests) lanraragi; }; - }; + passthru.tests.module = nixosTests.lanraragi; meta = { changelog = "https://github.com/Difegue/LANraragi/releases/tag/${src.rev}"; @@ -128,3 +136,4 @@ buildNpmPackage rec { platforms = lib.platforms.unix; }; } +