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

Enable musl support for ebtables #50242

Closed
wants to merge 3 commits into from

Conversation

tathougies
Copy link
Contributor

Motivation for this change

By default, ebtables depends on shared object initialization routines which are not supported in the musl dynamic linker. ebtables can also be built statically, and then works fine with musl. This patch adds an option to enable static builds for ebtables, and enables this by default for musl.

Additionally, there is some name-shadowing going on with the ethhdr struct. I used the C preprocessor to get rid of this, but I'm open to suggestions on how to make this better.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

@@ -30,4 +53,4 @@ stdenv.mkDerivation rec {
license = licenses.gpl2;
platforms = platforms.linux;
};
}
} // (if enableStatic then staticBuildOpts else {}))
Copy link
Member

Choose a reason for hiding this comment

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

Use optionalAttrs here for clarity.

@@ -12,16 +23,28 @@ stdenv.mkDerivation rec {
makeFlags =
[ "LIBDIR=$(out)/lib" "BINDIR=$(out)/sbin" "MANDIR=$(out)/share/man"
"ETCDIR=$(out)/etc" "INITDIR=$(TMPDIR)" "SYSCONFIGDIR=$(out)/etc/sysconfig"
"LOCALSTATEDIR=/var"
"LOCALSTATEDIR=/var" "CC=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
Copy link
Member

Choose a reason for hiding this comment

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

We' have issues with this in the past. Sometimes packages will save $CC in their output for debugging, causing a dependency on the compiler. To avoid that, you should just do CC=${stdenv.cc.targetPrefix}cc.

"-Du_int8_t=uint8_t"
"-Du_int32_t=uint32_t"
] ++
lib.optional enableDebug "-g3"
Copy link
Member

Choose a reason for hiding this comment

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

We don't want this. This is something that you would set globally. You can use keepDebugInfo for this purpose:

https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/adapters.nix#L157-L165

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Er.. yeah, that makes sense. You can see my debugging process in this PR :)

preBuild =
''
substituteInPlace Makefile --replace '-o root -g root' ""
'';

NIX_CFLAGS_COMPILE = "-Wno-error";
NIX_CFLAGS_COMPILE = lib.concatStringsSep " " (
Copy link
Member

Choose a reason for hiding this comment

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

NIX_CFLAGS_COMPILE can just be made a list. Nix will do the concating for you.


stdenv.mkDerivation rec {
let staticBuildOpts = {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more clear to put these inside of mkDerivation. For instance:

  buildFlags = if enableStatic then "static" else null;
  installPhase = if enableStatic then ''
    ...
  '' else null;

@Mic92
Copy link
Member

Mic92 commented Nov 23, 2018

@GrahamcOfBorg build pkgsCross.aarch64-multiplatform.ebtables

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: pkgsCross.aarch64-multiplatform.ebtables

Partial log (click to expand)

shrinking /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/lib/libebt_802_3.so
shrinking /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/sbin/ebtables-restore
shrinking /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/sbin/ebtables
gzipping man pages under /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/share/man/
strip is /nix/store/6dpnd5aniypn8124mmy8f88s4mq2zl07-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/lib  /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/sbin
patching script interpreter paths in /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4
checking for references to /build in /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4...
moving /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/sbin/* to /nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4/bin
/nix/store/5sjcwnqay721p0cjd38ai62lh9vf9kj7-ebtables-2.0.10-4

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: pkgsCross.aarch64-multiplatform.ebtables

Partial log (click to expand)

shrinking /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/lib/libebt_vlan.so
shrinking /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/sbin/ebtables-restore
shrinking /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/sbin/ebtables
gzipping man pages under /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/share/man/
aarch64-unknown-linux-gnu-strip is /nix/store/spkgb1j8yhnj1k6hqvqd4plbh7p39a1a-aarch64-unknown-linux-gnu-binutils-2.30/bin/aarch64-unknown-linux-gnu-strip
stripping (with command aarch64-unknown-linux-gnu-strip and flags -S) in /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/lib  /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/sbin
patching script interpreter paths in /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu
checking for references to /build in /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu...
moving /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/sbin/* to /nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu/bin
/nix/store/s4qr6dybldmmdagjygkpxcw6is43r0sg-ebtables-2.0.10-4-aarch64-unknown-linux-gnu

@@ -14143,7 +14143,7 @@ with pkgs;

lightum = callPackage ../os-specific/linux/lightum { };

ebtables = callPackage ../os-specific/linux/ebtables { };
ebtables = callPackage ../os-specific/linux/ebtables { enableStatic = stdenv.hostPlatform.isMusl; };
Copy link
Member

Choose a reason for hiding this comment

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

I would move the default inside the package itself

{
  ...
  enableStatic = stdenv.hostPlatform.isMusl
}

Otherwise people might miss the override from all-packages.nix

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: pkgsCross.aarch64-multiplatform.ebtables

Partial log (click to expand)

make[1]: *** [Makefile:215: elf/subdir_lib] Error 2
make[1]: Leaving directory '/private/tmp/nix-build-glibc-2.27-aarch64-unknown-linux-gnu.drv-0/glibc-2.27'
make: *** [Makefile:9: all] Error 2
builder for '/nix/store/psazcng4ss3pljgv53b0y11s08sj8a4n-glibc-2.27-aarch64-unknown-linux-gnu.drv' failed with exit code 2
cannot build derivation '/nix/store/11nnhh4n52p47xlli793h37d8zw4w081-aarch64-unknown-linux-gnu-binutils-wrapper-2.30.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/6h1vwqwczk63vy28abrzpyg5hiaqqdlv-aarch64-unknown-linux-gnu-stage-final-gcc-debug-7.3.0.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/4rdafyx56sj4lklfrfj5scb5078i3cra-aarch64-unknown-linux-gnu-stage-final-gcc-debug-wrapper-7.3.0.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/b3aaf010356si39jlp8aqgm0lw8y8w14-stdenv-darwin.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/jchsrclfwql55xdzqbhdjkd2gkym97mh-ebtables-2.0.10-4-aarch64-unknown-linux-gnu.drv': 1 dependencies couldn't be built
error: build of '/nix/store/jchsrclfwql55xdzqbhdjkd2gkym97mh-ebtables-2.0.10-4-aarch64-unknown-linux-gnu.drv' failed

@tathougies
Copy link
Contributor Author

I think the last failure is unrelated to this patch?

@dtzWill
Copy link
Member

dtzWill commented May 1, 2019

Well this seems in good shape now!

That said, this may not be needed anymore-- iptables now includes ebtables, and pkgsMusl.iptables works properly AFAIK and includes an ebtables binary.

I haven't investigated the static/dynamic issue mentioned, but since void-linux has deprecated their ebtables package for iptables it probably already works or can be made to work readily.

All that said, as long as we have this package and don't replace it with iptables on all arch's,
maybe it's worth these fixes anyway...?

@FRidh
Copy link
Member

FRidh commented Nov 3, 2019

@tathougies what do you think about what @dtzWill wrote?

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 3, 2020
@stale
Copy link

stale bot commented Jun 5, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 5, 2021
@superherointj
Copy link
Contributor

@tathougies ping

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 9, 2022
@SuperSandro2000
Copy link
Member

Closing as this PR is really old, has merge conflicts and conditional patches are not nice for maintainability. Also I suspect this needs at least to be partly redone.

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

Successfully merging this pull request may close these issues.

None yet

10 participants