Skip to content

Instantly share code, notes, and snippets.

@aljce
Created August 8, 2019 20:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aljce/971e07bdcce4cd73923b25948d8703d7 to your computer and use it in GitHub Desktop.
Save aljce/971e07bdcce4cd73923b25948d8703d7 to your computer and use it in GitHub Desktop.
# Using a specific checkout of nixpkgs makes it easy to debug as you know exactly what the deps are.
# This being said in production you should pass the global nixpkgs to this file.
let nixpkgs-src = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/56d94c8c69f8cac518027d191e2f8de678b56088.tar.gz";
sha256 = "1c812ssgmnmh97sarmp8jcykk0g57m8rsbfjg9ql9996ig6crsmi";
};
in
{ pkgs ? (import nixpkgs-src {}) }:
with pkgs;
with stdenv.lib;
let chrome-revision = "681777";
chrome-src-location =
"https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/${chrome-revision}/chrome-linux.zip";
chrome-src = fetchzip {
url = chrome-src-location;
sha256 = "04ws0283v1anrji72w04gsb13g0hbv2ypviaszsb3lzncz07x774";
};
chrome-deps = with xorg; [
# Not all these deps are needed but they don't hurt anything
glib fontconfig freetype pango cairo libX11 libXi atk nss nspr
libXcursor libXext libXfixes libXrender libXScrnSaver libXcomposite libxcb
alsaLib libXdamage libXtst libXrandr expat cups
dbus gcc-unwrapped.lib systemd libexif
liberation_ttf curl utillinux xdg_utils wget
flac harfbuzz icu libpng snappy speechd
bzip2 libcap at-spi2-atk at-spi2-core
kerberos gtk3 gdk_pixbuf
];
chrome = stdenv.mkDerivation rec {
version = chrome-revision;
name = "chrome-${chrome-revision}";
src = chrome-src;
nativeBuildInputs = [ patchelf ];
rpath = makeLibraryPath chrome-deps + ":" + makeSearchPathOutput "lib" "lib64" chrome-deps;
installPhase = ''
mkdir -p $out/bin
cp -r . $out/bin
patchelf --set-rpath $rpath $out/bin/chrome
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/bin/chrome
'';
};
yarn2nix-src = fetchFromGitHub {
owner = "moretea";
repo = "yarn2nix";
rev = "3f2dbb08724bf8841609f932bfe1d61a78277232";
sha256 = "142av7dwviapsnahgj8r6779gs2zr17achzhr8b97s0hsl08dcl2";
};
yarn2nix = import yarn2nix-src { inherit pkgs; };
# To update puppeteer versions change rev to the new commit and run
# nix-prefect-url --unpack https://github.com/JarvusInnovations/puppeteer-cli/archive/{commit}.tar.gz
# That command generates the correct sha256
puppeteer-cli-src = fetchFromGitHub {
owner = "JarvusInnovations";
repo = "puppeteer-cli";
rev = "ca720dc5363406247cae80ecf978fbea2748e2df";
sha256 = "11h12bb77ngkjzrc4pmvzqfcwhsgx1y7i7wyl966cqf8kfflsmzb";
};
in
yarn2nix.mkYarnPackage {
name = "puppeteer-cli";
src = puppeteer-cli-src;
packageJSON = puppeteer-cli-src + "/package.json";
# If you update puppeteer-cli regenerate this yarn.lock file
yarnLock = ./yarn.lock;
# nix builds can not have access to the internet
# puppeteer needs access to the internet to download a specific binary of chrome
# we download the binary, patchelf it, and put it in the directory puppeteer thinks it should be in
postInstall = ''
chrome_loc=$out/libexec/puppeteer-cli/node_modules/puppeteer/.local-chromium/linux-674921
# I have no idea how that number ^ is generated
mkdir -p $chrome_loc
ln -s ${chrome}/bin $chrome_loc/chrome-linux
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment