Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
self: super:
{
# Install overlay:
# $ mkdir -p ~/.config/nixpkgs/overlays
# $ curl https://gist.githubusercontent.com/LnL7/570349866bb69467d0caf5cb175faa74/raw/3f3d53fe8e8713ee321ee894ecf76edbcb0b3711/lnl-overlay.nix -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" ''
#!${super.stdenv.shell}
if ! command -v nix-env &>/dev/null; then
echo "warning: nix-env was not found in PATH, add nix to userPackages" >&2
PATH=${self.nix}/bin:$PATH
fi
exec nix-env -f '<nixpkgs>' -r -iA userPackages "$@"
'';
};
}
@efx

This comment has been minimized.

Copy link

commented Oct 13, 2017

on macOS, if you haven't installed overlays before, you need to create the directory:

$ mkdir -p ~/.config/nixpkgs/overlays
@grahamc

This comment has been minimized.

Copy link

commented May 23, 2018

Aftr adding this overlay, run:

nix-env -f '<nixpkgs>' -r -iA userPackages

and from then on you edit this file and run nix-rebuild.

@jcrben

This comment has been minimized.

Copy link

commented Jul 23, 2018

UPDATE: looks like userPackages isn't showing up in a search but other overlay packages are - I tried giving it a name but that didn't fix it. Guess it's missing some attributes.

Is it expected that this will show up in a search? Been fiddling around for a while trying to get it (mentioned more at NixOS/nixpkgs#43266 (comment)).

@LnL7

This comment has been minimized.

Copy link
Owner Author

commented Aug 11, 2018

Use super.userPackages or {} // super.recurseIntoAttrs { ... } to expose these when searching packages, etc.

@jabranham

This comment has been minimized.

Copy link

commented Dec 11, 2018

This doesn't seem to make info manuals of those programs available.

@lilyball

This comment has been minimized.

Copy link

commented May 31, 2019

I tweaked this to print out the difference in packages on every rebuild:

self: super:

{
  userPackages = super.userPackages or {} // {
    # My packages
    inherit (self) hello;
    # add more packages here...

    # Default packages
    inherit (self)
      cacert
      nix; # don't enable nix on multi-user
    
    nix-rebuild = super.writeScriptBin "nix-rebuild" ''
      #!${super.stdenv.shell}
      set -e
      if ! command -v nix-env &>/dev/null; then
        echo "warning: nix-env was not found in PATH, add nix to userPackages" >&2
        PATH=${self.nix}/bin:$PATH
      fi
      IFS=- read -r _ oldGen _ <<<"$(readlink "$(readlink ~/.nix-profile)")"
      oldVersions=$(readlink ~/.nix-profile/package_versions || echo "/dev/null")
      nix-env -f '<nixpkgs>' -r -iA userPackages "$@"
      IFS=- read -r _ newGen _ <<<"$(readlink "$(readlink ~/.nix-profile)")"
      ${self.diffutils}/bin/diff --color -u --label "generation $oldGen" $oldVersions \
        --label "generation $newGen" ~/.nix-profile/package_versions \
        || true
    '';

    packageVersions =
      let
        versions = super.lib.attrsets.mapAttrsToList (_: pkg: pkg.name) self.userPackages;
        versionText = super.lib.strings.concatMapStrings (s: s+"\n") versions;
      in
      super.writeTextDir "package_versions" versionText;
  };
}

This dumps all the user packages into a file ~/.nix-profile/package_versions and then diffs this across the install. The output looks like

--- generation 68
+++ generation 69
@@ -33,6 +33,7 @@
 rlwrap-0.43
 ShellCheck-0.6.0
 taskwarrior-2.5.1
+tig-2.4.1
 tmux-2.9a
 unison-2.51.2
 vit-1.3
@steshaw

This comment has been minimized.

Copy link

commented Jun 12, 2019

Nice, @lilyball 😄

@lilyball

This comment has been minimized.

Copy link

commented Jun 12, 2019

I just updated my comment because I realized that the diff command was exiting with status code 1 when there's a difference. The update just tacks on || true so the whole rebuild doesn't exit with status code 1.

@steshaw

This comment has been minimized.

Copy link

commented Jun 12, 2019

Thanks again, @lilyball. I should have noticed:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.