Global overlay not being applied

I’m trying to gain a better understanding of NixOS and am working on removing unneeded dependencies. For example, fzf has perl as a dependency and when i enable printing, samba is installed. I want to get rid of both dependencies.

So i read through the wiki, the NixOS options and some articles on discourse about overlays. It is my understanding that i don’t need “old:” because i only want to remove things. I don’t know when “rec” is necessary.

This is what i came up with in my configuration.nix (i tried both “null” and “” to assign an empty value):

{
  config,
  pkgs,
  lib,
  ...
}: {
  imports = [
    ./hardware-configuration.nix
    ./hardening.nix
  ];
  nixpkgs = {
    config = {
      packageOverrides = pkgs: {
        unstable = import <nixos-unstable> {config = config.nixpkgs.config;};
      };
    };
    overlays = [
      (final: prev: {
        cupsd = prev.cupsd.overrideAttrs {additionalBackends = "";}; 
        })
      (final: prev: {
        fzf = prev.fzf.overrideAttrs {ourPerl = null;};
        })
    ];
  };
 ...

Running sudo nixos-rebuild shows no error but doesn’t change anything.

Also, i succeeded in making the following override:

      environment.systemPackages = with pkgs; [
      (easyeffects.overrideAttrs
      {
        preFixup = let
          lv2Plugins = [
            calf # compressor exciter, bass enhancer and others
            zam-plugins # maximizer
          ];
        in ''
          gappsWrapperArgs+=(
          --set LV2_PATH "${lib.makeSearchPath "lib/lv2" lv2Plugins}"
          )
        '';
      })
      ];

I then tried to convert that to a global overlay by doing the following:

...
    overlays = [
      (final: prev: {
      easyeffects = prev.easyeffects.overrideAttrs
      {
        preFixup = let
          lv2Plugins = [
            calf # compressor exciter, bass enhancer and others
            zam-plugins # maximizer
          ];
        in ''
          gappsWrapperArgs+=(
          --set LV2_PATH "${lib.makeSearchPath "lib/lv2" lv2Plugins}"
          )
        '';
      }
      ];
      })
...

but if i do that, NixOS complains with “undefined variable calf” and it will also complain for zam-plugins. If i put that part into ‘’ ‘’ like the gappsWrapperArgs, then NixOS doesn’t complain anymore but also removes calf and zam-plugins as it obviously disregards them in this case.

Obviously i don’t understand fundamental parts of how overlays work but the examples in the wiki don’t seem to help me.

How can i achieve what i want?

This looks about right at first glance. You’d have to look into how the printing module pulls in the cupsd package.

You had a with pkgs; before but didn’t take that over with the other code.

That’s why widely-scoped with;-statements are considered an anti-pattern.

That’d also be kind of wrong. You’d want those packages from final or prev, not pkgs though I guess pkgs might be equivalent to final in this context?

Either use final.calf or use a locally-scoped with; (i.e. lv2Plugins = with final; [ ... ];).

1 Like

Thanks! I didn’t think of that, it’s working now. :slightly_smiling_face:

For fzf i didn’t realize the real reference to perl but now i’ve got it:

      (final: prev: {
        fzf = prev.fzf.overrideAttrs {
          ourPerl = null;
          postPatch = null;
        };
      })

I only now realized how many programs depend on perl so this was rather futile but good exercise…

No luck with cupsd however. I now have

 (final: prev: {
        cupsd = prev.cupsd.overrideAttrs {
          additionalBackends = null;
          bindir = pkgs.buildEnv {
            name = "cups-progs";
            paths = with final;
              [cups.out cups-filters pkgs.ghostscript]
              ++ cfg.drivers;
            pathsToLink = ["/lib" "/share/cups" "/bin"];
            postBuild = final.cfg.bindirCmds;
            ignoreCollisions = true;
          };
        };
      })

but NixOS still doesn’t change anything when rebuilding and i see no other reference to samba. If i understand it correctly, then samba is not part of cups/default.nix but only added in printing/cupsd.nix under additionalBackends (the part that i’m trying to overlay).

I guess i have to overlay a different package, but i haven’t found it yet (overlaying cups maybe, but so far no luck).

I had a quick look and it’s indeed the module adding samba.

From the services.printing.drivers option description:

CUPS drivers to use. Drivers provided by CUPS, cups-filters,
Ghostscript and Samba are added unconditionally. If this list contains
Gutenprint (i.e. a derivation with
meta.isGutenprint = true) the PPD files in
{file}/var/lib/cups/ppd will be updated automatically
to avoid errors due to incompatible versions.

(emphasis mine)

So, you’re working against the module then. Whenever you’re doing that, it’s almost always better to make the upstream module more modular instead; in this case making samba optional.

What you could do without changing the module definition itself in this case is setting services.printing.bindirCmds to remove lib/cups/backend/smb/. That should get rid of the runtime dependency on samba by the module though the build-time dependency will remain.

I’m also doubtful you’ll be able to strip samba out of your closure this way because I don’t think cups is the only dependant.

Your attempts at overriding the cupsd package did not make sense as the package does not have those attributes. Those attribute names you tried to override are just let-bound constants’ names inside the module declaration. You cannot override them using overrideAttrs . That function only overrides arguments to the mkDerivation function. Don’t confuse modules and derivations; the cupsd derivation is unrelated to the printing module (other than that the printing module uses the cupsd package internally).

1 Like

Alright, thank you for your explanations!

I see that i’m in too deep right now as i wouldn’t know how to change a module etc. It’s no problem though because i was just wondering how to do it in order to learn it and not because i have to solve a problem with my system.