From f6543b1ef8117a1ac3fd623698ecb34d737d945b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 7 Dec 2025 21:35:05 +0100 Subject: [PATCH 01/11] feat: make use of Nix files to set up dev env --- Dockerfile | 23 ++++++++++++++++++----- README.md | 2 +- scripts/build.sh | 7 ++++--- scripts/ccache.sh | 6 ------ scripts/clone.sh | 13 +++++++------ scripts/install-node.sh | 12 ++++++++---- scripts/install.sh | 35 ----------------------------------- scripts/ncu.sh | 7 +++---- scripts/setup-origin.sh | 10 ---------- 9 files changed, 41 insertions(+), 74 deletions(-) delete mode 100755 scripts/ccache.sh delete mode 100755 scripts/install.sh delete mode 100755 scripts/setup-origin.sh diff --git a/Dockerfile b/Dockerfile index dfb9717..d548045 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,25 +9,38 @@ RUN useradd --uid $USER_UID --gid $USER_GID --shell /bin/bash --create-home deve # Install sudo first RUN apt-get update -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sudo +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates curl git git-restore-mtime sudo xz-utils # No Sudo Prompt - thanks Electron for this RUN echo 'developer ALL=NOPASSWD: ALL' >> /etc/sudoers.d/developer RUN echo 'Defaults env_keep += "DEBIAN_FRONTEND"' >> /etc/sudoers.d/env_keep ENV DEBIAN_FRONTEND=1 -ENV PATH=/usr/lib/ccache:$PATH # Copy scripts and make them executable by both root and developer COPY --chown=root:developer --chmod=0755 ./scripts/ /home/developer/scripts/ -RUN /home/developer/scripts/install.sh -RUN /home/developer/scripts/ccache.sh USER developer RUN /home/developer/scripts/clone.sh + +# Installing Nix and Cachix +RUN curl -L https://github.com/cachix/install-nix-action/raw/HEAD/install-nix.sh | \ + USER=developer \ + INPUT_SET_AS_TRUSTED_USER=true \ + INPUT_ENABLE_KVM=true \ + INPUT_EXTRA_NIX_CONFIG= \ + INPUT_INSTALL_OPTIONS= \ + RUNNER_TEMP=$(mktemp -d) GITHUB_ENV=/dev/null GITHUB_PATH=/dev/null bash +ENV NIX_PROFILES="/nix/var/nix/profiles/default /home/developer/.nix-profile" +ENV NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt +ENV PATH="/home/developer/.nix-profile/bin:${PATH}" +RUN nix-env -iA cachix -f https://cachix.org/api/v1/install +RUN USER=developer cachix use nodejs + RUN /home/developer/scripts/build.sh -ENV PATH=/home/developer/.local/bin:$PATH WORKDIR /home/developer/nodejs/node RUN /home/developer/scripts/install-node.sh RUN /home/developer/scripts/ncu.sh + +ENTRYPOINT ["/home/developer/.nix-profile/bin/nix-shell", "--pure", "-I", "nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix"] diff --git a/README.md b/README.md index c6f7316..993247c 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Do this from your local system, not in the container. The `git` configuration wi Some useful commands: - `docker build .` - build the current Dockerfile - `docker image ls` - list the images and IDs -- `docker run -it /bin/bash` - run a container and shell into it +- `docker run -it ` - run a container and shell into it - `docker tag devcontainer:nightly` - run to tag an image as `nightly` diff --git a/scripts/build.sh b/scripts/build.sh index 11e0a15..3e0e918 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,5 +1,6 @@ -#!/usr/bin/env bash +#!/usr/bin/env nix-shell +#! nix-shell --pure -i bash -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix /home/developer/nodejs/node/shell.nix -set -e # Exit with nonzero exit code if anything fails +set -xe -/home/developer/nodejs/node/configure --ninja && make -C /home/developer/nodejs/node +make -C /home/developer/nodejs/node build-ci diff --git a/scripts/ccache.sh b/scripts/ccache.sh deleted file mode 100755 index c009c28..0000000 --- a/scripts/ccache.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -e # Exit with nonzero exit code if anything fails - -# create symlinks -/usr/sbin/update-ccache-symlinks diff --git a/scripts/clone.sh b/scripts/clone.sh index ea16c68..53d59dc 100755 --- a/scripts/clone.sh +++ b/scripts/clone.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash -set -e # Exit with nonzero exit code if anything fails +set -xe mkdir -p /home/developer/nodejs -cd /home/developer/nodejs -git clone https://github.com/nodejs/node.git --single-branch --branch main --depth 1 -cd /home/developer/nodejs/node -git remote add upstream https://github.com/nodejs/node.git -git restore-mtime # Restore file modification times to commit times for build cache to match. +git clone https://github.com/nodejs/node.git --depth 1 /home/developer/nodejs/node +( + cd /home/developer/nodejs/node + git remote add upstream https://github.com/nodejs/node.git + git restore-mtime # Restore file modification times to commit times for build cache to match. +) diff --git a/scripts/install-node.sh b/scripts/install-node.sh index 47f2d64..af0d7eb 100755 --- a/scripts/install-node.sh +++ b/scripts/install-node.sh @@ -1,7 +1,11 @@ -#!/usr/bin/env bash +#!/usr/bin/env nix-shell +#! nix-shell --pure -i bash -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix /home/developer/nodejs/node/shell.nix -set -e # Exit with nonzero exit code if anything fails +set -xe make install PREFIX=/home/developer/.local -C /home/developer/nodejs/node -echo '' >> /home/developer/.bashrc -echo 'export PATH=/home/developer/.local/bin:$PATH' >> /home/developer/.bashrc +{ + echo '' + # Expose the PATH generated by Nix + the recently built `node` installation + echo "export PATH=/home/developer/.local/bin:$PATH" + } >> /home/developer/.bashrc diff --git a/scripts/install.sh b/scripts/install.sh deleted file mode 100755 index 4f30dde..0000000 --- a/scripts/install.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -set -e # Exit with nonzero exit code if anything fails - -package_list=" - build-essential \ - ccache \ - curl \ - nano \ - python3 \ - python3-pip \ - python-is-python3 \ - ninja-build \ - g++ \ - gcc \ - g++-12 \ - gcc-12 \ - make \ - git \ - pkg-config \ - locales \ - gpg \ - wget \ - git-restore-mtime" - -# Install Packages -apt-get update -DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $package_list - -# set up GitHub CLI resistry stuff to get gh CLI -curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg -echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null -gh_package_list="gh" -apt-get update -DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $gh_package_list diff --git a/scripts/ncu.sh b/scripts/ncu.sh index 0612251..af65545 100755 --- a/scripts/ncu.sh +++ b/scripts/ncu.sh @@ -1,8 +1,7 @@ -#!/usr/bin/env bash +#!/usr/bin/env nix-shell +#! nix-shell --pure -i bash -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix /home/developer/nodejs/node/shell.nix -set -e # Exit with nonzero exit code if anything fails - -npm install -g @node-core/utils +set -xe ncu-config set upstream upstream ncu-config set branch main diff --git a/scripts/setup-origin.sh b/scripts/setup-origin.sh deleted file mode 100755 index c990016..0000000 --- a/scripts/setup-origin.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -e # Exit with nonzero exit code if anything fails - -if [[ -z "${ORIGIN_URL}" ]] -then - echo "ORIGIN_URL is not set" -else - git remote set-url origin ${ORIGIN_URL} -fi From 3a89bf62b1987ba8c79ca0b2696ce4fcc8999aaa Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 8 Dec 2025 10:48:39 +0100 Subject: [PATCH 02/11] Update Dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d548045..2378b55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,4 +43,5 @@ WORKDIR /home/developer/nodejs/node RUN /home/developer/scripts/install-node.sh RUN /home/developer/scripts/ncu.sh -ENTRYPOINT ["/home/developer/.nix-profile/bin/nix-shell", "--pure", "-I", "nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix"] +# We pass `--impure` so the locally installed `node` build is available on the PATH. +ENTRYPOINT ["/home/developer/.nix-profile/bin/nix-shell", "--impure", "-I", "nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix"] From 7534642b22582a0e5a8a530b2c8f8b4978e45515 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 8 Dec 2025 12:24:57 +0100 Subject: [PATCH 03/11] Use the same Nix version as the one tested by GHA --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2378b55..6697e5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ USER developer RUN /home/developer/scripts/clone.sh # Installing Nix and Cachix -RUN curl -L https://github.com/cachix/install-nix-action/raw/HEAD/install-nix.sh | \ +RUN curl -L "https://github.com/$(sed -nE 's#.*(cachix/install-nix-action)@([a-f0-9]+).*#\1/raw/\2#p' /home/developer/nodejs/node/.github/workflows/test-shared.yml)/install-nix.sh" | \ USER=developer \ INPUT_SET_AS_TRUSTED_USER=true \ INPUT_ENABLE_KVM=true \ From 885db6bf06c84915a35824ad26168ac2f701eb15 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 8 Dec 2025 12:27:53 +0100 Subject: [PATCH 04/11] fix PATH --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6697e5d..0a333d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN curl -L "https://github.com/$(sed -nE 's#.*(cachix/install-nix-action)@([a-f RUNNER_TEMP=$(mktemp -d) GITHUB_ENV=/dev/null GITHUB_PATH=/dev/null bash ENV NIX_PROFILES="/nix/var/nix/profiles/default /home/developer/.nix-profile" ENV NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt -ENV PATH="/home/developer/.nix-profile/bin:${PATH}" +ENV PATH="/home/developer/.local/bin:/home/developer/.nix-profile/bin:${PATH}" RUN nix-env -iA cachix -f https://cachix.org/api/v1/install RUN USER=developer cachix use nodejs From cfde596206015ea8799f14e3b02c958f7945d8ea Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 9 Dec 2025 19:53:43 +0000 Subject: [PATCH 05/11] add `direnv` and `USE_SHARED_LIBS` arg --- Dockerfile | 13 +++++++++++-- scripts/build.sh | 6 ++++-- scripts/install-node.sh | 6 ++++-- scripts/ncu.sh | 6 ++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0a333d8..8bb06e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:latest AS build ARG USER_UID=900 ARG USER_GID=$USER_UID +ARG USE_SHARED_LIBS=false # Create the non-root user and grant NOPASSWD sudo RUN groupadd --gid $USER_GID developer @@ -37,11 +38,19 @@ ENV PATH="/home/developer/.local/bin:/home/developer/.nix-profile/bin:${PATH}" RUN nix-env -iA cachix -f https://cachix.org/api/v1/install RUN USER=developer cachix use nodejs +# Installing direnv +RUN nix profile add nixpkgs#nix-direnv nixpkgs#direnv -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix +RUN mkdir -p /home/developer/.config/direnv && \ + echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > /home/developer/.config/direnv/direnvrc +RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}'")" > /home/developer/nodejs/node/.envrc +RUN direnv allow /home/developer/nodejs/node +RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc + RUN /home/developer/scripts/build.sh WORKDIR /home/developer/nodejs/node RUN /home/developer/scripts/install-node.sh RUN /home/developer/scripts/ncu.sh -# We pass `--impure` so the locally installed `node` build is available on the PATH. -ENTRYPOINT ["/home/developer/.nix-profile/bin/nix-shell", "--impure", "-I", "nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix"] +# direnv will automatically load the nix environment when entering the directory +ENTRYPOINT ["/bin/bash", "-l"] diff --git a/scripts/build.sh b/scripts/build.sh index 3e0e918..09a94b8 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,6 +1,8 @@ -#!/usr/bin/env nix-shell -#! nix-shell --pure -i bash -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix /home/developer/nodejs/node/shell.nix +#!/usr/bin/env bash set -xe +cd /home/developer/nodejs/node +eval "$(direnv export bash)" + make -C /home/developer/nodejs/node build-ci diff --git a/scripts/install-node.sh b/scripts/install-node.sh index af0d7eb..8042f8f 100755 --- a/scripts/install-node.sh +++ b/scripts/install-node.sh @@ -1,8 +1,10 @@ -#!/usr/bin/env nix-shell -#! nix-shell --pure -i bash -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix /home/developer/nodejs/node/shell.nix +#!/usr/bin/env bash set -xe +cd /home/developer/nodejs/node +eval "$(direnv export bash)" + make install PREFIX=/home/developer/.local -C /home/developer/nodejs/node { echo '' diff --git a/scripts/ncu.sh b/scripts/ncu.sh index af65545..70c267f 100755 --- a/scripts/ncu.sh +++ b/scripts/ncu.sh @@ -1,7 +1,9 @@ -#!/usr/bin/env nix-shell -#! nix-shell --pure -i bash -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix /home/developer/nodejs/node/shell.nix +#!/usr/bin/env bash set -xe +cd /home/developer/nodejs/node +eval "$(direnv export bash)" + ncu-config set upstream upstream ncu-config set branch main From b7b5eed938ccd83b4101a2d428ce77595b2c6ef6 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 9 Dec 2025 19:56:56 +0000 Subject: [PATCH 06/11] fixup! move ARG down to avoid needlesly invalidate cache --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8bb06e5..8e7bb86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,6 @@ FROM ubuntu:latest AS build ARG USER_UID=900 ARG USER_GID=$USER_UID -ARG USE_SHARED_LIBS=false # Create the non-root user and grant NOPASSWD sudo RUN groupadd --gid $USER_GID developer @@ -42,9 +41,12 @@ RUN USER=developer cachix use nodejs RUN nix profile add nixpkgs#nix-direnv nixpkgs#direnv -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix RUN mkdir -p /home/developer/.config/direnv && \ echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > /home/developer/.config/direnv/direnvrc +RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc + +# Setting up direnv for the local clone +ARG USE_SHARED_LIBS=false RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}'")" > /home/developer/nodejs/node/.envrc RUN direnv allow /home/developer/nodejs/node -RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc RUN /home/developer/scripts/build.sh From a8c190f3fb557ccd239a149cc3be145f5645ea2e Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 9 Dec 2025 20:01:55 +0000 Subject: [PATCH 07/11] squash! also use vendored ICU --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8e7bb86..9a48994 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,7 +45,7 @@ RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc # Setting up direnv for the local clone ARG USE_SHARED_LIBS=false -RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}'")" > /home/developer/nodejs/node/.envrc +RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}' --argstr icu full")" > /home/developer/nodejs/node/.envrc RUN direnv allow /home/developer/nodejs/node RUN /home/developer/scripts/build.sh From 6b487ff856de53aafaa3715329f7b7e6599a0b90 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 20 Dec 2025 00:26:04 +0100 Subject: [PATCH 08/11] Add comments Co-authored-by: Joyee Cheung --- Dockerfile | 3 +++ scripts/build.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 9a48994..a8d8ac0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,8 @@ USER developer RUN /home/developer/scripts/clone.sh # Installing Nix and Cachix +# using the same script test-shared workflow uses upstream +# See https://github.com/cachix/install-nix-action/blob/HEAD/install-nix.sh RUN curl -L "https://github.com/$(sed -nE 's#.*(cachix/install-nix-action)@([a-f0-9]+).*#\1/raw/\2#p' /home/developer/nodejs/node/.github/workflows/test-shared.yml)/install-nix.sh" | \ USER=developer \ INPUT_SET_AS_TRUSTED_USER=true \ @@ -45,6 +47,7 @@ RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc # Setting up direnv for the local clone ARG USE_SHARED_LIBS=false +# Modifications to the env (such as adding flags, or env variables) should be done upstream unless it's only applicable to this repo. RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}' --argstr icu full")" > /home/developer/nodejs/node/.envrc RUN direnv allow /home/developer/nodejs/node diff --git a/scripts/build.sh b/scripts/build.sh index 09a94b8..375eedc 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -5,4 +5,5 @@ set -xe cd /home/developer/nodejs/node eval "$(direnv export bash)" +# BUILD_WTIH=ninja is set in https://github.com/nodejs/node/blob/HEAD/shell.nix make -C /home/developer/nodejs/node build-ci From 5686fcf09a3642cd645d5072755d4ac942ab783f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 20 Dec 2025 17:42:39 +0100 Subject: [PATCH 09/11] fixup! Add comments --- Dockerfile | 7 ++++--- scripts/build.sh | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a8d8ac0..6fb5922 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,8 @@ COPY --chown=root:developer --chmod=0755 ./scripts/ /home/developer/scripts/ USER developer RUN /home/developer/scripts/clone.sh -# Installing Nix and Cachix -# using the same script test-shared workflow uses upstream +# Installing Nix using the same script test-shared workflow uses upstream. +# See https://github.com/nodejs/node/blob/HEAD/.github/workflows/test-shared.yml # See https://github.com/cachix/install-nix-action/blob/HEAD/install-nix.sh RUN curl -L "https://github.com/$(sed -nE 's#.*(cachix/install-nix-action)@([a-f0-9]+).*#\1/raw/\2#p' /home/developer/nodejs/node/.github/workflows/test-shared.yml)/install-nix.sh" | \ USER=developer \ @@ -36,6 +36,7 @@ RUN curl -L "https://github.com/$(sed -nE 's#.*(cachix/install-nix-action)@([a-f ENV NIX_PROFILES="/nix/var/nix/profiles/default /home/developer/.nix-profile" ENV NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt ENV PATH="/home/developer/.local/bin:/home/developer/.nix-profile/bin:${PATH}" +# Installing Cachix, and set it up to reuse binaries build by the CI. RUN nix-env -iA cachix -f https://cachix.org/api/v1/install RUN USER=developer cachix use nodejs @@ -47,7 +48,7 @@ RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc # Setting up direnv for the local clone ARG USE_SHARED_LIBS=false -# Modifications to the env (such as adding flags, or env variables) should be done upstream unless it's only applicable to this repo. +# As much as possible, we want to use the defaults set in shell.nix so the DX is consistent for users of devcontainers and users of Nix. RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}' --argstr icu full")" > /home/developer/nodejs/node/.envrc RUN direnv allow /home/developer/nodejs/node diff --git a/scripts/build.sh b/scripts/build.sh index 375eedc..b9715c0 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -5,5 +5,6 @@ set -xe cd /home/developer/nodejs/node eval "$(direnv export bash)" -# BUILD_WTIH=ninja is set in https://github.com/nodejs/node/blob/HEAD/shell.nix +# Build tools and env variables (including e.g. BUILD_WITH=ninja) are +# defined in https://github.com/nodejs/node/blob/HEAD/shell.nix make -C /home/developer/nodejs/node build-ci From 7f78042778ff10d690bce47f64a634f69f5a501d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 24 Dec 2025 01:00:49 +0100 Subject: [PATCH 10/11] fix quoting in `install-node` --- scripts/install-node.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install-node.sh b/scripts/install-node.sh index 8042f8f..1754096 100755 --- a/scripts/install-node.sh +++ b/scripts/install-node.sh @@ -9,5 +9,5 @@ make install PREFIX=/home/developer/.local -C /home/developer/nodejs/node { echo '' # Expose the PATH generated by Nix + the recently built `node` installation - echo "export PATH=/home/developer/.local/bin:$PATH" - } >> /home/developer/.bashrc + echo 'export PATH=/home/developer/.local/bin:$PATH' +} >> /home/developer/.bashrc From 17b2b04ce88f3b04e83349e1c916c50d57092e64 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 24 Dec 2025 01:04:31 +0100 Subject: [PATCH 11/11] add `IMAGE_VARIANT` build var --- Dockerfile | 8 ++++---- envrc/README.md | 26 ++++++++++++++++++++++++++ envrc/shared-libs.envrc | 1 + envrc/static-libs.envrc | 3 +++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 envrc/README.md create mode 100644 envrc/shared-libs.envrc create mode 100644 envrc/static-libs.envrc diff --git a/Dockerfile b/Dockerfile index 6fb5922..b3d288c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,10 +46,10 @@ RUN mkdir -p /home/developer/.config/direnv && \ echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > /home/developer/.config/direnv/direnvrc RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc -# Setting up direnv for the local clone -ARG USE_SHARED_LIBS=false -# As much as possible, we want to use the defaults set in shell.nix so the DX is consistent for users of devcontainers and users of Nix. -RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}' --argstr icu full")" > /home/developer/nodejs/node/.envrc +# Setting up direnv for the local clone, see envrc/README.md for more info +COPY --chown=root:developer --chmod=0644 ./envrc/ /home/developer/envrc/ +ARG IMAGE_VARIANT=static-libs +RUN cp "/home/developer/envrc/${IMAGE_VARIANT}.envrc" /home/developer/nodejs/node/.envrc RUN direnv allow /home/developer/nodejs/node RUN /home/developer/scripts/build.sh diff --git a/envrc/README.md b/envrc/README.md new file mode 100644 index 0000000..f1a1b44 --- /dev/null +++ b/envrc/README.md @@ -0,0 +1,26 @@ +# Image variants using Nix and direnv + +`.envrc` files are consumed by [nix-direnv][], and will install software and +environment variables defined in the [`shell.nix`][] in the nodejs/node repository. + +To add an image variant, add a new file starting with `use nix` with the flags such as: + +- [`--impure`][]: to make sure user can still access non-Nix software. +- [`-I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix`][`-I`]: + that defines which version of the [NixOS/nixpkgs][] repository it should load. +- [`--arg `][`--arg`]: Override the default values defines in the + [`shell.nix`][] with some custom value. +- [`--argstr `][`--argstr`]: Useful to avoid the double quoting, + e.g. instead of `--arg icu '"small"'`, it is equivalent to pass `--argstr icu small`. + +It is possible to add custom environment variables, or to override Nix-defined ones by +adding `export NAME_OF_THE_VAR=value` lines at the end of the file, however it is +preferred to keep all environment variable definitions in one place. + +[nix-direnv]: https://github.com/nix-community/nix-direnv +[`shell.nix`]: https://github.com/nodejs/node/blob/HEAD/shell.nix +[NixOS/nixpkgs]: https://github.com/NixOS/nixpkgs +[`--impure`]: https://nix.dev/manual/nix/2.33/command-ref/nix-shell.html#opt-impure +[`-I`]: https://nix.dev/manual/nix/2.33/command-ref/nix-shell.html#opt-I +[`--arg`]: https://nix.dev/manual/nix/2.33/command-ref/nix-shell.html#opt-arg +[`--argstr`]: https://nix.dev/manual/nix/2.33/command-ref/nix-shell.html#opt-argstr diff --git a/envrc/shared-libs.envrc b/envrc/shared-libs.envrc new file mode 100644 index 0000000..e99e472 --- /dev/null +++ b/envrc/shared-libs.envrc @@ -0,0 +1 @@ +use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix diff --git a/envrc/static-libs.envrc b/envrc/static-libs.envrc new file mode 100644 index 0000000..bd8f87e --- /dev/null +++ b/envrc/static-libs.envrc @@ -0,0 +1,3 @@ +use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix \ + --arg sharedLibDeps '{}' \ + --argstr icu full