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*/ 5let 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; 42in 43if pathOverlays != "" && builtins.pathExists pathOverlays then 44 overlays pathOverlays 45else 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 '' 50else if builtins.pathExists homeOverlaysFile then 51 if isDir homeOverlaysFile then 52 throw (homeOverlaysFile + " should be a file") 53 else 54 overlays homeOverlaysFile 55else if builtins.pathExists homeOverlaysDir then 56 if !(isDir homeOverlaysDir) then 57 throw (homeOverlaysDir + " should be a directory") 58 else 59 overlays homeOverlaysDir 60else 61 [ ]