Override systemPackages dependencies

In my NixOS configuration.nix I have Gnome NetworkManager L2TP.

Gnome NetworkManager L2TP depends on StrongSwan. I want to override the StrongSwan derivation, and have Gnome NetworkManager L2TP use the overridden derivation. How do I do that? Something like this? This doesn’t seem to be working.

Reference: Overlays - NixOS Wiki

environment.systemPackages = with pkgs; [
    gnome.networkmanager-l2tp
];


nixpkgs.overlays = [
 (self: super: {
   strongswan = super.strongswan.overrideAttrs (old: rec {
     postInstall = ''
     # this is needed for l2tp
     echo "include /etc/ipsec.d/*.secrets" >> $out/etc/ipsec.secrets
     '';
   });
 }) 
 ];

What you’re trying should work. Though it’s probably not advisable to override strongswan globally as that might results in lots of unnecessary rebuilds of packages other than l2tp.

I’d rather do

environment.systemPackages = with pkgs; [
  (gnome.networkmanager-l2tp.override {
    strongswan = pkgs.strongswan.overrideAttrs (old: {
      postInstall = ''
        # this is needed for l2tp
        echo "include /etc/ipsec.d/*.secrets" >> $out/etc/ipsec.secrets
      '';
    });
  })
];

Because this way, only gnome.networkmanager-l2tp depends on the overridden strongswan.

(Untested. You could also override gnome.networkmanager-l2tp in overlays the same way.)

If this is something all gnome.networkmanager-l2tp would benefit from, please bring the patch upstream into Nixpkgs!

1 Like

Thanks @Atemu , I’ll try it that way.

Yes, I’ll make a PR if this works.

I suspect that what’s happening here is that gnome.networkManager-l2tp is already overriding strongswan, so my own overrides to strongswan don’t get applied.

Similar to nixos - nixpkgs.overlays and nixpkgs.config.packageOverrides not being reflected in environment.systemPackages - Stack Overflow

It looks like my overlay is applied to systemPackages.

$ nix repl '<nixpkgs/nixos>'

nix-repl> pkgs.strongswan.postInstall
"# this is needed for l2tp\necho \"include /etc/ipsec.d/*.secrets\" >> $out/etc/ipsec.secrets\n"