···11+/**
22+ This file has as its value the list of overlays, as determined from the environment.
33+ 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.
44+*/
55+let
66+ # Return ‘x’ if it evaluates, or ‘def’ if it throws an exception.
77+ try =
88+ x: def:
99+ let
1010+ res = builtins.tryEval x;
1111+ in
1212+ if res.success then res.value else def;
1313+ homeDir = builtins.getEnv "HOME";
1414+1515+ isDir = path: builtins.pathExists (path + "/.");
1616+ pathOverlays = try (toString <nixpkgs-overlays>) "";
1717+ homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix";
1818+ homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays";
1919+ overlays =
2020+ path:
2121+ # check if the path is a directory or a file
2222+ if isDir path then
2323+ # it's a directory, so the set of overlays from the directory, ordered lexicographically
2424+ let
2525+ content = builtins.readDir path;
2626+ in
2727+ map (n: import (path + ("/" + n))) (
2828+ builtins.filter (
2929+ n:
3030+ (
3131+ builtins.match ".*\\.nix" n != null
3232+ &&
3333+ # ignore Emacs lock files (.#foo.nix)
3434+ builtins.match "\\.#.*" n == null
3535+ )
3636+ || builtins.pathExists (path + ("/" + n + "/default.nix"))
3737+ ) (builtins.attrNames content)
3838+ )
3939+ else
4040+ # it's a file, so the result is the contents of the file itself
4141+ import path;
4242+in
4343+if pathOverlays != "" && builtins.pathExists pathOverlays then
4444+ overlays pathOverlays
4545+else if builtins.pathExists homeOverlaysFile && builtins.pathExists homeOverlaysDir then
4646+ throw ''
4747+ Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both.
4848+ Please remove one of them and try again.
4949+ ''
5050+else if builtins.pathExists homeOverlaysFile then
5151+ if isDir homeOverlaysFile then
5252+ throw (homeOverlaysFile + " should be a file")
5353+ else
5454+ overlays homeOverlaysFile
5555+else if builtins.pathExists homeOverlaysDir then
5656+ if !(isDir homeOverlaysDir) then
5757+ throw (homeOverlaysDir + " should be a directory")
5858+ else
5959+ overlays homeOverlaysDir
6060+else
6161+ [ ]
+1-57
pkgs/top-level/impure.nix
···7788 homeDir = builtins.getEnv "HOME";
991010- # Return ‘x’ if it evaluates, or ‘def’ if it throws an exception.
1111- try =
1212- x: def:
1313- let
1414- res = builtins.tryEval x;
1515- in
1616- if res.success then res.value else def;
1717-1810in
19112012{
···5042 # Overlays are used to extend Nixpkgs collection with additional
5143 # collections of packages. These collection of packages are part of the
5244 # fix-point made by Nixpkgs.
5353- overlays ?
5454- let
5555- isDir = path: builtins.pathExists (path + "/.");
5656- pathOverlays = try (toString <nixpkgs-overlays>) "";
5757- homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix";
5858- homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays";
5959- overlays =
6060- path:
6161- # check if the path is a directory or a file
6262- if isDir path then
6363- # it's a directory, so the set of overlays from the directory, ordered lexicographically
6464- let
6565- content = builtins.readDir path;
6666- in
6767- map (n: import (path + ("/" + n))) (
6868- builtins.filter (
6969- n:
7070- (
7171- builtins.match ".*\\.nix" n != null
7272- &&
7373- # ignore Emacs lock files (.#foo.nix)
7474- builtins.match "\\.#.*" n == null
7575- )
7676- || builtins.pathExists (path + ("/" + n + "/default.nix"))
7777- ) (builtins.attrNames content)
7878- )
7979- else
8080- # it's a file, so the result is the contents of the file itself
8181- import path;
8282- in
8383- if pathOverlays != "" && builtins.pathExists pathOverlays then
8484- overlays pathOverlays
8585- else if builtins.pathExists homeOverlaysFile && builtins.pathExists homeOverlaysDir then
8686- throw ''
8787- Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both.
8888- Please remove one of them and try again.
8989- ''
9090- else if builtins.pathExists homeOverlaysFile then
9191- if isDir homeOverlaysFile then
9292- throw (homeOverlaysFile + " should be a file")
9393- else
9494- overlays homeOverlaysFile
9595- else if builtins.pathExists homeOverlaysDir then
9696- if !(isDir homeOverlaysDir) then
9797- throw (homeOverlaysDir + " should be a directory")
9898- else
9999- overlays homeOverlaysDir
100100- else
101101- [ ],
4545+ overlays ? import ./impure-overlays.nix,
1024610347 crossOverlays ? [ ],
10448