From 8d2a765adf01d45bddc63fbc2e97d0e5cf1638f8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 3 Jun 2024 18:52:42 +0200 Subject: [PATCH] Let-float various fromJSON calls to avoid repeated JSON reading/parsing Some of these were read/parsed dozens of times in a `nix search` invocation, and in particular the MELPA recipes archive (3 MiB) was read 4 times. --- .../editors/emacs/elisp-packages/melpa-packages.nix | 9 +++++++-- pkgs/applications/editors/jetbrains/default.nix | 11 +++++++---- .../compilers/adoptopenjdk-bin/jdk11-darwin.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk11-linux.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk13-darwin.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk13-linux.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk14-darwin.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk14-linux.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk15-darwin.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk15-linux.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk16-darwin.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk16-linux.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk17-darwin.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk17-linux.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk8-darwin.nix | 2 +- .../compilers/adoptopenjdk-bin/jdk8-linux.nix | 2 +- .../compilers/adoptopenjdk-bin/sources.nix | 1 + pkgs/development/tools/electron/binary/default.nix | 5 ++++- pkgs/games/papermc/default.nix | 4 +++- pkgs/misc/translatelocally-models/default.nix | 5 ++++- pkgs/os-specific/linux/kernel/mainline.nix | 5 ++++- 21 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 pkgs/development/compilers/adoptopenjdk-bin/sources.nix diff --git a/pkgs/applications/editors/emacs/elisp-packages/melpa-packages.nix b/pkgs/applications/editors/emacs/elisp-packages/melpa-packages.nix index bb45c383487c..5f5fdce90ac5 100644 --- a/pkgs/applications/editors/emacs/elisp-packages/melpa-packages.nix +++ b/pkgs/applications/editors/emacs/elisp-packages/melpa-packages.nix @@ -23,6 +23,11 @@ formats commits for you. */ +let + # Read ./recipes-archive-melpa.json in an outer let to make sure we only do this once. + defaultArchive = builtins.fromJSON (builtins.readFile ./recipes-archive-melpa.json); +in + { lib, pkgs }: variant: self: let dontConfigure = pkg: @@ -57,7 +62,7 @@ let if pkg != null then dontConfigure (externalSrc pkg pkgs.rtags) else null; - generateMelpa = lib.makeOverridable ({ archiveJson ? ./recipes-archive-melpa.json + generateMelpa = lib.makeOverridable ({ archiveJson ? defaultArchive }: let inherit (import ./libgenerated.nix lib self) melpaDerivation; @@ -66,7 +71,7 @@ let (s: s != null) (map (melpaDerivation variant) - (lib.importJSON archiveJson) + (if builtins.isList archiveJson then archiveJson else lib.importJSON archiveJson) ) ) ); diff --git a/pkgs/applications/editors/jetbrains/default.nix b/pkgs/applications/editors/jetbrains/default.nix index fb57331cc3b4..af155d9de826 100644 --- a/pkgs/applications/editors/jetbrains/default.nix +++ b/pkgs/applications/editors/jetbrains/default.nix @@ -1,3 +1,10 @@ +let + # `ides.json` is handwritten and contains information that doesn't change across updates, like maintainers and other metadata + # `versions.json` contains everything generated/needed by the update script version numbers, build numbers and tarball hashes + ideInfo = builtins.fromJSON (builtins.readFile ./bin/ides.json); + versions = builtins.fromJSON (builtins.readFile ./bin/versions.json); +in + { lib , stdenv , callPackage @@ -30,10 +37,6 @@ let inherit (stdenv.hostPlatform) system; - # `ides.json` is handwritten and contains information that doesn't change across updates, like maintainers and other metadata - # `versions.json` contains everything generated/needed by the update script version numbers, build numbers and tarball hashes - ideInfo = lib.importJSON ./bin/ides.json; - versions = lib.importJSON ./bin/versions.json; products = versions.${system} or (throw "Unsupported system: ${system}"); package = if stdenv.isDarwin then ./bin/darwin.nix else ./bin/linux.nix; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk11-darwin.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk11-darwin.nix index 1fd2fd8dc09e..f4f5108df437 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk11-darwin.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk11-darwin.nix @@ -1,7 +1,7 @@ { lib }: let - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-darwin-base.nix { sourcePerArch = sources.openjdk11.mac.jdk.hotspot; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk11-linux.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk11-linux.nix index fcad50017dba..6d5b1b036e5b 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk11-linux.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk11-linux.nix @@ -2,7 +2,7 @@ let variant = if stdenv.hostPlatform.isMusl then "alpine_linux" else "linux"; - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-linux-base.nix { sourcePerArch = sources.openjdk11.${variant}.jdk.hotspot; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk13-darwin.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk13-darwin.nix index fdde25bd361d..87beaf8ddaf8 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk13-darwin.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk13-darwin.nix @@ -1,7 +1,7 @@ { lib }: let - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-darwin-base.nix { sourcePerArch = sources.openjdk13.mac.jdk.hotspot; knownVulnerabilities = ["Support ended"]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk13-linux.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk13-linux.nix index 6c57b542e65b..e6c000201415 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk13-linux.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk13-linux.nix @@ -2,7 +2,7 @@ let variant = if stdenv.hostPlatform.isMusl then "alpine_linux" else "linux"; - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-linux-base.nix { sourcePerArch = sources.openjdk13.${variant}.jdk.hotspot; knownVulnerabilities = ["Support ended"]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk14-darwin.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk14-darwin.nix index 1c776f69e2db..a4d5b1fc432e 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk14-darwin.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk14-darwin.nix @@ -1,7 +1,7 @@ { lib }: let - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-darwin-base.nix { sourcePerArch = sources.openjdk14.mac.jdk.hotspot; knownVulnerabilities = ["Support ended"]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk14-linux.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk14-linux.nix index 573fc17b51be..4d357969f0ae 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk14-linux.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk14-linux.nix @@ -2,7 +2,7 @@ let variant = if stdenv.hostPlatform.isMusl then "alpine_linux" else "linux"; - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-linux-base.nix { sourcePerArch = sources.openjdk14.${variant}.jdk.hotspot; knownVulnerabilities = ["Support ended"]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk15-darwin.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk15-darwin.nix index 369822fa1ef7..422e5f21e96c 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk15-darwin.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk15-darwin.nix @@ -1,7 +1,7 @@ { lib }: let - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-darwin-base.nix { sourcePerArch = sources.openjdk15.mac.jdk.hotspot; knownVulnerabilities = [ "Support ended" ]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk15-linux.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk15-linux.nix index 52641c690bf0..47bd2a5c9f9f 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk15-linux.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk15-linux.nix @@ -2,7 +2,7 @@ let variant = if stdenv.hostPlatform.isMusl then "alpine_linux" else "linux"; - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-linux-base.nix { sourcePerArch = sources.openjdk15.${variant}.jdk.hotspot; knownVulnerabilities = [ "Support ended" ]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk16-darwin.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk16-darwin.nix index 454e92834bb0..4eef76cb6312 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk16-darwin.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk16-darwin.nix @@ -1,7 +1,7 @@ { lib }: let - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-darwin-base.nix { sourcePerArch = sources.openjdk16.mac.jdk.hotspot; knownVulnerabilities = [ "Support ended" ]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk16-linux.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk16-linux.nix index 3a50ad669c2e..873e0ce3549d 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk16-linux.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk16-linux.nix @@ -2,7 +2,7 @@ let variant = if stdenv.hostPlatform.isMusl then "alpine_linux" else "linux"; - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-linux-base.nix { sourcePerArch = sources.openjdk16.${variant}.jdk.hotspot; knownVulnerabilities = [ "Support ended" ]; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk17-darwin.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk17-darwin.nix index d9309d9ce0b0..b79b39902226 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk17-darwin.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk17-darwin.nix @@ -1,7 +1,7 @@ { lib }: let - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-darwin-base.nix { sourcePerArch = sources.openjdk17.mac.jdk.hotspot; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk17-linux.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk17-linux.nix index e069a8521d72..b8bb1cbf2bab 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk17-linux.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk17-linux.nix @@ -2,7 +2,7 @@ let variant = if stdenv.hostPlatform.isMusl then "alpine_linux" else "linux"; - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-linux-base.nix { sourcePerArch = sources.openjdk17.${variant}.jdk.hotspot; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk8-darwin.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk8-darwin.nix index 846870869910..56028d7f25e4 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk8-darwin.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk8-darwin.nix @@ -1,7 +1,7 @@ { lib }: let - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-darwin-base.nix { sourcePerArch = sources.openjdk8.mac.jdk.hotspot; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/jdk8-linux.nix b/pkgs/development/compilers/adoptopenjdk-bin/jdk8-linux.nix index 2b0cac664983..ee8226f6903d 100644 --- a/pkgs/development/compilers/adoptopenjdk-bin/jdk8-linux.nix +++ b/pkgs/development/compilers/adoptopenjdk-bin/jdk8-linux.nix @@ -2,7 +2,7 @@ let variant = if stdenv.hostPlatform.isMusl then "alpine_linux" else "linux"; - sources = lib.importJSON ./sources.json; + sources = import ./sources.nix; in { jdk-hotspot = import ./jdk-linux-base.nix { sourcePerArch = sources.openjdk8.${variant}.jdk.hotspot; }; diff --git a/pkgs/development/compilers/adoptopenjdk-bin/sources.nix b/pkgs/development/compilers/adoptopenjdk-bin/sources.nix new file mode 100644 index 000000000000..0d5dd3c6cd48 --- /dev/null +++ b/pkgs/development/compilers/adoptopenjdk-bin/sources.nix @@ -0,0 +1 @@ +builtins.fromJSON (builtins.readFile ./sources.json) diff --git a/pkgs/development/tools/electron/binary/default.nix b/pkgs/development/tools/electron/binary/default.nix index b884428cf8b7..07637d13e9f2 100644 --- a/pkgs/development/tools/electron/binary/default.nix +++ b/pkgs/development/tools/electron/binary/default.nix @@ -1,8 +1,11 @@ +let + infoJson = builtins.fromJSON (builtins.readFile ./info.json); +in + { lib, callPackage }: let mkElectron = callPackage ./generic.nix { }; - infoJson = builtins.fromJSON (builtins.readFile ./info.json); in lib.mapAttrs' (majorVersion: info: lib.nameValuePair diff --git a/pkgs/games/papermc/default.nix b/pkgs/games/papermc/default.nix index 29d5c6b85203..037b307c6df3 100644 --- a/pkgs/games/papermc/default.nix +++ b/pkgs/games/papermc/default.nix @@ -1,6 +1,8 @@ +let + versions = builtins.fromJSON (builtins.readFile ./versions.json); +in { callPackage, lib, ... }: let - versions = lib.importJSON ./versions.json; latestVersion = lib.last (builtins.sort lib.versionOlder (builtins.attrNames versions)); escapeVersion = builtins.replaceStrings [ "." ] [ "_" ]; packages = lib.mapAttrs' diff --git a/pkgs/misc/translatelocally-models/default.nix b/pkgs/misc/translatelocally-models/default.nix index 3c71247d1d9a..82f6556e93d9 100644 --- a/pkgs/misc/translatelocally-models/default.nix +++ b/pkgs/misc/translatelocally-models/default.nix @@ -1,7 +1,10 @@ +let + modelSpecs = (builtins.fromJSON (builtins.readFile ./models.json)); +in + { lib, stdenvNoCC, fetchurl }: let - modelSpecs = (builtins.fromJSON (builtins.readFile ./models.json)); withCodeAsKey = f: { code, ... }@attrs: lib.nameValuePair code (f attrs); mkModelPackage = { name, code, version, url, checksum }: stdenvNoCC.mkDerivation { diff --git a/pkgs/os-specific/linux/kernel/mainline.nix b/pkgs/os-specific/linux/kernel/mainline.nix index 4e1d5b8a9e87..862ba8e8ddcc 100644 --- a/pkgs/os-specific/linux/kernel/mainline.nix +++ b/pkgs/os-specific/linux/kernel/mainline.nix @@ -1,7 +1,10 @@ +let + allKernels = builtins.fromJSON (builtins.readFile ./kernels-org.json); +in + { branch, lib, fetchurl, fetchzip, buildLinux, ... } @ args: let - allKernels = builtins.fromJSON (builtins.readFile ./kernels-org.json); thisKernel = allKernels.${branch}; inherit (thisKernel) version;