Skip to content

lib/strings: Add makeIncludePath#296237

Merged
infinisil merged 12 commits intoNixOS:masterfrom
mrdev023:patch-1
Apr 2, 2024
Merged

lib/strings: Add makeIncludePath#296237
infinisil merged 12 commits intoNixOS:masterfrom
mrdev023:patch-1

Conversation

@mrdev023
Copy link
Contributor

Description of changes

Add makeIncludePath, it can be usefull to add wrapProgram with C_INCLUDE_PATH

libraryPath = pkgs.lib.makeLibraryPath (libs);
makeIncludePath = pkgs.lib.makeSearchPathOutput "dev" "include";
includePath = makeIncludePath (libs);

wrappedRuby = (pkgs.symlinkJoin {
  name = "ruby";
  paths = [ ruby ];
  nativeBuildInputs = [ pkgs.makeWrapper ];
  postBuild = ''
    wrapProgram $out/bin/ruby \
      --set LD_LIBRARY_PATH ${libraryPath}
    wrapProgram $out/bin/bundle \
      --set LD_LIBRARY_PATH ${libraryPath} \
      --set LIBRARY_PATH ${libraryPath} \
      --set C_INCLUDE_PATH ${includePath}
  '';
});
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@mrdev023 mrdev023 requested a review from infinisil as a code owner March 15, 2024 19:26
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Mar 15, 2024
@NixOSInfra NixOSInfra added the 12.first-time contribution This PR is the author's first one; please be gentle! label Mar 15, 2024
@mrdev023
Copy link
Contributor Author

Result of nixpkgs-review pr 296237 run on x86_64-linux 1

1 package blacklisted:
  • nixos-install-tools

@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Mar 15, 2024
@lolbinarycat
Copy link
Contributor

i think C_INCLUDE_PATH should be automatically setup by stdenv, but i suppose it could be useful to have more precise control, especially when working with programs that parse c headers at runtime for ffi.

@mrdev023
Copy link
Contributor Author

i think C_INCLUDE_PATH should be automatically setup by stdenv, but i suppose it could be useful to have more precise control, especially when working with programs that parse c headers at runtime for ffi.

the ffi gem seems to manage headers and libs loading itself

@lolbinarycat
Copy link
Contributor

parsing C headers is fairly common for ffi in dynamic languages.

Copy link
Contributor

@lolbinarycat lolbinarycat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a trivial function with adequate usecases, i don't see a reason to oppose this.

there are a few tweaks to the documentation i would suggest, however.

mrdev023 and others added 2 commits March 19, 2024 22:16
Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>
Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>
@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Mar 20, 2024
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me, but it's unfortunate that all makeSearchPath functions are entirely untested, and I'd rather not merge new untested code (also in the new lib contribution guidelines).

So could you write some tests for these functions? lib/tests/misc.nix should work here

@mrdev023
Copy link
Contributor Author

It looks good to me, but it's unfortunate that all makeSearchPath functions are entirely untested, and I'd rather not merge new untested code (also in the new lib contribution guidelines).

So could you write some tests for these functions? lib/tests/misc.nix should work here

I add it soon as possible, i didn't know where to put the tests ^^

@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one person. label Mar 26, 2024
@mrdev023
Copy link
Contributor Author

It looks good to me, but it's unfortunate that all makeSearchPath functions are entirely untested, and I'd rather not merge new untested code (also in the new lib contribution guidelines).

So could you write some tests for these functions? lib/tests/misc.nix should work here

I add unit test for strings but i don't know how to test with pkgs arguments

@mrdev023 mrdev023 requested a review from infinisil March 26, 2024 18:14
@mrdev023 mrdev023 requested a review from lolbinarycat March 26, 2024 18:41
@lolbinarycat
Copy link
Contributor

maybe you could add pkgs = import ../.. {}; to the let expression at the top of the file? that seems to be how other testing files do it. then you can just interpolate the package outPath into the expected string, like "${pkgs.openssl.dev.outPath}/include or whatever.

@mrdev023
Copy link
Contributor Author

maybe you could add pkgs = import ../.. {}; to the let expression at the top of the file? that seems to be how other testing files do it. then you can just interpolate the package outPath into the expected string, like "${pkgs.openssl.dev.outPath}/include or whatever.

I made requested changes. Would you like me to test makeLibraryPath and makeBinPath too?

@mrdev023
Copy link
Contributor Author

Strange ofborg-eval not like my commit fb1850c

but nix-instantiate --eval --strict lib/tests/misc.nix return empty list

Copy link
Contributor

@lolbinarycat lolbinarycat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, the CI failure is strange, maybe it would be best to go back to using fake derivations instead of real ones.

@mrdev023
Copy link
Contributor Author

hmm, the CI failure is strange, maybe it would be best to go back to using fake derivations instead of real ones.

done.

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. and removed 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. labels Mar 26, 2024
@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Mar 26, 2024
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, the CI failure is strange, maybe it would be best to go back to using fake derivations instead of real ones.

The CI failure was caused by master being broken, it was not related, see #274481 (comment). But yeah using fake derivations here sounds fine.

It would be great to test it a bit more thoroughly though, getOutput is non-trivial:

nixpkgs/lib/attrsets.nix

Lines 1762 to 1765 in 2d96747

getOutput = output: pkg:
if ! pkg ? outputSpecified || ! pkg.outputSpecified
then pkg.${output} or pkg.out or pkg
else pkg;

Co-authored-by: Silvan Mosberger <github@infinisil.com>
@mrdev023 mrdev023 requested a review from infinisil March 27, 2024 09:02
@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one person. label Mar 27, 2024
@mrdev023
Copy link
Contributor Author

hmm, the CI failure is strange, maybe it would be best to go back to using fake derivations instead of real ones.

The CI failure was caused by master being broken, it was not related, see #274481 (comment). But yeah using fake derivations here sounds fine.

It would be great to test it a bit more thoroughly though, getOutput is non-trivial:

nixpkgs/lib/attrsets.nix

Lines 1762 to 1765 in 2d96747

getOutput = output: pkg:
if ! pkg ? outputSpecified || ! pkg.outputSpecified
then pkg.${output} or pkg.out or pkg
else pkg;

Should I also test getOutput?

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me now!

Feel free to make further PRs to add more tests, I definitely won't complain about that :P

@infinisil infinisil merged commit 3b883d3 into NixOS:master Apr 2, 2024
@mrdev023 mrdev023 deleted the patch-1 branch April 3, 2024 14:43
@mrdev023
Copy link
Contributor Author

mrdev023 commented Apr 3, 2024

Looking good to me now!

Feel free to make further PRs to add more tests, I definitely won't complain about that :P

Yes, as soon as I have time, I'll add some unit tests ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments