feat(npm): use npmmirror for npm fetches

Set the user-level npm/pnpm registry to npmmirror, and make Nix builds use the same mirror through nixpkgs' npmRegistryOverrides and rewriteURL. The configured Nixpkgs policy is also applied to myNurPkgs and Colmena's nodeNixpkgs so NUR packages such as dsh use the mirror while preserving Colmena parity.
This commit is contained in:
Ryan Yin committed 2026-11-01 16:57:57 +08:00
1 parent 89d7a9bd82
commit af084f1eb4
3 files changed
+34 -2

No files matched your search

+30 -2
View File
@@ -9,6 +9,22 @@ let
mylib = import ../lib { inherit lib; };
myvars = import ../vars { inherit lib; };
# Keep npm fetches on the domestic mirror, including inside Nix builds.
# `rewriteURL` covers plain fetchurl calls; `npmRegistryOverrides` covers
# fetchNpmDeps (package-lock tarballs and registry packuments).
nixpkgsConfig = {
allowUnfree = true;
npmRegistryOverrides = {
"registry.npmjs.org" = "https://registry.npmmirror.com";
};
rewriteURL =
url:
if lib.hasPrefix "https://registry.npmjs.org/" url then
"https://registry.npmmirror.com/${lib.removePrefix "https://registry.npmjs.org/" url}"
else
url;
};
# Add my custom lib, vars, nixpkgs instance, and all the inputs to specialArgs,
# so that I can use them in all my nixos/home-manager/darwin modules.
genSpecialArgs =
@@ -29,6 +45,7 @@ let
inputs
mylib
myvars
nixpkgsConfig
pkgs-stable
;
@@ -58,7 +75,14 @@ let
};
# NUR packages for this system; modules use `myNurPkgs.dsh` instead of
# repeating `nur-ryan4yin.packages.${pkgs.stdenv.hostPlatform.system}`.
myNurPkgs = inputs.nur-ryan4yin.packages.${system};
# Instantiate them with the same Nixpkgs policy as the host so npm
# fetchers inside NUR packages also use the mirror.
myNurPkgs = import "${inputs.nur-ryan4yin}" {
pkgs = import inputs.nixpkgs {
inherit system;
config = nixpkgsConfig;
};
};
};
# This is the args for all the haumea modules in this folder.
@@ -106,7 +130,11 @@ let
meta = {
nixpkgs = import nixpkgs { system = "x86_64-linux"; };
nodeNixpkgs = builtins.mapAttrs (
name: _: import nixpkgs { inherit (nixosConfigurations.${name}.pkgs.stdenv.hostPlatform) system; }
name: _:
import nixpkgs {
inherit (nixosConfigurations.${name}.pkgs.stdenv.hostPlatform) system;
config = nixpkgsConfig;
}
) colmenaDeployments;
nodeSpecialArgs = builtins.mapAttrs (
name: _: nixosConfigurations.${name}._module.specialArgs