Fix `legacyPackages` performance (#423290)

authored by Robert Hensing and committed by GitHub 5d22f1ff bd3237f7

+70 -62
+8 -5
flake.nix
··· 209 209 */ 210 210 legacyPackages = forAllSystems ( 211 211 system: 212 - (import ./. { inherit system; }).extend ( 213 - final: prev: { 214 - lib = prev.lib.extend libVersionInfoOverlay; 215 - } 216 - ) 212 + (import ./. { 213 + inherit system; 214 + overlays = import ./pkgs/top-level/impure-overlays.nix ++ [ 215 + (final: prev: { 216 + lib = prev.lib.extend libVersionInfoOverlay; 217 + }) 218 + ]; 219 + }) 217 220 ); 218 221 219 222 /**
+61
pkgs/top-level/impure-overlays.nix
··· 1 + /** 2 + This file has as its value the list of overlays, as determined from the environment. 3 + If Nix evaluation is [pure](https://nix.dev/manual/nix/latest/command-ref/conf-file.html?highlight=pure-eval#conf-pure-eval), then the list is empty. 4 + */ 5 + let 6 + # Return ‘x’ if it evaluates, or ‘def’ if it throws an exception. 7 + try = 8 + x: def: 9 + let 10 + res = builtins.tryEval x; 11 + in 12 + if res.success then res.value else def; 13 + homeDir = builtins.getEnv "HOME"; 14 + 15 + isDir = path: builtins.pathExists (path + "/."); 16 + pathOverlays = try (toString <nixpkgs-overlays>) ""; 17 + homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix"; 18 + homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays"; 19 + overlays = 20 + path: 21 + # check if the path is a directory or a file 22 + if isDir path then 23 + # it's a directory, so the set of overlays from the directory, ordered lexicographically 24 + let 25 + content = builtins.readDir path; 26 + in 27 + map (n: import (path + ("/" + n))) ( 28 + builtins.filter ( 29 + n: 30 + ( 31 + builtins.match ".*\\.nix" n != null 32 + && 33 + # ignore Emacs lock files (.#foo.nix) 34 + builtins.match "\\.#.*" n == null 35 + ) 36 + || builtins.pathExists (path + ("/" + n + "/default.nix")) 37 + ) (builtins.attrNames content) 38 + ) 39 + else 40 + # it's a file, so the result is the contents of the file itself 41 + import path; 42 + in 43 + if pathOverlays != "" && builtins.pathExists pathOverlays then 44 + overlays pathOverlays 45 + else if builtins.pathExists homeOverlaysFile && builtins.pathExists homeOverlaysDir then 46 + throw '' 47 + Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both. 48 + Please remove one of them and try again. 49 + '' 50 + else if builtins.pathExists homeOverlaysFile then 51 + if isDir homeOverlaysFile then 52 + throw (homeOverlaysFile + " should be a file") 53 + else 54 + overlays homeOverlaysFile 55 + else if builtins.pathExists homeOverlaysDir then 56 + if !(isDir homeOverlaysDir) then 57 + throw (homeOverlaysDir + " should be a directory") 58 + else 59 + overlays homeOverlaysDir 60 + else 61 + [ ]
+1 -57
pkgs/top-level/impure.nix
··· 7 7 8 8 homeDir = builtins.getEnv "HOME"; 9 9 10 - # Return ‘x’ if it evaluates, or ‘def’ if it throws an exception. 11 - try = 12 - x: def: 13 - let 14 - res = builtins.tryEval x; 15 - in 16 - if res.success then res.value else def; 17 - 18 10 in 19 11 20 12 { ··· 50 42 # Overlays are used to extend Nixpkgs collection with additional 51 43 # collections of packages. These collection of packages are part of the 52 44 # fix-point made by Nixpkgs. 53 - overlays ? 54 - let 55 - isDir = path: builtins.pathExists (path + "/."); 56 - pathOverlays = try (toString <nixpkgs-overlays>) ""; 57 - homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix"; 58 - homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays"; 59 - overlays = 60 - path: 61 - # check if the path is a directory or a file 62 - if isDir path then 63 - # it's a directory, so the set of overlays from the directory, ordered lexicographically 64 - let 65 - content = builtins.readDir path; 66 - in 67 - map (n: import (path + ("/" + n))) ( 68 - builtins.filter ( 69 - n: 70 - ( 71 - builtins.match ".*\\.nix" n != null 72 - && 73 - # ignore Emacs lock files (.#foo.nix) 74 - builtins.match "\\.#.*" n == null 75 - ) 76 - || builtins.pathExists (path + ("/" + n + "/default.nix")) 77 - ) (builtins.attrNames content) 78 - ) 79 - else 80 - # it's a file, so the result is the contents of the file itself 81 - import path; 82 - in 83 - if pathOverlays != "" && builtins.pathExists pathOverlays then 84 - overlays pathOverlays 85 - else if builtins.pathExists homeOverlaysFile && builtins.pathExists homeOverlaysDir then 86 - throw '' 87 - Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both. 88 - Please remove one of them and try again. 89 - '' 90 - else if builtins.pathExists homeOverlaysFile then 91 - if isDir homeOverlaysFile then 92 - throw (homeOverlaysFile + " should be a file") 93 - else 94 - overlays homeOverlaysFile 95 - else if builtins.pathExists homeOverlaysDir then 96 - if !(isDir homeOverlaysDir) then 97 - throw (homeOverlaysDir + " should be a directory") 98 - else 99 - overlays homeOverlaysDir 100 - else 101 - [ ], 45 + overlays ? import ./impure-overlays.nix, 102 46 103 47 crossOverlays ? [ ], 104 48