Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildYarnPackage: Add support for packageOverrides #28

Merged
merged 1 commit into from
Jun 22, 2021

Conversation

aszlig
Copy link
Contributor

@aszlig aszlig commented Dec 10, 2020

Disclaimer: The branch is mainly for me to have a somewhat "stable" Flake URL, feel free to close this pull request if it's not wanted or if the way I've done it doesn't suit your or the project's goals.

This is similar to b5cd694, which added the attribute to mkNodeModule and buildNpmPackage but didn't do it for the buildYarnPackage flavour.

However, we're using lib.extends instead of a plain attribute set, since we want to tread the original package set as a fixed point to be composable with multiple levels of overrides, similar to how it's done with nixpkgs overlays.

In my case it's to quickly override a dependency fetched from GitHub, eg. like this:

let
  mydep = "https://github.com/someowner/somerepo.git";

  newMydep = pkgs.fetchFromGitHub {
    owner = "someowner";
    repo = "somerepo";
    rev = "...";
    sha256 = "...";
    fetchSubmodules = true;
    leaveDotGit = true;
  };

in buildYarnPackage {
  # ...
  nativeBuildInputs = lib.singleton (pkgs.writeScriptBin "git" ''
    #!${pkgs.python3.interpreter}
    import sys, os
    for n, arg in enumerate(sys.argv):
      if arg == '${mydep}':
        sys.argv[n] = '${newMydep}'
    os.execv('${pkgs.git}/bin/git', sys.argv)
  '');
  packageOverrides = lib.singleton (self: super: {
    ${mydep} = super.${mydep} // { path = "dummy"; };
  });
  # ...
}

I know that the way I've done the above is probably winning the first price for "the ugliest override" but since I'm not particularly invested in anything related to node.js, I'm usually pretty cruel when it comes to it.

So the above example is just to have a complete almost-real-world example for reference and in this case it's to work around #7.

This is similar to b5cd694, which added
the attribute to mkNodeModule and buildNpmPackage but didn't do it for
the buildYarnPackage flavour.

However, we're using lib.extends instead of a plain attribute set, since
we want to tread the original package set as a fixed point to be
compasable with multiple levels of overrides, similar to how it's done
with nixpkgs overlays.

In my case it's to quickly override a dependency fetched from GitHub,
eg. like this:

  let
    mydep = "https://github.com/someowner/somerepo.git";

    newMydep = pkgs.fetchFromGitHub {
      owner = "someowner";
      repo = "somerepo";
      rev = "...";
      sha256 = "...";
      fetchSubmodules = true;
      leaveDotGit = true;
    };

  in buildYarnPackage {
    # ...
    nativeBuildInputs = lib.singleton (pkgs.writeScriptBin "git" ''
      #!${pkgs.python3.interpreter}
      import sys, os
      for n, arg in enumerate(sys.argv):
        if arg == '${mydep}':
          sys.argv[n] = '${newMydep}'
      os.execv('${pkgs.git}/bin/git', sys.argv)
    '');
    packageOverrides = lib.singleton (self: super: {
      ${mydep} = super.${mydep} // { path = "dummy"; };
    });
    # ...
  }

I know that the way I've done the above is probably winning the first
price for "the ugliest override" but since I'm not particularly invested
in anything related to node.js, I'm usually pretty cruel when it comes
to it.

So the above example is just to have a complete almost-real-world
example for reference and in this case it's to work around serokell#7.

Signed-off-by: aszlig <[email protected]>
@yorickvP yorickvP merged commit 3461855 into serokell:master Jun 22, 2021
@yorickvP
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants