name: repl-overlays internalName: replOverlays settingType: PathsSetting default: []
A list of files containing Nix expressions that can be used to add
default bindings to nix repl sessions.
Each file is called with three arguments:
- An attribute set
containing at least a
currentSystemattribute (this is identical tobuiltins.currentSystem, except that it's available inpure-evalmode). - The final top-level bindings produced by calling all
repl-overlays. - The top-level bindings produced by the previous
repl-overlaysvalue (or the default top-level bindings).
For example, the following file would alias pkgs to
legacyPackages.${info.currentSystem} (if that attribute is defined):
info: final: prev:
if prev ? legacyPackages
&& prev.legacyPackages ? ${info.currentSystem}
then
{
pkgs = prev.legacyPackages.${info.currentSystem};
}
else
{ }
Here's a more elaborate repl-overlay, which provides the following
variables:
- The original, unmodified variables are aliased to
original. legacyPackages.${system}(if it exists) orpackages.${system}(otherwise) is aliased topkgs.- All attribute set variables with a
${system}attribute are abbreviated in the same manner; e.g.devShells.${system}is shortened todevShells.
For example, the following attribute set:
info: final: attrs: let
# Equivalent to nixpkgs `lib.optionalAttrs`.
optionalAttrs = predicate: attrs:
if predicate
then attrs
else {};
# If `attrs.${oldName}.${info.currentSystem}` exists, alias `${newName}` to
# it.
collapseRenamed = oldName: newName:
optionalAttrs (builtins.hasAttr oldName attrs
&& builtins.hasAttr info.currentSystem attrs.${oldName})
{
${newName} = attrs.${oldName}.${info.currentSystem};
};
# Alias `attrs.${oldName}.${info.currentSystem} to `${newName}`.
collapse = name: collapseRenamed name name;
# Alias all `attrs` keys with an `${info.currentSystem}` attribute.
collapseAll =
builtins.foldl'
(prev: name: prev // collapse name)
{}
(builtins.attrNames attrs);
in
# Preserve the original bindings as `original`.
(optionalAttrs (! attrs ? original)
{
original = attrs;
})
// (collapseRenamed "packages" "pkgs")
// (collapseRenamed "legacyPackages" "pkgs")
// collapseAll