nixpkgs icon indicating copy to clipboard operation
nixpkgs copied to clipboard

nodejs/importNpmLock: init source overrides option

Open hsjobeki opened this issue 1 year ago • 2 comments

Description of changes

Allows the users to specify packageSourceOverrides for individual packages which can be used to:

  • Apply patches to any dependency.
  • Use nix-built nodejs dependencies.
  • Fetch private dependencies e.g. with builtins.fetchGit instead of pkgs.fetchGit.

The user of this interface is responsible to provide a correct node package which is specified:

https://docs.npmjs.com/about-packages-and-modules#about-package-formats

But Usually:

A folder containing a program described by a package.json file.

Usage example:

{ buildNpmPackage, importNpmLock, my-library,  stdenv, ... }:
  buildNpmPackage {
    pname = "hello";
    version = "0.1.0";
    src = ./.;

    npmDeps = importNpmLock {
      npmRoot = ./.;
      packageSourceOverrides = {
        "node_modules/A" = builtins.fetchGit {
              # my private repo
        };
       "node_modules/B" = stdenv.mkDerivation {
              # my custom dependency patch
        };
        "node_modules/@my/library" = my-library;
      };
    };

    npmConfigHook = pkgs.importNpmLock.npmConfigHook;
  };

Things done

  • Built on platform(s)
    • [x] x86_64-linux
    • [ ] aarch64-linux
    • [ ] x86_64-darwin
    • [ ] aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • [ ] sandbox = relaxed
    • [ ] sandbox = true
  • [ ] Tested, as applicable:
  • [ ] Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • [ ] Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • [ ] (Package updates) Added a release notes entry if the change is major or breaking
    • [ ] (Module updates) Added a release notes entry if the change is significant
    • [ ] (Module addition) Added a release notes entry if adding a new NixOS module
  • [ ] Fits CONTRIBUTING.md.

Add a :+1: reaction to pull requests you find important.

hsjobeki avatar Sep 02 '24 09:09 hsjobeki

@adisbladis What do you think ?

I didn't see the introduction of buildNodeModules early enough. Maybe we should factor this afterwards such that both can use the same node_modules source?

EDIT:

Something like spltting the argument list, such that that all arguments are transparently forwarded and we dont need to maintain seperate interfaces


 buildNodeModules =
    importLockArgs: {
    # ...
    , derivationArgs ? { }
    , nodejs ? pkgs.nodejs_latest
    }:
...
npmDeps = self.importNpmLock importLockArgs

hsjobeki avatar Sep 06 '24 07:09 hsjobeki

@philiptaron Could you continue the review of this PR? I use this already in some of my own projects.

Sometimes it is necessary to manual realize the symlink of the overriden dependency in node_modules in preBuild

hsjobeki avatar Oct 22 '24 09:10 hsjobeki

Sorry, I've been consumed with work that's not nixpkgs recently. Thanks for your patience.

philiptaron avatar Oct 23 '24 20:10 philiptaron