Unable to install node packages for gitlab-ci-local project

So the context is that Im trying to run the project gitlab-ci-local (GitHub - firecow/gitlab-ci-local: Tired of pushing to test your .gitlab-ci.yml?) via custom nixos derivation but am getting the error at the stage where it is installing the node modules for the project. Here are the necessary files with the error:

  1. default.nix file:
let
  pkgs = import <nixpkgs> {};
in
  import ./gitlab-ci-local.nix {
    stdenv = pkgs.stdenv;
    fetchurl = pkgs.fetchurl;
    nodejs = pkgs.nodejs_20;
    lib = pkgs.lib;
  }

  1. gitlab-ci-local.nix
{ stdenv, fetchurl, nodejs, lib }:

stdenv.mkDerivation rec {
  pname = "gitlab-ci-local";
  version = "4.44.0";

  src = fetchurl {
    url = "https://api.github.com/repos/firecow/gitlab-ci-local/tarball/4.44.0";
    sha256 = "JD5l5Imiupm02ahVzyX/bTzMPir5FPZUnIg5JXPQG30=";
  };

  unpackPhase = ''
    tar -xzf $src
  '';

  nativeBuildInputs = [ nodejs ];

  buildPhase = ''
    cd firecow-gitlab-ci-local-c59eab8
    npm install
    npm run build
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp -r build/* $out/bin/
  '';

  meta = with lib; {
    description = "Run GitLab pipelines locally";
    license = licenses.mit;
    platforms = platforms.linux;
  };
}
  1. Error that I am getting:
[uzi@nixos:~/etc/nixos/project/derivations]$ nix-build default.nix
these 2 derivations will be built:
  /nix/store/zi9ssk22nhjc02rw4g6mmrjvzvb4dnl6-4.44.0.drv
  /nix/store/54zn7zdn5wsnjvirx315p9spcfyi7dgl-gitlab-ci-local-4.44.0.drv
these 21 paths will be fetched (4.58 MiB download, 24.11 MiB unpacked):
  /nix/store/05jrf7nnv3nzv0dmcwi2cq9gnv39wikj-libkrb5-1.20.1-dev
  /nix/store/2q1x5hazpr8yf5hh0pj09nmz94sc7q81-file-5.44
  /nix/store/4hnv473m55jv6j0pxdawcr5fcc3mgx9f-mirrors-list
  /nix/store/502zy2vrfc1ncgnpqrywb6k589cs37yn-curl-8.1.1-bin
  /nix/store/55i3fg8rv3ppc7l9nml34glgjq33njis-nghttp2-1.51.0-lib
  /nix/store/5rbqiz11vagap5fsk3vw8fgznw6vxyrh-patchelf-0.15.0
  /nix/store/60yjahg1bx0dhcgxcs2gndyycwchv8pz-openssl-3.0.10-dev
  /nix/store/6m8yldi3j1g7m11k9sh16mzv89mzn300-libkrb5-1.20.1
  /nix/store/cj9q2w7z4m207fi0d10isx6g3ss0mmrb-stdenv-linux
  /nix/store/f02079fv9arqmzl8dmys8m2dqsi8414b-libssh2-1.11.0
  /nix/store/ik9ibmq0rbznwyj6472lv2ab0c397lhy-gnumake-4.4.1
  /nix/store/kxdf0cf0hp44g0gnghddqvqdl40abrlj-curl-8.1.1-man
  /nix/store/m5lrwabwapmmbbg4p5d0wi3jjfckmjib-nghttp2-1.51.0-dev
  /nix/store/ns6r87jr7aniv401p5yb3xi776hn1c4m-nghttp2-1.51.0-bin
  /nix/store/pdc9h5virf325gn96sdwxarzv2s00qq3-openssl-3.0.10
  /nix/store/plbw4jp9wv3bf9vqij235gvxc2dbhj4a-curl-8.1.1-dev
  /nix/store/rh9k2d6kaq5f39wc21nkvjk2s2nvazkw-openssl-3.0.10-bin
  /nix/store/vfdg65hiv4bwls48588msw8la7452w2q-stdenv-linux
  /nix/store/wwzriw5z17sk82cm758r9habbkaz1dhv-curl-8.1.1
  /nix/store/xq4isfp20b1vrdl09fv71wmxll5l4lcd-libssh2-1.11.0-dev
  /nix/store/y6njq1nz4x5wsg01h407qqpy68aicdrf-nghttp2-1.51.0
copying path '/nix/store/2q1x5hazpr8yf5hh0pj09nmz94sc7q81-file-5.44' from 'https://cache.nixos.org'...
copying path '/nix/store/ik9ibmq0rbznwyj6472lv2ab0c397lhy-gnumake-4.4.1' from 'https://cache.nixos.org'...
copying path '/nix/store/4hnv473m55jv6j0pxdawcr5fcc3mgx9f-mirrors-list' from 'https://cache.nixos.org'...
copying path '/nix/store/5rbqiz11vagap5fsk3vw8fgznw6vxyrh-patchelf-0.15.0' from 'https://cache.nixos.org'...
copying path '/nix/store/kxdf0cf0hp44g0gnghddqvqdl40abrlj-curl-8.1.1-man' from 'https://cache.nixos.org'...
copying path '/nix/store/y6njq1nz4x5wsg01h407qqpy68aicdrf-nghttp2-1.51.0' from 'https://cache.nixos.org'...
copying path '/nix/store/ns6r87jr7aniv401p5yb3xi776hn1c4m-nghttp2-1.51.0-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/6m8yldi3j1g7m11k9sh16mzv89mzn300-libkrb5-1.20.1' from 'https://cache.nixos.org'...
copying path '/nix/store/55i3fg8rv3ppc7l9nml34glgjq33njis-nghttp2-1.51.0-lib' from 'https://cache.nixos.org'...
copying path '/nix/store/pdc9h5virf325gn96sdwxarzv2s00qq3-openssl-3.0.10' from 'https://cache.nixos.org'...
copying path '/nix/store/m5lrwabwapmmbbg4p5d0wi3jjfckmjib-nghttp2-1.51.0-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/cj9q2w7z4m207fi0d10isx6g3ss0mmrb-stdenv-linux' from 'https://cache.nixos.org'...
copying path '/nix/store/vfdg65hiv4bwls48588msw8la7452w2q-stdenv-linux' from 'https://cache.nixos.org'...
copying path '/nix/store/05jrf7nnv3nzv0dmcwi2cq9gnv39wikj-libkrb5-1.20.1-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/f02079fv9arqmzl8dmys8m2dqsi8414b-libssh2-1.11.0' from 'https://cache.nixos.org'...
copying path '/nix/store/rh9k2d6kaq5f39wc21nkvjk2s2nvazkw-openssl-3.0.10-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/60yjahg1bx0dhcgxcs2gndyycwchv8pz-openssl-3.0.10-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/wwzriw5z17sk82cm758r9habbkaz1dhv-curl-8.1.1' from 'https://cache.nixos.org'...
copying path '/nix/store/xq4isfp20b1vrdl09fv71wmxll5l4lcd-libssh2-1.11.0-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/502zy2vrfc1ncgnpqrywb6k589cs37yn-curl-8.1.1-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/plbw4jp9wv3bf9vqij235gvxc2dbhj4a-curl-8.1.1-dev' from 'https://cache.nixos.org'...
building '/nix/store/zi9ssk22nhjc02rw4g6mmrjvzvb4dnl6-4.44.0.drv'...

trying https://api.github.com/repos/firecow/gitlab-ci-local/tarball/4.44.0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  333k    0  333k    0     0  31779      0 --:--:--  0:00:10 --:--:-- 73663
building '/nix/store/54zn7zdn5wsnjvirx315p9spcfyi7dgl-gitlab-ci-local-4.44.0.drv'...
unpacking sources
patching sources
configuring
no configure script, doing nothing
building
npm ERR! code EAI_AGAIN
npm ERR! syscall getaddrinfo
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org

npm ERR! Log files were not written due to an error writing to the directory: /homeless-shelter/.npm/_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

error: builder for '/nix/store/54zn7zdn5wsnjvirx315p9spcfyi7dgl-gitlab-ci-local-4.44.0.drv' failed with exit code 1;
       last 10 log lines:
       > no configure script, doing nothing
       > building
       > npm ERR! code EAI_AGAIN
       > npm ERR! syscall getaddrinfo
       > npm ERR! errno EAI_AGAIN
       > npm ERR! request to https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org
       > 
       > npm ERR! Log files were not written due to an error writing to the directory: /homeless-shelter/.npm/_logs
       > npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
       > 
       For full logs, run 'nix log /nix/store/54zn7zdn5wsnjvirx315p9spcfyi7dgl-gitlab-ci-local-4.44.0.drv'.

Will appreciate if someone could guide me to a resolution. I doubt it is a DNS issue as Im able to carry out npm install on other projects.

So after doing some research and help from a redditor I found out that nixos derivation does not allow access to the internet. This is for reproducability. An alternate approach from the nixos documentation would be to use buildNpmPackage Nixpkgs 23.11 manual | Nix & NixOS

Implementing buildNpmPackage worked and heres the working build:

  1. default.nix
let
  pkgs = import <nixpkgs> {};
in
  import ./gitlab-ci-local.nix {
    lib = pkgs.lib;
    buildNpmPackage = pkgs.buildNpmPackage;
    fetchFromGitHub = pkgs.fetchFromGitHub;
    git = pkgs.git;
  }

  1. gitlab-ci-local.nix
{ lib, buildNpmPackage, fetchFromGitHub,git }:

buildNpmPackage rec {
  pname = "gitlab-ci-local";
  version = "4.7.0";

  src = fetchFromGitHub {
    owner = "firecow";
    repo = "gitlab-ci-local";
    rev = "c59eab87de7550936ae37b94c6ad9493e4e5d673";
    sha256 = "6e0sgSqOk24XAlL7ISC5ZB9Pa+WJbrjfPLBNW94XYLI="; 
  };

  npmDepsHash = "sha256-QhE6C7i7VOjzKCFQNouPxv4/DXj79/woJy1jHbZEh/w=";

  preBuild = ''
    substituteInPlace package.json \
      --replace '"cleanup": "git clean -fX tests/ && git clean -fX src/"' '"cleanup": "echo skipping cleanup"'
  '';
  # The prepack script runs the build script, which we'd rather do in the build phase.
  npmPackFlags = [ "--ignore-scripts" ];

  NODE_OPTIONS = "--openssl-legacy-provider";

meta = with lib; {
    description = "Run GitLab pipelines locally";
    license = licenses.mit;
    platforms = platforms.linux;
  };
}

Alternatively we can use the __noChroot variable in the original implementation I shared to allow sandbox to access the internet but I have not tried it yet: