remove photoprism, go back to loginShellInit hm activation

This commit is contained in:
Gabriel Fontes
2022-06-06 02:29:10 -03:00
parent fd189f29fd
commit 1fcbc4cbb5
14 changed files with 7 additions and 33483 deletions
-1
View File
@@ -1,6 +1,5 @@
{
argonone = ./argonone.nix;
openrgb = ./openrgb.nix;
photoprism = ./photoprism.nix;
satisfactory = ./satisfactory.nix;
}
-290
View File
@@ -1,290 +0,0 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.photoprism;
defaultUser = "photoprism";
defaultGroup = defaultUser;
in
{
options.services.photoprism = with lib; {
enable = mkEnableOption "photoprism";
user = mkOption {
type = types.str;
default = defaultUser;
example = "yourUser";
description = ''
The user to run Photoprism as.
By default, a user named <literal>${defaultUser}</literal> will be created.
'';
};
group = mkOption {
type = types.str;
default = defaultGroup;
example = "yourGroup";
description = ''
The group to run Photoprism under.
By default, a group named <literal>${defaultGroup}</literal> will be created.
'';
};
host = mkOption {
type = types.str;
default = "127.0.0.1";
example = "0.0.0.0";
description = "The address to serve the web interface at.";
};
port = mkOption {
type = types.int;
default = 2342;
description = "The port to serve the web interface at.";
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = "Open the web interface port in the firewall for photoprism.";
};
databaseDriver = mkOption {
type = types.enum [ "sqlite" "mysql" ];
default = "sqlite";
description = ''
Database driver, select mysql to use an embedded database.
Photoprism recommends a maria database (using the
<literal>"mysql"</literal> driver) to improve performance.
'';
};
databaseDsn = mkOption {
type = types.nullOr types.str;
default = null;
example = ''
photoprism@unix(/run/mysqld/mysqld.sock)/photoprism?charset=utf8mb4,utf8&parseTime=true
'';
description = ''
Photoprism database source name. Valid only when
<link linkend="opt-services.photoprism.databaseDriver">databaseDriver</link>
is set to <literal>"mysql"</literal>.
'';
};
initialPassword = mkOption {
type = types.str;
default = "insecure";
description = ''
Initial admin password.
This should be changed in the web UI after the first startup.
'';
};
detectNsfw = mkOption {
type = types.bool;
default = false;
description = ''
Flag photos as private that MAY be offensive.
'';
};
allowNsfw = mkOption {
type = types.bool;
default = true;
description = ''
Allow uploads that MAY be offensive.
'';
};
experimental = mkOption {
type = types.bool;
default = false;
description = ''
Enable experimental features.
'';
};
originalsLimit = mkOption {
type = types.int;
default = 5000;
description = ''
File size limit for originals in MB (increase for high-res video).
'';
};
public = mkOption {
type = types.bool;
default = false;
description = ''
No authentication required (disables password protection).
'';
};
readonly = mkOption {
type = types.bool;
default = false;
description = ''
Do not modify originals directory (reduced functionality).
'';
};
originalsDir = mkOption {
type = types.str;
example = "/mnt/nas/photos";
description = "Path to your photos.";
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/photoprism";
description = "Data directory for photoprism.";
};
siteTitle = mkOption {
type = types.str;
default = "PhotoPrism";
description = "Web UI title.";
};
siteCaption = mkOption {
type = types.str;
default = "Browse Your Life";
description = "Web UI caption.";
};
extraEnv = mkOption {
type = types.attrsOf types.str;
default = { };
example = { PHOTOPRISM_DEBUG = "true"; };
description = ''
Additional environment variables for the photoprism service.
See <link xlink:href="https://dl.photoprism.app/docker/docker-compose.yml"/>
and <link xlink:href="https://github.com/photoprism/photoprism/blob/develop/internal/config/flags.go">
for the supported environment variables.
'';
};
package = mkOption {
type = types.package;
default = pkgs.photoprism;
description = "Photoprism package to use.";
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.databaseDriver == "sqlite" -> (cfg.databaseDsn == null);
message = "SQLite is an internal database, databaseDsn must be null";
}
{
assertion = cfg.databaseDriver == "mysql" -> (cfg.databaseDsn != null);
message = "databaseDsn must be provided when using mysql databases";
}
];
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
users = {
users.${cfg.user} = {
inherit (cfg) group;
home = cfg.dataDir;
createHome = true;
isSystemUser = true;
};
groups.${cfg.group} = { };
};
systemd.services.photoprism = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/photoprism --assets-path ${cfg.package}/assets start
'';
User = cfg.user;
Group = cfg.group;
# hardening
DevicePolicy = "closed";
CapabilityBoundingSet = "";
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" "AF_NETLINK" ];
DeviceAllow = "";
NoNewPrivileges = true;
PrivateDevices = true;
PrivateMounts = true;
PrivateTmp = true;
PrivateUsers = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectSystem = "strict";
BindPaths = [
cfg.dataDir
cfg.originalsDir
] ++ lib.optionals (cfg.databaseDriver == "mysql") [
"-/run/mysqld"
"-/var/run/mysqld"
];
LockPersonality = true;
RemoveIPC = true;
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [
"~@clock"
"~@debug"
"~@module"
"~@mount"
"~@raw-io"
"~@reboot"
"~@swap"
"~@privileged"
"~@resources"
"~@cpu-emulation"
"~@obsolete"
];
SystemCallErrorNumber = "EPERM";
ProtectHostname = true;
};
environment = lib.recursiveUpdate {
PHOTOPRISM_ADMIN_PASSWORD = cfg.initialPassword;
PHOTOPRISM_HTTP_HOST = cfg.host;
PHOTOPRISM_HTTP_PORT = toString cfg.port;
PHOTOPRISM_SITE_URL = "http://${cfg.host}:${toString cfg.port}/";
PHOTOPRISM_DATABASE_DRIVER = cfg.databaseDriver;
PHOTOPRISM_DATABASE_DSN =
if cfg.databaseDriver == "sqlite" then "${cfg.dataDir}/photoprism.sqlite"
else cfg.databaseDsn;
PHOTOPRISM_DETECT_NSFW = toString cfg.detectNsfw;
PHOTOPRISM_UPLOAD_NSFW = toString cfg.allowNsfw;
PHOTOPRISM_EXPERIMENTAL = toString cfg.experimental;
PHOTOPRISM_ORIGINALS_LIMIT = toString cfg.originalsLimit;
PHOTOPRISM_PUBLIC = toString cfg.public;
PHOTOPRISM_READONLY = toString cfg.readonly;
PHOTOPRISM_SITE_TITLE = cfg.siteTitle;
PHOTOPRISM_SITE_CAPTION = cfg.siteCaption;
PHOTOPRISM_SIDECAR_PATH = "${cfg.dataDir}/sidecar";
PHOTOPRISM_STORAGE_PATH = "${cfg.dataDir}/storage";
PHOTOPRISM_ASSETS_PATH = "${cfg.package}/assets";
PHOTOPRISM_ORIGINALS_PATH = cfg.originalsDir;
PHOTOPRISM_IMPORT_PATH = "${cfg.dataDir}/import";
} cfg.extraEnv;
};
};
}
+7 -7
View File
@@ -10,11 +10,11 @@
./users.nix
];
system = {
stateVersion = "22.05";
# Activate home-manager config when booting
userActivationScripts = {
activate-hm.text = "/nix/var/nix/profiles/per-user/$USER/home-manager/activate";
};
};
# Activate home-manager environment, if not already
environment.loginShellInit = ''
[ -d "$HOME/.nix-profile" ] || /nix/var/nix/profiles/per-user/$USER/home-manager/activate &> /dev/null
'';
system.stateVersion = "22.05";
}
-27
View File
@@ -1,27 +0,0 @@
{ lib, config, persistence, ... }: {
services = {
photoprism = {
enable = true;
originalsDir = "/media/photos";
};
nginx.virtualHosts =
let
location = "http://localhost:${toString config.services.photoprism.port}";
in
{
"photos.misterio.me" = {
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = location;
proxyWebsockets = true;
};
};
};
};
environment.persistence = lib.mkIf persistence {
"/persist".directories = [ "/var/lib/photoprism" ];
};
}
-8
View File
@@ -1,8 +0,0 @@
{ inputs, ... }: {
imports = [ inputs.sistemer-bot.nixosModule ];
services.sistemer-bot = {
enable = true;
tokenFile = "/srv/sistemer_bot.key";
};
}
-1
View File
@@ -6,7 +6,6 @@
comma = pkgs.callPackage ./comma { };
minicava = pkgs.callPackage ./minicava { };
pass-wofi = pkgs.callPackage ./pass-wofi { };
photoprism = pkgs.callPackage ./photoprism { };
preferredplayer = pkgs.callPackage ./preferredplayer { };
rgbdaemon = pkgs.callPackage ./rgbdaemon { };
shellcolord = pkgs.callPackage ./shellcolord { };
-3
View File
@@ -1,3 +0,0 @@
_package-lock.json linguist-generated
node-env.nix linguist-generated
node-packages.nix linguist-generated
-21608
View File
File diff suppressed because it is too large Load Diff
-209
View File
@@ -1,209 +0,0 @@
{ lib, pkgs, stdenv, buildGoModule, fetchFromGitHub, fetchzip, coreutils, fetchurl, darktable, rawtherapee, ffmpeg, libheif, exiftool, nodejs }:
with lib;
let
version = "220302-0059f429";
pname = "photoprism";
inherit (stdenv.hostPlatform) system;
src = fetchFromGitHub {
owner = pname;
repo = pname;
rev = version;
sha256 = "sha256-hEA2E5ty9j9BH7DviYh5meao0ot0alPgMoJcplJDRc4=";
};
fetchModel = { name, sha256 }:
fetchzip {
inherit sha256;
url = "https://dl.photoprism.org/tensorflow/${name}.zip";
stripRoot = false;
};
facenet = fetchModel {
name = "facenet";
sha256 = "sha256-aS5kkNhxOLSLTH/ipxg7NAa1w9X8iiG78jmloR1hpRo=";
};
nasnet = fetchModel {
name = "nasnet";
sha256 = "sha256-bF25jPmZLyeSWy/CGXZE/VE2UupEG2q9Jmr0+1rUYWE=";
};
nsfw = fetchModel {
name = "nsfw";
sha256 = "sha256-zy/HcmgaHOY7FfJUY6I/yjjsMPHR2Ote9ppwqemBlfg=";
};
libtensorflow = stdenv.mkDerivation rec {
pname = "libtensorflow-photoprism";
version = "1.15.2";
srcs = [
# Photoprism-packaged libtensorflow tarball (with pre-built libs for both arm64 and amd64)
# We need this specific version because of https://github.com/photoprism/photoprism/issues/222
(fetchurl {
sha256 = {
x86_64-linux = "sha256-bZAC3PJxqcjuGM4RcNtzYtkg3FD3SrO5beDsPoKenzc=";
aarch64-linux = "sha256-qnj4vhSWgrk8SIjzIH1/4waMxMsxMUvqdYZPaSaUJRk=";
}.${system} or (throw "Unsupported system");
url =
let
systemName = {
x86_64-linux = "amd64";
aarch64-linux = "arm64";
}.${system} or (throw "Unsupported system");
in
"https://dl.photoprism.app/tensorflow/${systemName}/libtensorflow-${systemName}-${version}.tar.gz";
})
# Upstream tensorflow tarball (with .h's photoprism's tarball is missing)
(fetchurl {
# Can't seem to find 1.15.2 tarball, but this works fine.
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.15.0.tar.gz";
sha256 = "sha256-3sv9WnCeztNSP1XM+iOTN6h+GrPgAO/aNhfbeeEDTe0=";
})
];
sourceRoot = ".";
unpackPhase = ''
sources=($srcs)
mkdir downstream upstream
tar xf ''${sources[0]} --directory downstream
tar xf ''${sources[1]} --directory upstream
mv downstream/lib .
mv upstream/{include,LICENSE,THIRD_PARTY_TF_C_LICENSES} .
rm -r downstream upstream
cd lib
ln -sT libtensorflow.so{,.1}
ln -sT libtensorflow_framework.so{,.1}
cd ..
'';
# Patch library to use our libc, libstdc++ and others
patchPhase =
let
rpath = makeLibraryPath [ stdenv.cc.libc stdenv.cc.cc.lib ];
in
''
chmod -R +w lib
patchelf --set-rpath "${rpath}:$out/lib" lib/libtensorflow.so
patchelf --set-rpath "${rpath}" lib/libtensorflow_framework.so
'';
buildPhase = ''
# Write pkg-config file.
mkdir lib/pkgconfig
cat > lib/pkgconfig/tensorflow.pc << EOF
Name: TensorFlow
Version: ${version}
Description: Library for computation using data flow graphs for scalable machine learning
Requires:
Libs: -L$out/lib -ltensorflow
Cflags: -I$out/include/tensorflow
EOF
'';
installPhase = ''
mkdir -p $out
cp -r LICENSE THIRD_PARTY_TF_C_LICENSES lib include $out
'';
};
backend = buildGoModule rec {
inherit pname version src;
buildInputs = [
coreutils
libtensorflow
];
postPatch = ''
substituteInPlace internal/commands/passwd.go --replace '/bin/stty' "${coreutils}/bin/stty"
'';
vendorSha256 = "sha256-GaMV1SFDTCgZMZz0lYAKqqqX5zW+pU39vnwtlz2UDbQ=";
subPackages = [ "cmd/photoprism" ];
# https://github.com/mattn/go-sqlite3/issues/822
CGO_CFLAGS = "-Wno-return-local-addr";
# https://github.com/tensorflow/tensorflow/issues/43847
CGO_LDFLAGS = "-fuse-ld=gold";
};
inherit (import ./node-composition.nix {
inherit pkgs nodejs system;
}) nodeDependencies;
frontend = stdenv.mkDerivation {
name = "photoprism-frontend";
inherit src;
buildInputs = [ nodejs ];
buildPhase = ''
runHook preBuild
pushd frontend
ln -s ${nodeDependencies}/lib/node_modules ./node_modules
export PATH="${nodeDependencies}/bin:$PATH"
NODE_ENV=production npm run build
popd
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir $out
cp -r assets $out/
runHook postInstall
'';
};
in
stdenv.mkDerivation {
inherit pname version;
buildInputs = [
darktable
rawtherapee
ffmpeg
libheif
exiftool
];
phases = [ "installPhase" ];
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,assets}
# install backend
cp ${backend}/bin/photoprism $out/bin/photoprism
# install frontend
cp -r ${frontend}/assets $out/
# install tensorflow models
cp -r ${nasnet}/nasnet $out/assets
cp -r ${nsfw}/nsfw $out/assets
cp -r ${facenet}/facenet $out/assets
runHook postInstall
'';
meta = with lib; {
homepage = "https://photoprism.app";
description = "Personal Photo Management powered by Go and Google TensorFlow";
platforms = [ "x86_64-linux" "aarch64-linux" ];
license = licenses.agpl3;
maintainers = with maintainers; [ newam ];
};
}
-8
View File
@@ -1,8 +0,0 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p nodePackages.node2nix
node2nix \
--node-env ./node-env.nix \
--lock _package-lock.json \
--output node-packages.nix \
--composition node-composition.nix
-17
View File
@@ -1,17 +0,0 @@
# This file has been generated by node2nix 1.9.0. Do not edit!
{pkgs ? import <nixpkgs> {
inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}:
let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript;
inherit pkgs nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages.nix {
inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
inherit nodeEnv;
}
-577
View File
@@ -1,577 +0,0 @@
# This file originates from node2nix
{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}:
let
# Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
utillinux = pkgs.utillinux or pkgs.util-linux;
python = nodejs.python or python2;
# Create a tar wrapper that filters all the 'Ignoring unknown extended header keyword' noise
tarWrapper = runCommand "tarWrapper" {} ''
mkdir -p $out/bin
cat > $out/bin/tar <<EOF
#! ${stdenv.shell} -e
$(type -p tar) "\$@" --warning=no-unknown-keyword --delay-directory-restore
EOF
chmod +x $out/bin/tar
'';
# Function that generates a TGZ file from a NPM project
buildNodeSourceDist =
{ name, version, src, ... }:
stdenv.mkDerivation {
name = "node-tarball-${name}-${version}";
inherit src;
buildInputs = [ nodejs ];
buildPhase = ''
export HOME=$TMPDIR
tgzFile=$(npm pack | tail -n 1) # Hooks to the pack command will add output (https://docs.npmjs.com/misc/scripts)
'';
installPhase = ''
mkdir -p $out/tarballs
mv $tgzFile $out/tarballs
mkdir -p $out/nix-support
echo "file source-dist $out/tarballs/$tgzFile" >> $out/nix-support/hydra-build-products
'';
};
# Common shell logic
installPackage = writeShellScript "install-package" ''
installPackage() {
local packageName=$1 src=$2
local strippedName
local DIR=$PWD
cd $TMPDIR
unpackFile $src
# Make the base dir in which the target dependency resides first
mkdir -p "$(dirname "$DIR/$packageName")"
if [ -f "$src" ]
then
# Figure out what directory has been unpacked
packageDir="$(find . -maxdepth 1 -type d | tail -1)"
# Restore write permissions to make building work
find "$packageDir" -type d -exec chmod u+x {} \;
chmod -R u+w "$packageDir"
# Move the extracted tarball into the output folder
mv "$packageDir" "$DIR/$packageName"
elif [ -d "$src" ]
then
# Get a stripped name (without hash) of the source directory.
# On old nixpkgs it's already set internally.
if [ -z "$strippedName" ]
then
strippedName="$(stripHash $src)"
fi
# Restore write permissions to make building work
chmod -R u+w "$strippedName"
# Move the extracted directory into the output folder
mv "$strippedName" "$DIR/$packageName"
fi
# Change to the package directory to install dependencies
cd "$DIR/$packageName"
}
'';
# Bundle the dependencies of the package
#
# Only include dependencies if they don't exist. They may also be bundled in the package.
includeDependencies = {dependencies}:
lib.optionalString (dependencies != []) (
''
mkdir -p node_modules
cd node_modules
''
+ (lib.concatMapStrings (dependency:
''
if [ ! -e "${dependency.name}" ]; then
${composePackage dependency}
fi
''
) dependencies)
+ ''
cd ..
''
);
# Recursively composes the dependencies of a package
composePackage = { packageName, src, dependencies ? [], ... }:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
installPackage "${packageName}" "${src}"
${includeDependencies { inherit dependencies; }}
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
'';
pinpointDependencies = {dependencies, production}:
let
pinpointDependenciesFromPackageJSON = writeTextFile {
name = "pinpointDependencies.js";
text = ''
var fs = require('fs');
var path = require('path');
function resolveDependencyVersion(location, name) {
if(location == process.env['NIX_STORE']) {
return null;
} else {
var dependencyPackageJSON = path.join(location, "node_modules", name, "package.json");
if(fs.existsSync(dependencyPackageJSON)) {
var dependencyPackageObj = JSON.parse(fs.readFileSync(dependencyPackageJSON));
if(dependencyPackageObj.name == name) {
return dependencyPackageObj.version;
}
} else {
return resolveDependencyVersion(path.resolve(location, ".."), name);
}
}
}
function replaceDependencies(dependencies) {
if(typeof dependencies == "object" && dependencies !== null) {
for(var dependency in dependencies) {
var resolvedVersion = resolveDependencyVersion(process.cwd(), dependency);
if(resolvedVersion === null) {
process.stderr.write("WARNING: cannot pinpoint dependency: "+dependency+", context: "+process.cwd()+"\n");
} else {
dependencies[dependency] = resolvedVersion;
}
}
}
}
/* Read the package.json configuration */
var packageObj = JSON.parse(fs.readFileSync('./package.json'));
/* Pinpoint all dependencies */
replaceDependencies(packageObj.dependencies);
if(process.argv[2] == "development") {
replaceDependencies(packageObj.devDependencies);
}
replaceDependencies(packageObj.optionalDependencies);
/* Write the fixed package.json file */
fs.writeFileSync("package.json", JSON.stringify(packageObj, null, 2));
'';
};
in
''
node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"}
${lib.optionalString (dependencies != [])
''
if [ -d node_modules ]
then
cd node_modules
${lib.concatMapStrings pinpointDependenciesOfPackage dependencies}
cd ..
fi
''}
'';
# Recursively traverses all dependencies of a package and pinpoints all
# dependencies in the package.json file to the versions that are actually
# being used.
pinpointDependenciesOfPackage = { packageName, dependencies ? [], production ? true, ... }:
''
if [ -d "${packageName}" ]
then
cd "${packageName}"
${pinpointDependencies { inherit dependencies production; }}
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
fi
'';
# Extract the Node.js source code which is used to compile packages with
# native bindings
nodeSources = runCommand "node-sources" {} ''
tar --no-same-owner --no-same-permissions -xf ${nodejs.src}
mv node-* $out
'';
# Script that adds _integrity fields to all package.json files to prevent NPM from consulting the cache (that is empty)
addIntegrityFieldsScript = writeTextFile {
name = "addintegrityfields.js";
text = ''
var fs = require('fs');
var path = require('path');
function augmentDependencies(baseDir, dependencies) {
for(var dependencyName in dependencies) {
var dependency = dependencies[dependencyName];
// Open package.json and augment metadata fields
var packageJSONDir = path.join(baseDir, "node_modules", dependencyName);
var packageJSONPath = path.join(packageJSONDir, "package.json");
if(fs.existsSync(packageJSONPath)) { // Only augment packages that exist. Sometimes we may have production installs in which development dependencies can be ignored
console.log("Adding metadata fields to: "+packageJSONPath);
var packageObj = JSON.parse(fs.readFileSync(packageJSONPath));
if(dependency.integrity) {
packageObj["_integrity"] = dependency.integrity;
} else {
packageObj["_integrity"] = "sha1-000000000000000000000000000="; // When no _integrity string has been provided (e.g. by Git dependencies), add a dummy one. It does not seem to harm and it bypasses downloads.
}
if(dependency.resolved) {
packageObj["_resolved"] = dependency.resolved; // Adopt the resolved property if one has been provided
} else {
packageObj["_resolved"] = dependency.version; // Set the resolved version to the version identifier. This prevents NPM from cloning Git repositories.
}
if(dependency.from !== undefined) { // Adopt from property if one has been provided
packageObj["_from"] = dependency.from;
}
fs.writeFileSync(packageJSONPath, JSON.stringify(packageObj, null, 2));
}
// Augment transitive dependencies
if(dependency.dependencies !== undefined) {
augmentDependencies(packageJSONDir, dependency.dependencies);
}
}
}
if(fs.existsSync("./package-lock.json")) {
var packageLock = JSON.parse(fs.readFileSync("./package-lock.json"));
if(![1, 2].includes(packageLock.lockfileVersion)) {
process.stderr.write("Sorry, I only understand lock file versions 1 and 2!\n");
process.exit(1);
}
if(packageLock.dependencies !== undefined) {
augmentDependencies(".", packageLock.dependencies);
}
}
'';
};
# Reconstructs a package-lock file from the node_modules/ folder structure and package.json files with dummy sha1 hashes
reconstructPackageLock = writeTextFile {
name = "addintegrityfields.js";
text = ''
var fs = require('fs');
var path = require('path');
var packageObj = JSON.parse(fs.readFileSync("package.json"));
var lockObj = {
name: packageObj.name,
version: packageObj.version,
lockfileVersion: 1,
requires: true,
dependencies: {}
};
function augmentPackageJSON(filePath, dependencies) {
var packageJSON = path.join(filePath, "package.json");
if(fs.existsSync(packageJSON)) {
var packageObj = JSON.parse(fs.readFileSync(packageJSON));
dependencies[packageObj.name] = {
version: packageObj.version,
integrity: "sha1-000000000000000000000000000=",
dependencies: {}
};
processDependencies(path.join(filePath, "node_modules"), dependencies[packageObj.name].dependencies);
}
}
function processDependencies(dir, dependencies) {
if(fs.existsSync(dir)) {
var files = fs.readdirSync(dir);
files.forEach(function(entry) {
var filePath = path.join(dir, entry);
var stats = fs.statSync(filePath);
if(stats.isDirectory()) {
if(entry.substr(0, 1) == "@") {
// When we encounter a namespace folder, augment all packages belonging to the scope
var pkgFiles = fs.readdirSync(filePath);
pkgFiles.forEach(function(entry) {
if(stats.isDirectory()) {
var pkgFilePath = path.join(filePath, entry);
augmentPackageJSON(pkgFilePath, dependencies);
}
});
} else {
augmentPackageJSON(filePath, dependencies);
}
}
});
}
}
processDependencies("node_modules", lockObj.dependencies);
fs.writeFileSync("package-lock.json", JSON.stringify(lockObj, null, 2));
'';
};
prepareAndInvokeNPM = {packageName, bypassCache, reconstructLock, npmFlags, production}:
let
forceOfflineFlag = if bypassCache then "--offline" else "--registry http://www.example.com";
in
''
# Pinpoint the versions of all dependencies to the ones that are actually being used
echo "pinpointing versions of dependencies..."
source $pinpointDependenciesScriptPath
# Patch the shebangs of the bundled modules to prevent them from
# calling executables outside the Nix store as much as possible
patchShebangs .
# Deploy the Node.js package by running npm install. Since the
# dependencies have been provided already by ourselves, it should not
# attempt to install them again, which is good, because we want to make
# it Nix's responsibility. If it needs to install any dependencies
# anyway (e.g. because the dependency parameters are
# incomplete/incorrect), it fails.
#
# The other responsibilities of NPM are kept -- version checks, build
# steps, postprocessing etc.
export HOME=$TMPDIR
cd "${packageName}"
runHook preRebuild
${lib.optionalString bypassCache ''
${lib.optionalString reconstructLock ''
if [ -f package-lock.json ]
then
echo "WARNING: Reconstruct lock option enabled, but a lock file already exists!"
echo "This will most likely result in version mismatches! We will remove the lock file and regenerate it!"
rm package-lock.json
else
echo "No package-lock.json file found, reconstructing..."
fi
node ${reconstructPackageLock}
''}
node ${addIntegrityFieldsScript}
''}
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} rebuild
if [ "''${dontNpmInstall-}" != "1" ]
then
# NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
rm -f npm-shrinkwrap.json
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} install
fi
'';
# Builds and composes an NPM package including all its dependencies
buildNodePackage =
{ name
, packageName
, version
, buildInputs ? []
, production ? true
, npmFlags ? ""
, dontNpmInstall ? false
, bypassCache ? false
, reconstructLock ? false
, preRebuild ? ""
, dontStrip ? true
, unpackPhase ? "true"
, buildPhase ? "true"
, meta ? {}
, ... }@args:
let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta" ];
in
stdenv.mkDerivation ({
name = "${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ lib.optional stdenv.isLinux utillinux
++ lib.optional stdenv.isDarwin libtool
++ buildInputs;
inherit nodejs;
inherit dontStrip; # Stripping may fail a build for some package deployments
inherit dontNpmInstall preRebuild unpackPhase buildPhase;
compositionScript = composePackage args;
pinpointDependenciesScript = pinpointDependenciesOfPackage args;
passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
installPhase = ''
source ${installPackage}
# Create and enter a root node_modules/ folder
mkdir -p $out/lib/node_modules
cd $out/lib/node_modules
# Compose the package and all its dependencies
source $compositionScriptPath
${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }}
# Create symlink to the deployed executable folder, if applicable
if [ -d "$out/lib/node_modules/.bin" ]
then
ln -s $out/lib/node_modules/.bin $out/bin
fi
# Create symlinks to the deployed manual page folders, if applicable
if [ -d "$out/lib/node_modules/${packageName}/man" ]
then
mkdir -p $out/share
for dir in "$out/lib/node_modules/${packageName}/man/"*
do
mkdir -p $out/share/man/$(basename "$dir")
for page in "$dir"/*
do
ln -s $page $out/share/man/$(basename "$dir")
done
done
fi
# Run post install hook, if provided
runHook postInstall
'';
meta = {
# default to Node.js' platforms
inherit (nodejs.meta) platforms;
} // meta;
} // extraArgs);
# Builds a node environment (a node_modules folder and a set of binaries)
buildNodeDependencies =
{ name
, packageName
, version
, src
, dependencies ? []
, buildInputs ? []
, production ? true
, npmFlags ? ""
, dontNpmInstall ? false
, bypassCache ? false
, reconstructLock ? false
, dontStrip ? true
, unpackPhase ? "true"
, buildPhase ? "true"
, ... }@args:
let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ];
in
stdenv.mkDerivation ({
name = "node-dependencies-${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ lib.optional stdenv.isLinux utillinux
++ lib.optional stdenv.isDarwin libtool
++ buildInputs;
inherit dontStrip; # Stripping may fail a build for some package deployments
inherit dontNpmInstall unpackPhase buildPhase;
includeScript = includeDependencies { inherit dependencies; };
pinpointDependenciesScript = pinpointDependenciesOfPackage args;
passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
installPhase = ''
source ${installPackage}
mkdir -p $out/${packageName}
cd $out/${packageName}
source $includeScriptPath
# Create fake package.json to make the npm commands work properly
cp ${src}/package.json .
chmod 644 package.json
${lib.optionalString bypassCache ''
if [ -f ${src}/package-lock.json ]
then
cp ${src}/package-lock.json .
fi
''}
# Go to the parent folder to make sure that all packages are pinpointed
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }}
# Expose the executables that were installed
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
mv ${packageName} lib
ln -s $out/lib/node_modules/.bin $out/bin
'';
} // extraArgs);
# Builds a development shell
buildNodeShell =
{ name
, version
, dependencies ? []
, buildInputs ? []
, ... }@args:
let
nodeDependencies = buildNodeDependencies args;
in
stdenv.mkDerivation {
name = "node-shell-${name}-${version}";
buildInputs = [ python nodejs ] ++ lib.optional stdenv.isLinux utillinux ++ buildInputs;
buildCommand = ''
mkdir -p $out/bin
cat > $out/bin/shell <<EOF
#! ${stdenv.shell} -e
$shellHook
exec ${stdenv.shell}
EOF
chmod +x $out/bin/shell
'';
# Provide the dependencies in a development shell through the NODE_PATH environment variable
inherit nodeDependencies;
shellHook = lib.optionalString (dependencies != []) ''
export NODE_PATH=${nodeDependencies}/lib/node_modules
export PATH="${nodeDependencies}/bin:$PATH"
'';
};
in
{
buildNodeSourceDist = lib.makeOverridable buildNodeSourceDist;
buildNodePackage = lib.makeOverridable buildNodePackage;
buildNodeDependencies = lib.makeOverridable buildNodeDependencies;
buildNodeShell = lib.makeOverridable buildNodeShell;
}
File diff suppressed because it is too large Load Diff
-129
View File
@@ -1,129 +0,0 @@
{
"name": "photoprism",
"version": "1.0.0",
"description": "PhotoPrism Progressive Web App (PWA)",
"author": "Michael Mayer",
"license": "AGPL-3.0",
"private": true,
"scripts": {
"watch": "webpack --watch",
"build": "webpack --node-env=production",
"trace": "webpack --stats-children",
"lint": "eslint --cache src/ *.js",
"fmt": "eslint --cache --fix src/ *.js .eslintrc.js",
"test": "karma start",
"upgrade": "npm --depth 10 update && npm audit fix",
"acceptance": "testcafe chromium:headless --skip-js-errors --quarantine-mode --selector-timeout 5000 -S -s tests/screenshots tests/acceptance",
"acceptance-firefox": "testcafe firefox:headless --skip-js-errors --quarantine-mode --selector-timeout 5000 -S -s tests/screenshots tests/acceptance",
"acceptance-private": "testcafe chromium:headless --skip-js-errors --quarantine-mode --selector-timeout 5000 -S -s tests/screenshots tests/acceptance-private",
"acceptance-private-firefox": "testcafe firefox:headless --skip-js-errors --quarantine-mode --selector-timeout 5000 -S -s tests/screenshots tests/acceptance-private",
"acceptance-local": "testcafe chromium --selector-timeout 5000 -S -s tests/screenshots tests/acceptance",
"gettext-extract": "gettext-extract --output src/locales/translations.pot $(find src -type f \\( -iname \\*.vue -o -iname \\*.js \\) -not -path src/common/vm.js)",
"gettext-compile": "gettext-compile --output src/locales/translations.json src/locales/*.po"
},
"dependencies": {
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.10",
"@babel/eslint-parser": "^7.16.5",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.16.8",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.16.10",
"@babel/register": "^7.16.9",
"@babel/runtime": "^7.16.7",
"@lcdp/offline-plugin": "^5.1.0",
"@vvo/tzdb": "^6.44.0",
"axios": "^0.26.0",
"axios-mock-adapter": "^1.19.0",
"babel-loader": "^8.2.3",
"babel-plugin-istanbul": "^6.1.1",
"browserslist": "^4.19.1",
"chai": "^4.3.4",
"chrome-finder": "^1.0.7",
"core-js": "^3.21.0",
"cross-env": "^7.0.3",
"css-loader": "^6.5.1",
"cssnano": "^5.0.17",
"easygettext": "^2.17.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^17.0.0-1",
"eslint-formatter-pretty": "^4.1.0",
"eslint-plugin-html": "^6.2.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier-vue": "^3.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-vue": "^8.3.0",
"eslint-webpack-plugin": "^3.1.1",
"eventsource-polyfill": "^0.9.6",
"file-loader": "^6.2.0",
"file-saver": "^2.0.5",
"hls.js": "^1.1.3",
"i": "^0.3.7",
"karma": "^6.3.11",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-htmlfile-reporter": "^0.3.8",
"karma-mocha": "^2.0.1",
"karma-verbose-reporter": "^0.0.8",
"karma-webpack": "^5.0.0",
"luxon": "^2.3.0",
"maplibre-gl": "^2.1.1",
"material-design-icons-iconfont": "6.1.1",
"mini-css-extract-plugin": "^2.5.3",
"minimist": ">=1.2.5",
"mocha": "^9.0.2",
"node-storage-shim": "^2.0.1",
"photoswipe": "^4.1.3",
"postcss": "^8.4.6",
"postcss-import": "^14.0.2",
"postcss-loader": "^6.2.1",
"postcss-preset-env": "^7.4.1",
"postcss-reporter": "^7.0.5",
"postcss-url": "^10.1.3",
"prettier": "^2.5.1",
"pubsub-js": "^1.9.4",
"regenerator-runtime": "^0.13.9",
"resolve-url-loader": "^5.0.0",
"sass": "^1.48.0",
"sass-loader": "^12.4.0",
"server": "^1.0.37",
"sockette": "^2.0.6",
"style-loader": "^3.3.1",
"svg-url-loader": "^7.1.1",
"tar": "^6.1.11",
"url-loader": "^4.1.1",
"util": "^0.12.4",
"vue": "^2.6.14",
"vue-fullscreen": "^2.5.2",
"vue-gettext": "^2.1.12",
"vue-infinite-scroll": "^2.0.2",
"vue-loader": "^15.9.8",
"vue-loader-plugin": "^1.3.0",
"vue-luxon": "^0.10.0",
"vue-router": "^3.5.2",
"vue-style-loader": "^4.1.3",
"vue-template-compiler": "^2.6.14",
"vue2-filters": "^0.14.0",
"vuetify": "^1.5.24",
"webpack": "^5.66.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.1",
"webpack-hot-middleware": "^2.25.1",
"webpack-manifest-plugin": "^4.1.1",
"webpack-md5-hash": "^0.0.6",
"webpack-merge": "^5.8.0"
},
"engines": {
"node": ">= 14.0.0",
"npm": ">= 8.0.0",
"yarn": "please use npm"
},
"browserslist": [
"> 1%",
"not ie <= 9",
"last 3 versions"
]
}