As per the manual — 2.6 Declarative Package Management — I’m currently using packageOverrides in my ~/.config/nixpkgs/config.nix
.
In 3.2 Defining Overlays it says
Overlays are similar to other methods for customizing Nixpkgs, in particular the
packageOverrides
attribute described in Section 2.5, “Modify packages viapackageOverrides
”. Indeed,packageOverrides
acts as an overlay with only thesuper
argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute.
So I’m looking to migrate my packageOverrides to overlays (if that’s recommended?).
The challenge I’m facing (in doing so incrementally), is that the overlays don’t seem to take effect in a buildEnv
within packageOverrides
.
If I try to create these overlays for example, removing their definitions from packageOverrides they either fail to be found (in the case of markdown) or aren’t applied (in the case of emacs).
Any tips welcome. Thanks!
What I thought I could do…
#~/.config/nixpkgs/overlays/markdown.nix
self: super: {
markdown = super.emem.overrideAttrs (oldAttrs: rec {
installPhase = oldAttrs.installPhase + ''
ln -fs $out/bin/emem $out/bin/markdown
'';
});
}
and
#~/.config/nixpkgs/overlays/emacs.nix
self: super: {
emacs = super.callPackage ./nixpkgs/emacs { };
}
#~/.config/nixpkgs/overlays/nixpkgs/emacs/default.nix
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
myEmacsConfig = ./default.el;
in
emacsWithPackages (...);
What currently works using packageOverrides.
{
allowUnfree = true;
packageOverrides = pkgs: with pkgs; rec {
myProfile = pkgs.writeText "my-profile" ''
export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man
export IDEA_VM_OPTIONS=~/Library/Preferences/IntelliJIdea2019.3/idea.vmoptions
function idownload {
if [ "$#" -ne 1 ] || ! [ -e $1 ]; then
echo "Usage: idownload <file|dir>";
return 1;
fi
find . -name '.*icloud' |\
perl -pe 's|(.*)/.(.*).icloud|$1/$2|s' |\
while read file; do brctl download "$file"; done
}
'';
myPackages = buildEnv {
name = "my-packages";
paths = [
(runCommand "profile" {} ''
mkdir -p $out/etc/profile.d
cp ${myProfile} $out/etc/profile.d/my-profile.sh
‘')
...
emacs
markdown
...
];
pathsToLink = [ "/share/man" "/share/doc" "/bin" "/etc" "/Applications" ];
extraOutputsToInstall = [ "man" "doc" ];
};
markdown = emem.overrideAttrs (oldAttrs: rec {
installPhase = oldAttrs.installPhase + ''
ln -fs $out/bin/emem $out/bin/markdown
'';
});
#
# COMMENTING OUT BELOW WITH OVERLAYS IN PLACE FAILS
#
myEmacsConfig = ./overlays/pkgs/emacs/default.el;
emacs = emacsWithPackages (epkgs:
# CONFIG setup
[
(runCommand "default.el" {} ''
mkdir -p $out/share/emacs/site-lisp
cp ${myEmacsConfig} $out/share/emacs/site-lisp/default.el
'')
] ++
# ELPA packages
(with epkgs.elpaPackages; [
...
]) ++
(with epkgs.melpaPackages; [
...
]) ++
# MELPA stable packages
(with epkgs.melpaStablePackages; [
...
]));
};
}