I don't understand how to use overrides

Hi,

I just read this doc and the Nix Pill about override design pattern and I want to try to use this to personalize a package, however I can’t find the good syntax to do that.

I want to personalize the chromium package, in order to modify the google api key used and add other gn flags to modify the build.
After reading this, I think I can achieve that by appending things to the gnFlags attribute but no matter what syntax I try, it does not want to evaluate.

Here is the last thing I wrote:

let
  mychromium = pkgs.chromium.override (prev: { gnFlags = prev.genFlags // {
    google_api_key = "some-key";
    google_default_client_id = "some-id";
    google_default_client_secret = "some-secret";
  }; });

in
{
  imports = [
     # Removed for clarity, irrelevant
  ];

  home.packages = with pkgs; [
    # Web
    mychromium
  ];
}

I also thought I could use the overrideAttrs thing but as the gnFlags attribute is inside a ‘base’ attribute, I fear I would need to redeclare the whole base attribute, wich seems way to complicated to modify a simple set.

Thank’s for help,
JM445

base is just part of the attribute set passed to stdenv.mkDerivation, so overrideAttrs should work.

overrideAttrs overriding the attribute set passed to a stdenv.mkDerivation call, and you don’t really need to care about any temporary variables used in the middle, such as base.

Still not able to evaluate…

I tried:

  mychromium = pkgs.chromium.overrideAttrs  (oldAttrs: {
    base = oldAttrs.base // {
      gnFlags = {
        google_api_key = "...";
        google_default_client_id = "...";
        google_default_client_secret = "...";
      };
    };
  });

This tells me ‘base’ attribute is missing.
I also tried that:

mychromium = pkgs.chromium.overrideAttrs  (oldAttrs: {
      gnFlags = oldAttrs.gnFlags // {
        google_api_key = "...";
        google_default_client_id = "...";
        google_default_client_secret = "...";
      };
  });

But same result with ‘gnFlags’ missing…

pkgs.chromium is defined here:

which is just a wrapper, not common.nix:

common.nix is used in the wrapper’s passthru, so you can access it via some code like:

pkgs.chromium.mkDerivation (base: {
  name = "my-chromium";
  gnFlags = { test_flag = 42; };
})

brower.nix is also referenced in passthru, so you can used something like this either:

pkgs.chromium.browser.overrideAttrs ...

Here is the docs for passthru:

In fact, nixos.wiki already have examples for this, you do not have to dive into those details if you just want to have things done:

https://nixos.wiki/wiki/Chromium#Overriding_Chromium

2 Likes

Hi,

This seems like exactly what I was searching for, but I can’t get it to work.
If I use the pkgs.chromium.mkDerivation function, the package won’t build anymore, even if I only change the name of the package.

Example:

let
    myChromium = pkgs.chromium.mkDerivation (base: {
        name = "my-chromium";
    });
in
{
    home.packages = with pkgs; [
        myChromium
    ];
}

On rebuild, I then get a ninja error “ninja.build: no such file or directory” during installPhase…

Anyway, I have not been able to find a solution to build chromium with different flags.
However I found a simple workaround for my case: API keys can be passed through environment variables.

1 Like