How to override the platform field of a derivation?

I’m trying to override the meta.platforms field of the vimv derivation on the nixos-unstable channel from platforms.linux to platforms.unix.

I have the following code in the let .. in block of my home.nix (I’m using home-manager):

  ...
  unstable = import <nixos-unstable> {
    config.allowUnfree = true;
    overlays = [
      (self: super: {
        vimv = super.vimv.override {
          meta.platforms = self.platforms.unix;
        };
      })
    ];
  };
  ...

and in my home.packages I have

home.packages = with pkgs; [
  ...
  unstable.vimv
  ...
];

Unfortunately when I try to home-manager switch I get the following error:

error: anonymous function at /nix/store/2nqpjn55jwb4zbwc8k0fwf32bmvk79q1-nixos-unstable-21.05pre273435.0aeba64fb26/nixos-unstable/pkgs/tools/misc/vimv/default.nix:1:1 called with unexpected argument 'meta', at /nix/store/2nqpjn55jwb4zbwc8k0fwf32bmvk79q1-nixos-unstable-21.05pre273435.0aeba64fb26/nixos-unstable/lib/customisation.nix:69:16
(use '--show-trace' to show detailed location information)

What am I doing wrong?

You need overrideAttrs, override is used to override arguments of the function that creates a derivation.

By the way, you do not need an overlay, you could do something like:

home.packages = with pkgs; [
  (vimv.overrideAttrs (_: {
    meta.platforms = super.lib.platforms.unix;
  }))
];

With

  unstable = import <nixos-unstable> {
    config.allowUnfree = true;
    overlays = [
      (self: super: {
        vimv = super.vimv.overrideAttrs (old: {
          meta.platforms = self.platforms.unix;
        });
      })
    ];
  };

I now get the error:

error: attribute 'unix' missing, at /Users/noibe/Sync/dotfiles/machines/mbair/home.nix:8:28
(use '--show-trace' to show detailed location information

The top-level platforms attribute is not what you want, but rather lib.platforms. If you use an overlay, e.g. super.lib.platforms.unix.

Note that this is the same as

(pkgs.vimv.overrideAttrs (_: {
  meta = {
    platforms = pkgs.lib.platforms.unix;
  };
}))

and as such, it will override the whole meta attribute (e.g. it will remove meta.homepage)

It might not matter to you when installing the package but it is a good idea to avoid the incorrect approach and merge the overridden value into the old meta:

(pkgs.vimv.overrideAttrs (attrs: {
  meta = attrs.meta or {} // {
    platforms = pkgs.lib.platforms.unix;
  };
}))

You can also use default arguments, which is my preferred strategy:

(pkgs.vimv.overrideAttrs ({ meta ? {}, ... }: {
  meta = meta // {
    platforms = pkgs.lib.platforms.unix;
  };
}))
2 Likes