mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-11-13 12:13:46 +01:00
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:
1 parent
89d7a9bd82
commit
af084f1eb4
3 files changed
+34
-2
No files matched your search
@@ -4,6 +4,7 @@
|
||||
# npm - set min-release-age(in days) for supply-chain security
|
||||
home.file.".npmrc".text = ''
|
||||
prefix=${config.home.homeDirectory}/.npm
|
||||
registry=https://registry.npmmirror.com
|
||||
min-release-age=2
|
||||
'';
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
{
|
||||
pkgs,
|
||||
config,
|
||||
nixpkgsConfig,
|
||||
...
|
||||
}:
|
||||
{
|
||||
nixpkgs.config = nixpkgsConfig;
|
||||
|
||||
nix.settings = {
|
||||
# enable flakes globally
|
||||
experimental-features = [
|
||||
|
||||
+30
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user