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

how to deal with string contexts #74

Open
MangoIV opened this issue Feb 27, 2024 · 8 comments
Open

how to deal with string contexts #74

MangoIV opened this issue Feb 27, 2024 · 8 comments

Comments

@MangoIV
Copy link

MangoIV commented Feb 27, 2024

the issue is as follows:

  • for the build time dependencies we want to look up meta/ pname/ ... to find information about our packages
  • for this we must be at the nix level, i.e. with access to the attrset that mkDerivation builds
  • at this point we know the drvPath so we can query the dependencies
  • these dependencies don't necessarily have to be available in the nix level, reason: string contexts; simple example:
pkgs.callPackage ./buildtime-dependencies.nix {} (
  pkgs.runCommand "foo" {} ''cp -r ${pkgs.hello}/bin $out''
)

this package clearly depends on pkgs.hello but bombon doesn't recognize that.

I have not found a solution but a very sad one:

  • build meta for all of the packages that might be included; the user would pass a list of package sets and dependencies to build a meta "database" keyed by the drvPath of the derivation
  • build the dependency tree of some package separately
  • query the "database" against the drvPaths.
@nikstur
Copy link
Owner

nikstur commented Mar 25, 2024

That's a very good observation, thank you! I don't have a clear answer yet how I can/want to solve this.

@arianvp
Copy link

arianvp commented Sep 26, 2024

We need NixOS/nix#4677

@MangoIV
Copy link
Author

MangoIV commented Sep 26, 2024

@MangoIV
Copy link
Author

MangoIV commented Sep 26, 2024

It goes what I described above though.

@arianvp
Copy link

arianvp commented Sep 26, 2024

because pkgs is actually not a tree but a graph so you

will go around in circle

You could use https://nix.dev/manual/nix/2.18/language/builtins#builtins-genericClosure for this

@MangoIV
Copy link
Author

MangoIV commented Sep 26, 2024

That’s not the only problem though. Nix will also memory leak like crazy. So probably not going to work anyway. You need to be careful what to recurse on. I think I also excluded a couple of attrsets to not look at.

@sternenseemann
Copy link

In Nix >= 2.6 you can use the following code to correctly and reliably determine the dependency closure of a derivation (in Nix < 2.6 you have to parse the drv files yourself which is perfectly possible):

drv:
builtins.map (builtins.getAttr "key") 
  builtins.genericClosure {
    startSet = [ { key = builtins.unsafeDiscardStringContext "${drv.drvPath}"; } ];
    operator = { key }: builtins.map (drvPath: { key = drvPath; }) (
      builtins.attrNames (builtins.getContext (builtins.readFile key))
    );
  }
)

Obviously you are left with the problem that the serialized derivation files are lossy and lack e.g. meta. This is an inherent problem with string context. OTOH this code needs to make no assumptions about how the derivations work or are structured.

@arianvp
Copy link

arianvp commented Nov 21, 2024

Came up with something very similar. But adds a fixup phase that tried to reconstruct string-context deps if they happen to match non-string-context deps

https://gist.github.com/arianvp/e96acf85734ebe7a58bf24d4758484eb

As a last resort we can at least guess the version and pname by doing string parsing on the drv path and show a warning that the drv is unknown.

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

4 participants