[20.09] Unable to use overlay in containers

I’m trying to upgrade one of my personal NixOS servers where I run the services inside declarative containers. The containers use personal overlays located on the server.

After updating the nix-channel to 20.09-small, a nixos-rebuild test fails with the message:

# nixos-rebuild switch
building Nix...
building the system configuration...
error: attribute 'erp' missing, at /etc/nixos/containers/mission/default.nix:125:44
(use '--show-trace' to show detailed location information)

My setup worked fine from 17.09 through 20.03. I’m not sure what’s changed with overlays and containers, but it seems broken now. Hopefully, someone knows whether 20.09 introduced a different way to use overlays in containers and can enlighten me, as I didn’t see it mentioned in the 20.09 release notes.

I did find a PR that broke overlays in containers for 20.03, but that PR was reverted for 20.03 and appears to still be reverted in the 20.09 release.

Here’s my basic configuration:

# /etc/nixos/containers/erp-service/default.nix

{ config, pkgs, ... }:

with pkgs.lib;

  syscfg = config;

  # other vars ...
in {
  containers.mission = {
    autoStart = true;

    bindMounts = { ... };

    config = { config, pkgs, ... }: {
      networking.firewall.enable = false;
      services.httpd = {
        # httpd options here.

      nixpkgs.overlays = [ (import /etc/nixos/overlays/erp) ];
# /etc/nixos/overlays/erp/default.nix
self: super: { erp = super.callPackages ./pkgs {}; }

./pkgs/default.nix is just a package file, and I’ve established where the erp in the error message should originate from. If more details are needed, I can provide.

88621 [1] is the bug report I found before. The offending commit was found and reverted in the 20.03 branch, but not the master or unstable branches, so far as i could find. I decided to submit another revert PR for 20.09, but the revert failed, and I found little code in 20.09 that correlated with the offending commit.

And while citing sources for this post, I stumbled down a rabbit hole and found PR 98655 [2] addressing the very issue I’m having. Once that is applied, it seems some form of pkgs = null will enable overlays in containers for 20.09.

[1]: https://github.com/NixOS/nixpkgs/issues/88621
[2]: https://github.com/NixOS/nixpkgs/pull/98655

Yes, unfortunately, this bug is still unfixed.
@Ma27, @adisbladis, could you help merging the bugfix PR?

@boxofrox, the PR in its current state, including the fixup commit, restores the default behavior of 20.03/20.09, so you wouldn’t have to set pkgs = null.

1 Like

I’m pretty sure you want

self: super: { erp = self.callPackages ./pkgs {}; }

as super could be a package set without the previously overlays applied.

1 Like

My [limited] understanding is that self is a fix point of nixpkgs + all overlays combined (past and present with respect to current overlay, if that makes any sense), and that super is an accumulation of nixpkgs + only those overlays that were processed thus far (i.e. past).

I’ve never fully understood when it’s appropriate to use self, other than there’s a foot-gun of creating an infinite recursion with self, so I use super by default.

My (also limited) understanding from asking around on IRC is that you want self for all things except when you’re overriding/patching an existing derivation, in which case you’d do something like self.callPackage ./mypackage-patched.nix { inherit (super) mypackage; }.

(super is also appropriate for when Nix throws infinite recursion errors at you, as you pointed out.)

1 Like