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

Can I extend nixpkgs.lib or builtins with my own library function? #28

Closed
con-f-use opened this issue May 26, 2023 · 2 comments
Closed

Comments

@con-f-use
Copy link

con-f-use commented May 26, 2023

Say I had a custom fetcher, that I wanted to use everywhere in a flake:

  fetchPrivatePyPi= url: builtins.fetchurl (
    let
      components = builtins.match "(.*)#sha256=([a-fA-F0-9]+).*" url;
    in {
      url = "http://my-custom-pypi.org/company/" + builtins.head components;
      hash = "sha256:" + lib.last components;
    }
  );

How would I make that similarly accessible as builtins.fetchurl?

I mean, sure, I could just import a file or use an overlay or whatever, like an animal. But maybe there's a way to extend built-ins or a way to specify a "global library" for use inside a flake. There's a kinda related nixpkgs issue that Silvan already participated in.

@con-f-use
Copy link
Author

con-f-use commented Jun 7, 2023

Covered in Nix Hour #32 - nix plugins & extending lib and builtins

@infinisil, you forgot to push the files with the various solutions to ./32/. I remember you cleaning them up in the after hour chat - would be a shame if that work went unappreciated 😉 .

@infinisil
Copy link
Member

@con-f-use Oh yeah forgot to push it! Here it is: https://github.com/tweag/nix-hour/tree/master/32 😄

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

No branches or pull requests

2 participants