Skip to content

Instantly share code, notes, and snippets.

@eqyiel
Created September 14, 2017 01:28
Show Gist options
  • Save eqyiel/e1d2cb3cee89a581dcd06fdab40e2ecc to your computer and use it in GitHub Desktop.
Save eqyiel/e1d2cb3cee89a581dcd06fdab40e2ecc to your computer and use it in GitHub Desktop.
Nix expression for generating a build of keystone that won't try writing to node_modules in /nix/store
#!/bin/sh -eu
# You need nix installed to run this:
# https://nixos.org/nix/download.html
export NIX_PATH="nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/d0d905668c010b65795b57afdf7f0360aac6245b.tar.gz"
rm -f default.nix node-env.nix node-packages.nix package.json
cat <<EOF > package.json
[
{ "keystone": "4.0.0-beta.5" }
]
EOF
cat <<EOF > supplement.json
[
{ "uglify-js": "2.8.29" }
]
EOF
cat <<EOF > default.nix
{ stdenv
, pkgs ? import <nixpkgs> {}
, system ? builtins.currentSystem
, nodejs ? pkgs.nodejs-6_x
}:
let
nodePackages = import ./composition.nix {
inherit pkgs system nodejs;
};
inherit (nodejs) python;
in nodePackages // {
"keystone-4.0.0-beta.5" = nodePackages."keystone-4.0.0-beta.5".override {
# you must do this step so that node_modules is written to before being
# sealed in /nix/store
postInstall = ''
KEYSTONE_PREBUILD_ADMIN=true npm run build
'';
};
}
EOF
"$(nix-build '<nixpkgs>' -A nodePackages.node2nix --no-out-link)/bin/node2nix" \
-6 \
-i package.json \
-c composition.nix \
-e node-env.nix \
--supplement-input supplement.json
nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}'
# Afterwards you should have the bundles here:
#
# % ls -lha result/lib/node_modules/keystone/admin/bundles/js
# total 1.4M
# dr-xr-xr-x 5 rkm staff 170 Jan 1 1970 .
# dr-xr-xr-x 3 rkm staff 102 Jan 1 1970 ..
# dr-xr-xr-x 3 rkm staff 102 Jan 1 1970 11bbac-App
# -r--r--r-- 1 rkm staff 1.4M Jan 1 1970 11bbac-FieldTypes.js
# dr-xr-xr-x 3 rkm staff 102 Jan 1 1970 11bbac-Signin
#
# Note that you also have to set KEYSTONE_PREBUILD_ADMIN=true when you're
# running your app that has keystone as a dependency.
#
# Now keystone won't attempt to write to node_modules in /nix/store.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment