Skip to content

Instantly share code, notes, and snippets.

Last active January 15, 2024 18:17
Show Gist options
  • Save LnL7/570349866bb69467d0caf5cb175faa74 to your computer and use it in GitHub Desktop.
Save LnL7/570349866bb69467d0caf5cb175faa74 to your computer and use it in GitHub Desktop.
self: super:
# Install overlay:
# $ mkdir -p ~/.config/nixpkgs/overlays
# $ curl -o ~/.config/nixpkgs/overlays/lnl.nix
userPackages = super.userPackages or {} // {
# Example:
hello = self.hello;
# add more packages here...
# Default packages:
# cacert = self.cacert;
# nix = self.nix; # don't enable this on multi-user.
nix-rebuild = super.writeScriptBin "nix-rebuild" ''
if ! command -v nix-env &>/dev/null; then
echo "warning: nix-env was not found in PATH, add nix to userPackages" >&2
exec nix-env -f '<nixpkgs>' -r -iA userPackages "$@"
Copy link

@lilyball Thanks a lot, that's something I'd have figured out by myself about a few decades later 😁

Copy link

untoreh commented Mar 15, 2021

does this need to be setup for every channel?

Copy link

@lilyball thanks for sharing that, looks great. I'm getting an infinite recursion error when trying to use your 2020 version (The older one works fine).

nix-env -f '' -r -iA userPackages
error: infinite recursion encountered, at /home/user/.config/nixpkgs/overlays/packages.nix:4:17

Any idea what could be causing this?

Copy link

@Amir-Ahmad What does your packages.nix look like?

Copy link

Amir-Ahmad commented Nov 11, 2021

@lilyball I was trying with this, copied from your comment

self: super:
# Packages exposed as part of nixpkgs.userPackages
  inherit (self)
    fish tmux
    # …

Copy link

lilyball commented Nov 11, 2021

@Amir-Ahmad Oh I think you probably put this in ~/.config/nixpkgs/overlays/ directly, yes? I suppose I should have elaborated. Your directory structure should look like


The nested folder name (userPackages above) doesn't matter, but the two files do need to be nested in a folder, and the main file is default.nix in this folder.

What this does is it makes userPackages/default.nix to be the actual overlay, and that in turn imports ./packages.nix to construct the userPackages set. By putting both files in the top level overlays folder you instead make them two separate overlays and the packages.nix file is then trying to overwrite each package with itself, which causes infinite recursion.

Copy link

@lilyball It's working now! thanks for the explanation 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment