about summary refs log tree commit diff
diff options
context:
space:
mode:
authoradisbladis <adisbladis@gmail.com>2024-07-04 13:47:08 +1200
committerGitHub <noreply@github.com>2024-07-04 13:47:08 +1200
commit1be927ca6672322781a4cdb44ec4bb74260acd33 (patch)
treee5cda59dd9caaf37903c45fd00f1dac61cbe15f9
parent7e4cda72fcee65122fccd43967732eecfbc62a43 (diff)
parent8d2a765adf01d45bddc63fbc2e97d0e5cf1638f8 (diff)
Merge pull request #316983 from edolstra/let-float-json
Let-float various fromJSON calls to avoid repeated JSON reading/parsing
-rw-r--r--pkgs/applications/editors/emacs/elisp-packages/melpa-packages.nix9
-rw-r--r--pkgs/applications/editors/jetbrains/default.nix11
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk11-darwin.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk11-linux.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk13-darwin.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk13-linux.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk14-darwin.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk14-linux.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk15-darwin.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk15-linux.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk16-darwin.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk16-linux.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk17-darwin.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk17-linux.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk8-darwin.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/jdk8-linux.nix2
-rw-r--r--pkgs/development/compilers/adoptopenjdk-bin/sources.nix1
-rw-r--r--pkgs/development/tools/electron/binary/default.nix5
-rw-r--r--pkgs/games/papermc/default.nix4
-rw-r--r--pkgs/misc/translatelocally-models/default.nix5
-rw-r--r--pkgs/os-specific/linux/kernel/mainline.nix5
21 files changed, 44 insertions, 24 deletions
diff --git a/pkgs/applications/editors/emacs/elisp-packages/melpa-packages.nix b/pkgs/applications/editors/emacs/elisp-packages/melpa-packages.nix
index 1e9a8191b3f16..00646b6d81b38 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 fb57331cc3b46..af155d9de826c 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 1fd2fd8dc09e4..f4f5108df4372 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 fcad50017dbaf..6d5b1b036e5b3 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 fdde25bd361df..87beaf8ddaf86 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 6c57b542e65bf..e6c0002014158 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 1c776f69e2dba..a4d5b1fc432ee 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 573fc17b51be1..4d357969f0aed 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 369822fa1ef74..422e5f21e96cf 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 52641c690bf03..47bd2a5c9f9fd 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 454e92834bb0a..4eef76cb63129 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 3a50ad669c2e7..873e0ce3549de 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 d9309d9ce0b0f..b79b39902226b 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 e069a8521d72e..b8bb1cbf2bab7 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 8468708699109..56028d7f25e42 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 2b0cac6649837..ee8226f6903db 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 0000000000000..0d5dd3c6cd480
--- /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 b884428cf8b73..07637d13e9f25 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 29d5c6b852032..037b307c6df37 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 3c71247d1d9a9..82f6556e93d95 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 4e1d5b8a9e87c..862ba8e8ddcce 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;