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

lua: allow static build #75901

Closed
wants to merge 1 commit into from
Closed

lua: allow static build #75901

wants to merge 1 commit into from

Conversation

malbarbo
Copy link
Contributor

Motivation for this change

This is a step forward to allow static building pandoc.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @nh2

@malbarbo
Copy link
Contributor Author

Can someone help me avoid mass rebuild?

@lovesegfault
Copy link
Member

@malbarbo I don't think you can avoid it, you should just target staging instead of master.

@nh2
Copy link
Contributor

nh2 commented Dec 19, 2019

Can someone help me avoid mass rebuild?

The problem is that with inherit enableShared; in the derivation you add it to the environment variables. nix-diff can show it (called on the .drv files between your commits and the previous):

% nix-diff /nix/store/gh1il6ggfznnars706xpd4x4zs65ldnq-lua-5.2.4.drv /nix/store/ixhz51p4wldvqkii50649zg4pf0lj9wm-lua-5.2.4.drv
- /nix/store/gh1il6ggfznnars706xpd4x4zs65ldnq-lua-5.2.4.drv:{out}
+ /nix/store/ixhz51p4wldvqkii50649zg4pf0lj9wm-lua-5.2.4.drv:{out}
• The environments do not match:
    + enableShared=1

It is not necessary to add enableShared to the environment.

Try this diff as solution, putting it into passthru instead (I am on purpose using different sharedEnabled terminology there to distinguish the user "request" from what it was eventually built with):

diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix
index 72c2a794ef0..f7967a156ca 100644
--- a/pkgs/development/interpreters/lua-5/default.nix
+++ b/pkgs/development/interpreters/lua-5/default.nix
@@ -42,7 +42,7 @@ in rec {
     sourceVersion = { major = "5"; minor = "2"; patch = "4"; };
     hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
   }).overrideAttrs (oldAttrs: rec {
-    patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else if oldAttrs.enableShared then [ dsoPatch52 ] else [ ];
+    patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else if oldAttrs.passthru.enableShared then [ dsoPatch52 ] else [ ];
   });
 
   lua5_2_compat = lua5_2.override({
diff --git a/pkgs/development/interpreters/lua-5/interpreter.nix b/pkgs/development/interpreters/lua-5/interpreter.nix
index f378c3d5eac..f9dd818f8cc 100644
--- a/pkgs/development/interpreters/lua-5/interpreter.nix
+++ b/pkgs/development/interpreters/lua-5/interpreter.nix
@@ -28,7 +28,6 @@ self = stdenv.mkDerivation rec {
 
   buildInputs = [ readline ];
 
-  inherit enableShared;
   inherit patches;
 
   # see configurePhase for additional flags (with space)
@@ -103,6 +102,7 @@ self = stdenv.mkDerivation rec {
     withPackages = import ./with-packages.nix { inherit buildEnv luaPackages;};
     pkgs = luaPackages;
     interpreter = "${self}/bin/lua";
+    sharedEnabled = enableShared;
   };
 
   meta = {

Even better would be to have a form of override function that allows us to get at the previous derivation arguments (as opposed to attributes), but I don't know if that's possible.

@nh2
Copy link
Contributor

nh2 commented Dec 19, 2019

This is a step forward to allow static building pandoc.

@malbarbo FYI static-haskell-nix can already build pandoc statically, see #43795

  • pandoc

If your plan is to build Haskell executables statically using nixpkgs only, then the most efficient path to that might be to help me with merging static-haskell-nix into nixpkgs, or more concretely, to remove open blockers that prevent it (in particular #61575, because for TemplateHaskell we need both .sos and .as and pkgsStatic only does .as).


Your lua improvements are still appreciated though, and there's also this related issue you may want to subscribe to:

https://github.com/nh2/static-haskell-nix/blob/d24dea3d46a727e1cd93e67458ce2768109efe0a/survey/default.nix#L939-L941

@nh2
Copy link
Contributor

nh2 commented Dec 19, 2019

@malbarbo That looks much better, a lot less mass-rebuilds.

There are still a few things rebuilding though (these), I don't understand why.

For example lua52Packages.luaossl:

% nix-diff /nix/store/aniavlxa7r8jcpxh3qszyf56f86bg802-lua5.2-luaossl-20190731-0.drv /nix/store/ayvgjygjanin06923zmri8lln3sqldhg-lua5.2-luaossl-20190731-0.drv
- /nix/store/aniavlxa7r8jcpxh3qszyf56f86bg802-lua5.2-luaossl-20190731-0.drv:{out}
+ /nix/store/ayvgjygjanin06923zmri8lln3sqldhg-lua5.2-luaossl-20190731-0.drv:{out}
• The input named `hook` differs
  - /nix/store/805aiik3hmq5zng7a95i6kyywrd97rzg-hook.drv:{out}
  + /nix/store/7skgffkl3gf74wk2x47smalsj2j73bkg-hook.drv:{out}
  • The input named `lua-5.2.4` differs
    - /nix/store/4a6h2k3mnq47q0wywmk86q31dg8fg3ka-lua-5.2.4.drv:{out}
    + /nix/store/lq3llx5009aslvj91bxqxzasw3nkqkdz-lua-5.2.4.drv:{out}
    • The set of input names do not match:
        - lua-arch.patch
    • The environments do not match:
        patches=/nix/store/jpkm2nm2m9xf9m9v44cr5lw9kx3b2rf7-lua-arch.patch
• The input named `lua-5.2.4` differs
  • These two derivations have already been compared
• The input named `luarocks-3.2.1` differs
  - /nix/store/i6l5aic8kjijwkmdy10car1p5rb7snr3-luarocks-3.2.1.drv:{out}
  + /nix/store/p7gjmpyld13yj1z2x6qp9swqmhqjsf45-luarocks-3.2.1.drv:{out}
  • The input named `lua-5.2.4` differs
    • These two derivations have already been compared

The difference is the absence of lua-arch.patch, but I don't see how this could be unless in some place enableShared = false was set for the normal lua52Packages.luaossl, which doesn't seem to be the case.

What am I missing?

@malbarbo
Copy link
Contributor Author

@nh2 Thank you for your help.

The problem is that with inherit enableShared; in the derivation you add it to the environment variables. nix-diff can show it (called on the .drv files between your commits and the previous):

I'm starting with nix and didn't know about nix-diff, it's a great tool!

If your plan is to build Haskell executables statically using nixpkgs only, then the most efficient path to that might be to help me with merging static-haskell-nix into nixpkgs, or more concretely, to remove open blockers that prevent it (in particular #61575, because for TemplateHaskell we need both .sos and .as and pkgsStatic only does .as).

I'm interested in some static executables, but I think the only one write is haskell is pandoc. Anyway, I was able to get a static pandoc executable from static-haskell-nix, thanks. I can help making other (non haskell) static packages.

The difference is the absence of lua-arch.patch, but I don't see how this could be unless in some place enableShared = false was set for the normal lua52Packages.luaossl, which doesn't seem to be the case.

It seems that overrideAttrs is not being evaluated. I tried to build the lua52Packages.luaossl with this patch

diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix
index 60742e45a9f..10b82988797 100644
--- a/pkgs/development/interpreters/lua-5/default.nix
+++ b/pkgs/development/interpreters/lua-5/default.nix
@@ -42,12 +42,7 @@ in rec {
     sourceVersion = { major = "5"; minor = "2"; patch = "4"; };
     hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
   }).overrideAttrs (oldAttrs: rec {
-    patches =
-      if stdenv.isDarwin then
-        [ ./5.2.darwin.patch ]
-      else if oldAttrs.passthru.sharedEnabled then
-        [ dsoPatch52 ]
-      else [ ];
+    patches = [ dsoPatch52 ];
   });
 
   lua5_2_compat = lua5_2.override({

but it fails to build with

cp: cannot stat 'liblua.so': No such file or directory
cp: cannot stat 'liblua.so.5.2': No such file or directory
cp: cannot stat 'liblua.so.5.2.4': No such file or directory

On the other hand, the package build fine (it is downloaded from the cache, so no hash changes) with

diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix
index 60742e45a9f..837bc08292c 100644
--- a/pkgs/development/interpreters/lua-5/default.nix
+++ b/pkgs/development/interpreters/lua-5/default.nix
@@ -41,6 +41,7 @@ in rec {
   lua5_2 = (callPackage ./interpreter.nix {
     sourceVersion = { major = "5"; minor = "2"; patch = "4"; };
     hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
+    patches = [ dsoPatch52 ];
   }).overrideAttrs (oldAttrs: rec {
     patches =
       if stdenv.isDarwin then

In pkgs/top-level/all-packages.nix we have lua52Packages = recurseIntoAttrs lua5_2.pkgs;. Maybe it is a problem in the function recurseIntoAttrs?

@FRidh FRidh removed this from WIP in Staging Feb 5, 2020
@FRidh FRidh added this to Needs review in Static builds Mar 29, 2020
@stale
Copy link

stale bot commented Oct 15, 2020

Hello, I'm a bot and I thank you in the name of the community for your contributions.

Nixpkgs is a busy repository, and unfortunately sometimes PRs get left behind for too long. Nevertheless, we'd like to help committers reach the PRs that are still important. This PR has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

If this is still important to you and you'd like to remove the stale label, we ask that you leave a comment. Your comment can be as simple as "still important to me". But there's a bit more you can do:

If you received an approval by an unprivileged maintainer and you are just waiting for a merge, you can @ mention someone with merge permissions and ask them to help. You might be able to find someone relevant by using Git blame on the relevant files, or via GitHub's web interface. You can see if someone's a member of the nixpkgs-committers team, by hovering with the mouse over their username on the web interface, or by searching them directly on the list.

If your PR wasn't reviewed at all, it might help to find someone who's perhaps a user of the package or module you are changing, or alternatively, ask once more for a review by the maintainer of the package/module this is about. If you don't know any, you can use Git blame on the relevant files, or GitHub's web interface to find someone who touched the relevant files in the past.

If your PR has had reviews and nevertheless got stale, make sure you've responded to all of the reviewer's requests / questions. Usually when PR authors show responsibility and dedication, reviewers (privileged or not) show dedication as well. If you've pushed a change, it's possible the reviewer wasn't notified about your push via email, so you can always officially request them for a review, or just @ mention them and say you've addressed their comments.

Lastly, you can always ask for help at our Discourse Forum, or more specifically, at this thread or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 15, 2020
@malbarbo
Copy link
Contributor Author

I need some help here. It seems that recurseIntoAttrs (#75901 (comment)) does not work as I expect.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 15, 2020
@malbarbo
Copy link
Contributor Author

Done in #127425.

@malbarbo malbarbo closed this Jun 26, 2021
@cdepillabout cdepillabout moved this from Needs review to Done in Static builds Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants