fx_cast: 0.1.2 -> 0.2.0

Reviews:

- Just makes the error message a bit nicer. (kevincox)

Co-authored-by: Kevin Cox <kevincox@kevincox.ca>
This commit is contained in:
PedroHLC ☭ 2022-06-09 09:30:45 -03:00
parent 43ecbe7840
commit 6850695d67
No known key found for this signature in database
GPG Key ID: F5BFC029DA9A28CE
5 changed files with 4298 additions and 1432 deletions

View File

@ -3,14 +3,15 @@
# Update version and hash as usual. # Update version and hash as usual.
# #
# ``` # ```
# git clone https://github.com/hensm/fx_cast.git
# cd fx_cast/app # cd fx_cast/app
# # Add `"name": "fx_cast_bridge", "version": "...",` to package.json and package-lock.json # # Add `"name": "fx_cast_bridge", "version": "...",` to package.json and package-lock.json
# nix run nixpkgs.nodePackages.node2nix -c node2nix -l package-lock.json -d # nix run nixpkgs#nodePackages.node2nix -- -c node2nix -l package-lock.json -d
# cp -v node-*.nix package*.json ~/p/nixpkgs/pkgs/tools/misc/fx_cast/app # cp -v node-*.nix package*.json ${nixpkgs_path:?}/pkgs/tools/misc/fx_cast/
# ``` # ```
{ pkgs, stdenv }: let { pkgs, stdenv }: let
nodeEnv = import ./node-env.nix { nodeEnv = import ./node-env.nix {
inherit (pkgs) nodejs stdenv lib python2 runCommand writeTextFile; inherit (pkgs) nodejs stdenv lib python2 runCommand writeTextFile writeShellScript;
inherit pkgs; inherit pkgs;
libtool = if stdenv.isDarwin then pkgs.darwin.cctools else null; libtool = if stdenv.isDarwin then pkgs.darwin.cctools else null;
}; };
@ -22,13 +23,13 @@
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "fx_cast_bridge"; pname = "fx_cast_bridge";
version = "0.1.2"; version = "0.2.0";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "hensm"; owner = "hensm";
repo = "fx_cast"; repo = "fx_cast";
rev = "v${version}"; rev = "v${version}";
hash = "sha256:1prgk9669xgwkdl39clq0l75n0gnkkpn27gp9rbgl4bafrhvmg9a"; hash = "sha256-bgoItAOIHxGow7TjlRzaMqtIefcSym1h5n6v/9fFZfc=";
}; };
buildInputs = with pkgs; [ buildInputs = with pkgs; [
@ -37,7 +38,8 @@ stdenv.mkDerivation rec {
buildPhase = '' buildPhase = ''
ln -vs ${nodePackages.nodeDependencies}/lib/node_modules app/node_modules ln -vs ${nodePackages.nodeDependencies}/lib/node_modules app/node_modules
npm run build:app # The temporary home solves the "failed with exit code 243"
HOME="$(mktemp -d)" npm run build:app
''; '';
installPhase = '' installPhase = ''

View File

@ -1,6 +1,6 @@
# This file originates from node2nix # This file originates from node2nix
{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile}: {lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}:
let let
# Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master # Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
@ -40,36 +40,22 @@ let
''; '';
}; };
includeDependencies = {dependencies}: # Common shell logic
lib.optionalString (dependencies != []) installPackage = writeShellScript "install-package" ''
(lib.concatMapStrings (dependency: installPackage() {
'' local packageName=$1 src=$2
# Bundle the dependencies of the package
mkdir -p node_modules
cd node_modules
# Only include dependencies if they don't exist. They may also be bundled in the package. local strippedName
if [ ! -e "${dependency.name}" ]
then
${composePackage dependency}
fi
cd .. local DIR=$PWD
''
) dependencies);
# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
DIR=$(pwd)
cd $TMPDIR cd $TMPDIR
unpackFile ${src} unpackFile $src
# Make the base dir in which the target dependency resides first # Make the base dir in which the target dependency resides first
mkdir -p "$(dirname "$DIR/${packageName}")" mkdir -p "$(dirname "$DIR/$packageName")"
if [ -f "${src}" ] if [ -f "$src" ]
then then
# Figure out what directory has been unpacked # Figure out what directory has been unpacked
packageDir="$(find . -maxdepth 1 -type d | tail -1)" packageDir="$(find . -maxdepth 1 -type d | tail -1)"
@ -79,28 +65,53 @@ let
chmod -R u+w "$packageDir" chmod -R u+w "$packageDir"
# Move the extracted tarball into the output folder # Move the extracted tarball into the output folder
mv "$packageDir" "$DIR/${packageName}" mv "$packageDir" "$DIR/$packageName"
elif [ -d "${src}" ] elif [ -d "$src" ]
then then
# Get a stripped name (without hash) of the source directory. # Get a stripped name (without hash) of the source directory.
# On old nixpkgs it's already set internally. # On old nixpkgs it's already set internally.
if [ -z "$strippedName" ] if [ -z "$strippedName" ]
then then
strippedName="$(stripHash ${src})" strippedName="$(stripHash $src)"
fi fi
# Restore write permissions to make building work # Restore write permissions to make building work
chmod -R u+w "$strippedName" chmod -R u+w "$strippedName"
# Move the extracted directory into the output folder # Move the extracted directory into the output folder
mv "$strippedName" "$DIR/${packageName}" mv "$strippedName" "$DIR/$packageName"
fi fi
# Unset the stripped name to not confuse the next unpack step # Change to the package directory to install dependencies
unset strippedName cd "$DIR/$packageName"
}
'';
# Include the dependencies of the package # Bundle the dependencies of the package
cd "$DIR/${packageName}" #
# 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.packageName}" ]; then
${composePackage dependency}
fi
''
) dependencies)
+ ''
cd ..
''
);
# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
installPackage "${packageName}" "${src}"
${includeDependencies { inherit dependencies; }} ${includeDependencies { inherit dependencies; }}
cd .. cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
@ -379,7 +390,7 @@ let
buildNodePackage = buildNodePackage =
{ name { name
, packageName , packageName
, version , version ? null
, dependencies ? [] , dependencies ? []
, buildInputs ? [] , buildInputs ? []
, production ? true , production ? true
@ -391,13 +402,14 @@ let
, dontStrip ? true , dontStrip ? true
, unpackPhase ? "true" , unpackPhase ? "true"
, buildPhase ? "true" , buildPhase ? "true"
, meta ? {}
, ... }@args: , ... }@args:
let let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" ]; extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta" ];
in in
stdenv.mkDerivation ({ stdenv.mkDerivation ({
name = "node_${name}-${version}"; name = "${name}${if version == null then "" else "-${version}"}";
buildInputs = [ tarWrapper python nodejs ] buildInputs = [ tarWrapper python nodejs ]
++ lib.optional (stdenv.isLinux) utillinux ++ lib.optional (stdenv.isLinux) utillinux
++ lib.optional (stdenv.isDarwin) libtool ++ lib.optional (stdenv.isDarwin) libtool
@ -414,6 +426,8 @@ let
passAsFile = [ "compositionScript" "pinpointDependenciesScript" ]; passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
installPhase = '' installPhase = ''
source ${installPackage}
# Create and enter a root node_modules/ folder # Create and enter a root node_modules/ folder
mkdir -p $out/lib/node_modules mkdir -p $out/lib/node_modules
cd $out/lib/node_modules cd $out/lib/node_modules
@ -427,6 +441,14 @@ let
if [ -d "$out/lib/node_modules/.bin" ] if [ -d "$out/lib/node_modules/.bin" ]
then then
ln -s $out/lib/node_modules/.bin $out/bin ln -s $out/lib/node_modules/.bin $out/bin
# Patch the shebang lines of all the executables
ls $out/bin/* | while read i
do
file="$(readlink -f "$i")"
chmod u+rwx "$file"
patchShebangs "$file"
done
fi fi
# Create symlinks to the deployed manual page folders, if applicable # Create symlinks to the deployed manual page folders, if applicable
@ -446,13 +468,18 @@ let
# Run post install hook, if provided # Run post install hook, if provided
runHook postInstall runHook postInstall
''; '';
meta = {
# default to Node.js' platforms
platforms = nodejs.meta.platforms;
} // meta;
} // extraArgs); } // extraArgs);
# Builds a node environment (a node_modules folder and a set of binaries) # Builds a node environment (a node_modules folder and a set of binaries)
buildNodeDependencies = buildNodeDependencies =
{ name { name
, packageName , packageName
, version , version ? null
, src , src
, dependencies ? [] , dependencies ? []
, buildInputs ? [] , buildInputs ? []
@ -470,7 +497,7 @@ let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ]; extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ];
in in
stdenv.mkDerivation ({ stdenv.mkDerivation ({
name = "node-dependencies-${name}-${version}"; name = "node-dependencies-${name}${if version == null then "" else "-${version}"}";
buildInputs = [ tarWrapper python nodejs ] buildInputs = [ tarWrapper python nodejs ]
++ lib.optional (stdenv.isLinux) utillinux ++ lib.optional (stdenv.isLinux) utillinux
@ -486,6 +513,8 @@ let
passAsFile = [ "includeScript" "pinpointDependenciesScript" ]; passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
installPhase = '' installPhase = ''
source ${installPackage}
mkdir -p $out/${packageName} mkdir -p $out/${packageName}
cd $out/${packageName} cd $out/${packageName}
@ -498,6 +527,7 @@ let
if [ -f ${src}/package-lock.json ] if [ -f ${src}/package-lock.json ]
then then
cp ${src}/package-lock.json . cp ${src}/package-lock.json .
chmod 644 package-lock.json
fi fi
''} ''}
@ -520,7 +550,7 @@ let
buildNodeShell = buildNodeShell =
{ name { name
, packageName , packageName
, version , version ? null
, src , src
, dependencies ? [] , dependencies ? []
, buildInputs ? [] , buildInputs ? []
@ -536,9 +566,10 @@ let
let let
nodeDependencies = buildNodeDependencies args; nodeDependencies = buildNodeDependencies args;
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "unpackPhase" "buildPhase" ];
in in
stdenv.mkDerivation { stdenv.mkDerivation ({
name = "node-shell-${name}-${version}"; name = "node-shell-${name}${if version == null then "" else "-${version}"}";
buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs; buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs;
buildCommand = '' buildCommand = ''
@ -557,7 +588,7 @@ let
export NODE_PATH=${nodeDependencies}/lib/node_modules export NODE_PATH=${nodeDependencies}/lib/node_modules
export PATH="${nodeDependencies}/bin:$PATH" export PATH="${nodeDependencies}/bin:$PATH"
''; '';
}; } // extraArgs);
in in
{ {
buildNodeSourceDist = lib.makeOverridable buildNodeSourceDist; buildNodeSourceDist = lib.makeOverridable buildNodeSourceDist;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
{ {
"name": "fx_cast_bridge", "name": "fx_cast_bridge",
"version": "0.1.2", "version": "0.2.0",
"__applicationName": "fx_cast_bridge", "__applicationName": "fx_cast_bridge",
"__applicationVersion": "0.1.0", "__applicationVersion": "0.2.0",
"__applicationDirectoryName": "fx_cast", "__applicationDirectoryName": "fx_cast",
"__applicationExecutableName": "fx_cast_bridge", "__applicationExecutableName": "fx_cast_bridge",
"scripts": { "scripts": {
@ -12,28 +12,29 @@
"remove-manifest": "node bin/install-manifest.js --remove" "remove-manifest": "node bin/install-manifest.js --remove"
}, },
"dependencies": { "dependencies": {
"@types/minimist": "^1.2.1", "bplist-creator": "^0.1.0",
"@types/ws": "^7.4.0", "bplist-parser": "^0.3.1",
"bplist-creator": "0.0.8",
"bplist-parser": "^0.2.0",
"castv2": "^0.1.10", "castv2": "^0.1.10",
"fast-srp-hap": "^2.0.2", "fast-srp-hap": "^2.0.4",
"mdns": "^2.5.1", "mdns": "^2.7.2",
"mime-types": "^2.1.27", "mime-types": "^2.1.35",
"minimist": "^1.2.5", "minimist": "^1.2.6",
"node-fetch": "^2.6.0", "node-fetch": "^3.2.3",
"tweetnacl": "^1.0.3", "tweetnacl": "^1.0.3",
"ws": "^7.4.3" "ws": "^8.5.0"
}, },
"devDependencies": { "devDependencies": {
"@types/mdns": "0.0.33", "@types/mdns": "^0.0.34",
"@types/mime-types": "^2.1.0", "@types/mime-types": "^2.1.1",
"@types/node": "^13.13.15", "@types/minimist": "^1.2.2",
"@types/node-fetch": "^2.5.7", "@types/node": "^17.0.26",
"fs-extra": "^9.1.0", "@types/node-fetch": "^2.6.1",
"mustache": "^4.0.1", "@types/ws": "^8.5.3",
"pkg": "^4.4.9", "fs-extra": "^10.1.0",
"typescript": "^4.1.5" "mustache": "^4.2.0",
"pkg": "^5.6.0",
"tiny-typed-emitter": "^2.1.0",
"typescript": "^4.6.3"
}, },
"optionalDependencies": { "optionalDependencies": {
"rage-edit": "^1.2.0" "rage-edit": "^1.2.0"