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

NixOS/nixpkgs?dir=lib #10

Closed
dezren39 opened this issue Aug 23, 2023 · 6 comments
Closed

NixOS/nixpkgs?dir=lib #10

dezren39 opened this issue Aug 23, 2023 · 6 comments

Comments

@dezren39
Copy link

dezren39 commented Aug 23, 2023

idk where flakehub exists but i was wondering about something so im just gonna try here.

at some point subflakes i use had dependencies on nixpkg-lib and so to sync all the nixpkg reducing lock file,

i added a git flake to the same nixpkg i use but with lib subdir.

maybe that's not the right way to do it. i'm still adapting to nix.

if i wanted to use flakehub, i don't think that would work.

i looked in the documentation and the dir option seems to be git specific.

i notice that the documentation only mentions the dir flag for git but i'm using it for github.

maybe it already works for tarballs? i should have just tried it?

or maybe what i'm doing with github provider is already wrong,
but i copied someone else's code so i'm unsure.

does it make send to make a nixpkgs-lib tar and distribute that as well?

    nixpkgs.url = "github:NixOS/nixpkgs";
    nixpkgs-lib = {
      url = "github:NixOS/nixpkgs?dir=lib";
    };
# and then setup follows for each of these where used in sub-flakes.

maybe i need to restructure something like this? https://zimbatm.com/notes/1000-instances-of-nixpkgs
or there is some magic like using git+file here? NixOS/nix#3978 (comment)

@Lord-Valen
Copy link

  nixpkgs.url = "github:NixOS/nixpkgs";
  nixpkgs-lib = {
    url = "github:NixOS/nixpkgs?dir=lib";
  };

I don't see why anyone should do this when they can simply access inputs.nixpkgs.lib.

@dezren39
Copy link
Author

how do i set a dependent flake to use that? can i say follows "nixpkgs.lib"?

@Lord-Valen
Copy link

Lord-Valen commented Aug 25, 2023

You shouldn't really need a follows. lib is an output of nixpkgs, so you can just access it directly.

{
	inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz"; # nixpkgs-unstable
	outputs = { nixpkgs, ... }: let
		inherit (nixpkgs) lib;
		list1 = ["a" "b"];
		list2 = ["c"];
    in {
		foo = lib.concatLists [list1 list2]; # ["a" "b" "c"]
	};
}

@dezren39
Copy link
Author

dezren39 commented Aug 27, 2023

I guess what I mean is, I understand that. I don't intend to do that in my own flake, but I have a flake I want to use. How do I ensure that this flake, when referenced in my flake, gets the same nixpkgs lib as the one I use?

https://github.com/hercules-ci/flake-parts/blob/main/flake.nix

{
  description = "Flake basics described using the module system";

  inputs = {
    nixpkgs-lib.url = "github:NixOS/nixpkgs/nixos-unstable?dir=lib";
  };
<...>
}

and in my flake

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    nixpkgs-lib.url = "github:NixOS/nixpkgs?dir=lib";
<...>
    flake-parts = {
      url = "github:hercules-ci/flake-parts";
      inputs.nixpkgs-lib.follows = "nixpkgs-lib";
    };
<...>
}

I'm happy to offer a PR upstream if that's best? I don't know the exact reasoning to target the lib flake in flake-parts.

@Lord-Valen
Copy link

Ah. If you look, flake-parts only accesses nixpkgs-lib.lib (which is, in fact, the only output) which will be the same as nixpkgs.lib. So I would just have nixpkgs-lib follow nixpkgs or nixpkgs-lib, if you're already using it. The motivation is probably to reduce size and avoid 1000 nixpkgs.

@dezren39
Copy link
Author

thank you! i did not understand that I could pass nixpkgs to nixpkgs-lib. I guess I understand how this works, it surprised me though. I will try to look closer at how the deps get used next time and try to decipher. Switching to flakehub soon. :-)

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