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.
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.
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.