I’m trying to build a dev env for ReScript
lang and I got this shell.nix
that’s calls nix/default.nix
and so on:
shell.nix:
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
rescript-src = ./nix/default.nix;
rescript = (import rescript-src { inherit pkgs; }).rescript9;
in mkShell {
name = "kirby_dev";
buildInputs = [ rescript nodejs ];
shellHook = ''
mkdir -p ./node_modules/.bin
ln -sfn ${rescript} ./node_modules/rescript
ln -sfn ${rescript}/bin/* ./node_modules/.bin
echo "rescript linked to $(pwd)/node_modules/bs-platform"
npm install
'';
}
default.nix:
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
{
rescript9 = import ./build-rescript.nix {
inherit stdenv lib fetchFromGitHub ninja runCommand nodejs python3;
version = "9.1.4";
ocaml-version = "4.12.0";
src = fetchFromGitHub {
owner = "rescript-lang";
repo = "rescript-compiler";
rev = "9.1.4";
sha256 = "0s7g2zfhshsilv9zyp0246bypg34d294z27alpwz03ws9608yr7k";
fetchSubmodules = true;
};
};
}
build-rescript.nix:
{ stdenv, lib, fetchFromGitHub, ninja, runCommand, nodejs, python3,
ocaml-version, version, src,
ocaml ? (import ./ocaml.nix {
version = ocaml-version;
inherit stdenv lib;
src = "${src}/ocaml";
}),
custom-ninja ? (ninja.overrideAttrs (attrs: {
src = runCommand "ninja-patched-source" {} ''
mkdir -p $out
tar zxvf ${src}/vendor/ninja.tar.gz -C $out
'';
patches = [];
}))
}:
stdenv.mkDerivation {
inherit src version;
pname = "rescript";
buildInputs = [ nodejs python3 custom-ninja ];
patchPhase = ''
sed -i 's:./configure.py --bootstrap:python3 ./configure.py --bootstrap:' ./scripts/install.js
mkdir -p ./native/${ocaml-version}/bin
ln -sf ${ocaml}/bin/* ./native/${ocaml-version}/bin
rm -f vendor/ninja/snapshot/ninja.linux
cp ${custom-ninja}/bin/ninja vendor/ninja/snapshot/ninja.linux
'';
dontConfigure = true;
buildPhase = ''
# release build https://github.com/BuckleScript/bucklescript/issues/4091#issuecomment-574514891
node scripts/install.js
'';
installPhase = ''
mkdir -p $out/bin
cp -rf jscomp lib vendor odoc_gen native $out
cp bsconfig.json package.json $out
ln -s $out/lib/bsb $out/bin/bsb
ln -s $out/lib/bsc $out/bin/bsc
ln -s $out/lib/bsrefmt $out/bin/bsrefmt
'';
}
ocaml.nix:
{ stdenv, lib, src, version }:
stdenv.mkDerivation rec {
inherit src version;
name = "ocaml-${version}+bs";
configurePhase = ''
./configure -prefix $out
'';
buildPhase = ''
make -j9 world.opt
'';
meta = with lib; {
branch = "4.12.0";
platforms = platforms.all;
};
}
However, when I try to enter the shell I get this permission error:
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /home/matthew/documents/prefeitura/kirby/node_modules/bs-platform
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/home/matthew/documents/prefeitura/kirby/node_modules/bs-platform'
npm ERR! [Error: EACCES: permission denied, access '/home/matthew/documents/prefeitura/kirby/node_modules/bs-platform'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/home/matthew/documents/prefeitura/kirby/node_modules/bs-platform'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/matthew/.npm/_logs/2021-07-14T04_32_19_826Z-debug.log
why npm is trying to access bs-platform
folder if I’m creating the rescript
folder?
what I could do to improve this dev env?