nix-starter-configs
nix-starter-configs copied to clipboard
Can't make overlays working
Hi, thank you for your well made config 😁 But it's taking me time to comprehend how your config works 😅 Currently i'm struggling with the overlays (i'm not really familiar with them) My overlays look like:
# This file defines overlays
{ inputs, ... }: {
# This one brings our custom packages from the 'pkgs' directory
additions = final: _prev: import ../pkgs { pkgs = final; };
# This one contains whatever you want to overlay
# You can change versions, add patches, set compilation flags, anything really.
# https://nixos.wiki/wiki/Overlays
modifications = final: prev: {
# example = prev.example.overrideAttrs (oldAttrs: rec {
# ...
# });
wp4nix = import ./wp4nix.nix;
};
# When applied, the unstable nixpkgs set (declared in the flake inputs) will
# be accessible through 'pkgs.unstable'
unstable-packages = final: _prev: {
unstable = import inputs.nixpkgs-unstable {
system = final.system;
# config.allowUnfree = true;
};
};
}
and some of my uses are:
package = "pkgs.unstable.syncthing";
and:
{pkgs, libs, inputs, outputs, ...}:
{
nixpkgs.overlays = [
(final: super: {
nginxStable = super.nginxStable.override { openssl = super.pkgs.libressl; };
})
(self: super: {
wordpressPackages = pkgs.unstable.callPackage inputs.wp4nix { };
}
)
];
}
and in all the cases overlays don't seem to work so the syncthing is using 23.05, and wp4nix is not overlayed
there's probably something else i need to show here, but i'm not sure how the logic of your config works 😥
Hey!
There's no secret sauce to it, actually! Just plain ol' overlays in a separate file, which you can export to other people and/or use on your own config.
The included overlays are just examples, really. But, to actually use pkgs.unstable
, you gotta apply that unstable overlay (which you are not doing). This is probably the issue.
Second, using pkgs
inside an overlay is a no-no. This will almost def cause a infinite loop or something. You should only use the two arguments (super/prev
or self/final
). This should work:
{pkgs, libs, inputs, outputs, ...}:
{
nixpkgs.overlays = [
outputs.overlays.unstable-packages
(final: prev: {
nginxStable = prev.nginxStable.override { openssl = final.pkgs.libressl; };
})
(final: prev: {
wordpressPackages = final.unstable.callPackage inputs.wp4nix { };
})
];
}
Notice that overlays is an list, the order matters. Overlays are basically applied one after the other.
Also, It's not the easiest concept to grasp, but the first argument (in this example, final
) is pkgs
after that overlay is applied, and the second one (prev
) is pkgs
before the overlay is applied.
You usually always use final
, unless you're accessing something that overlay modified (for example, nginxStable
). In this case using final
or prev
does not matter much, but it's good practice.
This is what I'm doing to apply my own Neovim flake to my overlays in nixpkgs-unstable.
I'm new to Nix so I'm sticking with stable and had problems adding the flake to it, since it follows unstable.
Can this be considered a good practice?
overlays/default.nix
:
# This file defines overlays
{inputs, ...}: {
# This one brings our custom packages from the 'pkgs' directory
additions = final: _prev: import ../pkgs {pkgs = final;};
# This one contains whatever you want to overlay
# You can change versions, add patches, set compilation flags, anything really.
# https://nixos.wiki/wiki/Overlays
modifications = final: prev: {
# example = prev.example.overrideAttrs (oldAttrs: rec {
# ...
# });
};
# When applied, the unstable nixpkgs set (declared in the flake inputs) will
# be accessible through 'pkgs.unstable'
unstable-packages = final: _prev: {
unstable = import inputs.nixpkgs-unstable {
system = final.system;
config.allowUnfree = true;
overlays = [
inputs.neovim-flake.overlays.default
];
};
};
}