status-mobile/nix/desktop/realm-node/generate-nix.sh

59 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
if [[ -z "${IN_NIX_SHELL}" ]]; then
echo "Remember to call 'make shell'!"
exit 1
fi
#
# Run this file to regenerate the Nix files in ./output.
# Prerequisites: Node, npm, and node2nix (installed with npm i -g https://github.com/svanderburg/node2nix)
#
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
toolversion="${GIT_ROOT}/scripts/toolversion"
dir="$SCRIPTPATH"
input="${dir}/output/node-packages.json"
output_dir="${dir}/output"
supplement_input="${dir}/output/supplement.json"
rm -rf $output_dir && mkdir -p $output_dir
# Specify the package.json file containing the dependencies to install
cat << EOF > $input
[
{ "realm": "https://github.com/status-im/realm-js/archive/v2.20.1.tar.gz" }
]
EOF
# Specify the package.json file containing the build dependencies to install
cat << EOF > $supplement_input
[
"node-pre-gyp"
]
EOF
# Specify the package.json file containing the build dependencies to install
cat << EOF > $supplement_input
[
"node-pre-gyp"
]
EOF
node_required_version=$($toolversion node)
node_major_version=$(echo $node_required_version | cut -d. -f1,1)
if ! which node2nix > /dev/null; then
echo "Installing node2nix..."
nix-env -f '<nixpkgs>' -iA nodePackages.node2nix
fi
node2nix --nodejs-${node_major_version} --bypass-cache \
--input $input \
--output $output_dir/node-packages.nix \
--supplement-input $supplement_input \
--supplement-output $output_dir/supplement.nix \
--composition $output_dir/default.nix \
--node-env $output_dir/node-env.nix
rm $input $supplement_input