Nix-shell into a local derivation invokes "Permission denied" error

I am trying to learn a little more about nix-shell and I want to learn to create a shell environment in which I can use local packages (kind of want to mimic the behaviour of nix-shell -p <pkgs> but with local packages or custom packages). Here I have a local package “busybox-1.36.1” (the busybox package is already in nixpkgs but) I want to learn to create a shell environment in which I can use this local package. But after some back and forth in this site and chatgpt and other guides, I am getting an error of “Permission denied”. I am the only user in my system and I didn’t use sudo to download or make any of the files. I am not sure where I am going wrong at the moment but any guidance will really help me.

File Structure

this is the file structure (the content of the .nix file is at the end of this question):

.
├── busybox-1.36.1
├── busybox.nix
├── flake.lock
├── flake.nix
└── shell.nix

(note: the flake.nix and flake.lock is when I was trying to see what happens with nix shell which throws me a different error)

Error Message

When I try to run nix-shell, I get this error which shows “Permission denied”:

$ nix-shell
this derivation will be built:
  /nix/store/w0dvil4784n3d78qnkdnxsmw0dsz6bgh-busybox-1.36.1.drv
building '/nix/store/w0dvil4784n3d78qnkdnxsmw0dsz6bgh-busybox-1.36.1.drv'...
Running phase: buildPhase
sh: line 1: bb_libtest.c: Permission denied
rm: cannot remove 'bb_libtest.c': No such file or directory
sh: line 1: bb_libtest.c: Permission denied
rm: cannot remove 'bb_libtest.c': No such file or directory
sh: line 1: .kernelrelease: Permission denied
make: *** [Makefile:785: .kernelrelease] Error 1
error: builder for '/nix/store/w0dvil4784n3d78qnkdnxsmw0dsz6bgh-busybox-1.36.1.drv' failed with exit code 2;
       last 7 log lines:
       > Running phase: buildPhase
       > sh: line 1: bb_libtest.c: Permission denied
       > rm: cannot remove 'bb_libtest.c': No such file or directory
       > sh: line 1: bb_libtest.c: Permission denied
       > rm: cannot remove 'bb_libtest.c': No such file or directory
       > sh: line 1: .kernelrelease: Permission denied
       > make: *** [Makefile:785: .kernelrelease] Error 1
       For full logs, run 'nix log /nix/store/w0dvil4784n3d78qnkdnxsmw0dsz6bgh-busybox-1.36.1.drv'.

File Ownership or Permission

Looking into the ownership of these files and folder with ls -l, it is as follows:

$ ls -l
total 24
drwxrwxrwx 35 abdulla users 4096 Jun 18 11:38 busybox-1.36.1
-rwxrwxrwx  1 abdulla users  528 Jun 20 19:32 busybox.nix
-rw-r--r--  1 abdulla users 1385 Jun 21 11:03 flake.lock
-rw-r--r--  1 abdulla users  355 Jun 20 22:47 flake.nix
-rw-r--r--  1 abdulla users  565 Jun 20 19:37 flake.nix.old
-rwxrwxrwx  1 abdulla users  390 Jun 20 19:41 shell.nix

File Contents

These are the contents of the files:

busybox.nix

# busybox.nix

{ lib, fetchurl, stdenv, autoconf, automake, libtool, gcc, gnumake, ... }:

stdenv.mkDerivation rec {
  pname = "busybox";
  version = "1.36.1";
  make = gnumake;

  src = ./busybox-1.36.1;

  buildInputs = [ autoconf automake libtool gcc make ];

  phases = [ "buildPhase" "installPhase" ];

  buildPhase = ''
    cd $src
    make
    '';

  installPhase = ''
    cd $src
    mkdir -p $out/bin $out/sbin
    make CONFIG_PREFIX=$out install
    '';

  meta = {
    description = "The Swiss Army Knife of Embedded Linux";
  };
}

shell.nix

# shell.nix

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [
    pkgs.autoconf
    pkgs.automake
    pkgs.libtool
    pkgs.gcc
    pkgs.gnumake
  ];

  # Load the BusyBox derivation and include its build inputs
  busybox = pkgs.callPackage ./busybox.nix {};
  
  shellHook = ''
    echo "Entering shell with BusyBox environment"
    export PATH=$busybox/bin:$PATH
  '';
}

flake.nix (in case anyone wants to advise me on using nix shell)

# flake.nix

{
  description = "my project description";

  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem
      (system:
        let pkgs = nixpkgs.legacyPackages.${system}; in
        {
          devShells.default = import ./shell.nix { inherit pkgs; };
        }
      );
}