-
-
Save TimePath/fe1c4f624e144566232f0a496f9e6b73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, lib, stdenv }: | |
let | |
result = mkElectronApp rec { | |
name = "riot-${version}"; | |
version = "0.11.4"; | |
src = pkgs.fetchgit { | |
url = "https://github.com/vector-im/riot-web.git"; | |
rev = "cf5cf02529f95a094d88051c12fdb87a03d87335"; | |
sha256 = "00dk9pdphb227hlzkn8r034ffzl0ri7q1b9694jqm01zdlzmaglk"; | |
}; | |
devDeps = [ | |
(mkNodeModules { package.json = "${src}/package.json"; development = true; }) | |
# need reskindex from production matrix-react-sdk | |
(mkNodeModules { package.json = "${src}/package.json"; production = true; }) | |
# need olm at build time for it to be packaged | |
(mkNodeModules { package.json = "${src}/package.json"; optional = true; }) | |
]; | |
runDeps = [ | |
(mkNodeModules { package.json = "${src}/package.json"; production = true; }) | |
(mkNodeModules { package.json = "${src}/package.json"; optional = true; }) | |
(mkNodeModules { package.json = "${src}/electron_app/package.json"; production = true; }) | |
]; | |
sysDeps = with pkgs; [ | |
coreutils | |
]; | |
}; | |
mkElectronApp = {name, version, src, devDeps ? [], runDeps ? [], sysDeps ? []}: stdenv.mkDerivation { | |
inherit name version src; | |
nativeBuildInputs = with pkgs; [ nodejs makeWrapper rsync ]; | |
installPhase = '' | |
mkdir -p node_modules/.bin | |
${lib.concatMapStringsSep "\n" (it: '' | |
rsync -au ${it}/lib/node_modules/ node_modules/ | |
'') devDeps} | |
npm run build | |
mv node_modules node_modules_dev | |
mkdir -p node_modules/.bin | |
${lib.concatMapStringsSep "\n" (it: '' | |
ln -sf ${it}/lib/node_modules/* node_modules/ | |
ln -sf ${it}/lib/node_modules/.bin/* node_modules/.bin/ | |
'') runDeps} | |
mkdir out && mv * out && mv out/node_modules_dev . | |
mkdir -p $out/bin && cp -r out/. $out | |
makeWrapper ${pkgs.electron}/bin/electron $out/bin/riot \ | |
--set SHELL ${pkgs.bash}/bin/sh \ | |
--prefix PATH : '${lib.makeBinPath sysDeps}' \ | |
--run 'export NODE_ENV="''${NODE_ENV:-production}"' \ | |
--add-flags "$out" | |
''; | |
}; | |
mkNodeModules = { package, production ? false, development ? false, optional ? false }: let | |
prune = builtins.toFile "prune.js" '' | |
var fs = require("fs"); | |
var path = require("path"); | |
var package = JSON.parse(fs.readFileSync(process.argv[2])); | |
${lib.optionalString (production == false) "delete package.dependencies;"} | |
${lib.optionalString (development == false) "delete package.devDependencies;"} | |
${lib.optionalString (optional == true) "Object.assign(package.dependencies = (package.dependencies || {}), package.optionalDependencies || {});"} | |
console.log(JSON.stringify(package, undefined, 2)); | |
''; | |
o = lib.optionalString; | |
generateNpmNix = pkgs.runCommand "node-dependencies${o production "+prod"}${o development "+dev"}${o optional "+opt"}.nix" { | |
nativeBuildInputs = with pkgs; [ nodejs nodePackages.node2nix git nix ]; | |
} '' | |
mkdir -p $out | |
node ${prune} ${package.json} > package.json | |
node2nix \ | |
--input package.json \ | |
--flatten \ | |
--development \ | |
--composition node-composition.nix \ | |
; | |
sed -i -e 's/\(args = {\)/\1 dontNpmInstall = true;/' node-packages.nix | |
mv *.nix $out | |
''; | |
composition = pkgs.callPackage "${generateNpmNix}/node-composition.nix" {}; | |
result = composition.shell.nodeDependencies; | |
in result; | |
in result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment