haccfiles/pkgs/companion/default.nix

148 lines
4.7 KiB
Nix
Raw Permalink Normal View History

{ stdenv
, mkYarnPackage
, mkYarnModules
, fetchFromGitHub
, libsass
, python
, python3
, pkg-config
, libusb
, fetchurl
, nodejs
, electron
, writeText
, makeWrapper
, udev
, nodePackages
, libvips
}:
# some weird javascript thingy that runs our tally lights on conferences.
#
# in case it breaks or you want to update it:
# 1. update companion sources below (also update the hash)
# 2. re-generate the yarn.nix / yarn-webui.nix files (see comments below)
# 3. try re-generating yarn.lock itself (`yarn install --mode update-lockfile`)
#
# if things break, try taking a look at yarn2nix's documentation. In
# nix-typical fashion, it was deleted when yarn2nix got integrated into
# nixpkgs; a shorter version is now in the nixpkgs manual:
# - https://nixos.org/manual/nixpkgs/stable/#javascript-tool-specific
# sometimes the archived original documentation can still be helpful:
# - https://github.com/nix-community/yarn2nix
let
version = "2.1.3";
source = fetchFromGitHub {
owner = "bitfocus";
repo = "companion";
rev = "b653211f5507a090a120fa3e819ab3044405e461";
sha256 = "0gvibbhfqa9gk8cf3m07gd5dbik3kbpr03hx2pppqnh9pfrx35qh";
};
nodeHeaders = fetchurl {
url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz";
2021-10-31 20:25:48 +00:00
sha256 = "19b0dg8292cjx758wlrvpb3jf520bpyvjal2n7r4fyvk38x9flik";
};
# the companion's web ui. In a seperate derivation, but is symlinked into
# the companion itself.
webui = mkYarnPackage rec {
inherit version;
pname = "bitfocus-companion-webui";
src = "${source}/webui";
# nixified dependencies generated using `yarn2nix`. Must be re-generated
# when updating the companion using yarn2nix on the yarn.lock file of the
# webui.
yarnNix = ./yarn-webui.nix;
configurePhase = "
cp -r $node_modules node_modules
chmod -R u+w node_modules
";
buildPhase = "PUBLIC_URL=. yarn build";
installPhase = "mv build $out";
distPhase = "true";
pkgConfig = {
node-sass = {
buildInputs = [ libsass python ];
postInstall = "node scripts/build.js --tarball=${nodeHeaders}";
};
};
};
yarnModulesNoWorkspace = args: (mkYarnModules args).overrideAttrs(old: {
# this replaces exactly one occurance of that string in
# <nixpkgs>/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix
buildPhase = builtins.replaceStrings
[" ./package.json"]
[" /dev/null; cp deps/*/package.json ."]
old.buildPhase;
});
in stdenv.mkDerivation rec {
inherit version;
pname = "bitfocus-companion";
src = source;
# yarn modules needed for the build; these would usually be fetched by yarn
# when running `yarn build`.
modules = yarnModulesNoWorkspace rec {
inherit version;
pname = "companion-modules";
name = "${pname}-${version}";
# A nixified version of yarn's yarn.lock file. If anything in here breaks,
# try regenerating it using `yarn2nix` (found in nixpkgs.yarn2nix) on the
# yarn.lock file found in the companion's source tree (also try a newer
# version while you're at it).
yarnNix = ./yarn.nix;
# no idea what these two do tbh
packageJSON = "${source}/package.json";
yarnLock = "${source}/yarn.lock";
# ???
pkgConfig = {
node-hid = {
buildInputs = [ udev libusb python3 pkg-config ];
postInstall = "${nodePackages.node-gyp}/bin/node-gyp rebuild --tarball=${nodeHeaders}";
};
sharp = {
buildInputs = [ libvips pkg-config ];
postInstall = ''
sed -i "s|<!(node -p \"require(\\\\'./lib/libvips\\\\').minimumLibvipsVersion\")|${libvips.version}|" binding.gyp
sed -i "s|<!(node -p \"require(\\\\'./lib/libvips\\\\').pkgConfigPath()\")||" binding.gyp
sed -i "s|<!(node -p \"Boolean(require(\\\\'./lib/libvips\\\\').useGlobalLibvips()).toString()\")|true|" binding.gyp
sed -i "s|PKG_CONFIG_PATH=\"<(pkg_config_path)\" ||" binding.gyp
${nodePackages.node-gyp}/bin/node-gyp rebuild --tarball=${nodeHeaders}
'';
};
};
};
nativeBuildInputs = [ makeWrapper ];
configurePhase = "";
buildPhase = "";
installPhase = ''
mkdir -p $out/share
cp --no-preserve=mode -r $src "$out/share/companion"
echo "nixos-f00baa-0" > $out/share/companion/BUILD
ln -s '${webui}' "$out/share/companion/static"
cp -r '${modules}/node_modules' "$out/share/companion/node_modules"
sed -i "s|process.resourcesPath|\"$out/share/companion\"|" $out/share/companion/lib/server_http.js
sed -i "s|require('app-root-path')|\"$out/share/companion\"|" $out/share/companion/{app,lib/{schedule,help,instance}}.js
makeWrapper '${electron}/bin/electron' "$out/bin/companion" \
--add-flags "$out/share/companion"
'';
}