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

Switch Nixpkgs to using more NetBSD stuff for MUSL #41320

Merged
merged 5 commits into from Jun 1, 2018

Conversation

matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented May 31, 2018

Motivation for this change

This gets rid of some of the Musl specific stuff that was being pulled indirectly from NetBSD sources. Libbsd is also replaced with NetBSD compat. More testing is still needed.

This gets our BSD derivations directly from the upstream NetBSD CVS tree. Previously we were relying on "Linux"ized derivations of BSD sources (slightly modified versions of the original BSD sources). There are basically two things this changes:

  • Replace libbsd with NetBSD compat. The Freedesktop project maintains libbsd but they only support it on Linux platforms. libbsd works great for Linux but unfortunately lacks feature detection & requires heavy patching for macOS or really anything else that's not GNU/Linux. NetBSD compat does proper feature detection so should work almost anywhere. (https://github.com/NetBSD/src/tree/trunk/tools/compat)
  • Replace musl-* stuff with direct NetBSD derivation. These are all derived from NetBSD sources originally but we were relying on Alpine Linux's version of them. Moving to upstream should be more reliable.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: libbsd

Partial log (click to expand)

--- /nix/store/sb2nv5nki21g9hhg86dhsi89g6zzfg57-bsd-compat-netbsd-7.1.2/include/compat/nbtool_config.h ---
#   install  /nix/store/sb2nv5nki21g9hhg86dhsi89g6zzfg57-bsd-compat-netbsd-7.1.2/include/compat/nbtool_config.h
/nix/store/7ks9bl96a1793lxjk9vyxyf80a5m6a5f-coreutils-8.29/bin/install -c  -D nbtool_config.h /nix/store/sb2nv5nki21g9hhg86dhsi89g6zzfg57-bsd-compat-netbsd-7.1.2/include/compat/nbtool_config.h
--- includes ---
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/sb2nv5nki21g9hhg86dhsi89g6zzfg57-bsd-compat-netbsd-7.1.2
strip is /nix/store/92d2ifxcni4n3zx9s8wnkcjlvnx5ajlc-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/sb2nv5nki21g9hhg86dhsi89g6zzfg57-bsd-compat-netbsd-7.1.2/lib
patching script interpreter paths in /nix/store/sb2nv5nki21g9hhg86dhsi89g6zzfg57-bsd-compat-netbsd-7.1.2
checking for references to /build in /nix/store/sb2nv5nki21g9hhg86dhsi89g6zzfg57-bsd-compat-netbsd-7.1.2...

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: libbsd

Partial log (click to expand)

/nix/store/l28y6zy1qfiqhpcs37kvclabj066a8v7-coreutils-8.29/bin/install -d /nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2/share/compat
--- /nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2/lib/libnbcompat.a ---
/nix/store/l28y6zy1qfiqhpcs37kvclabj066a8v7-coreutils-8.29/bin/install -c  -D -m 444 libnbcompat.a /nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2/lib/libnbcompat.a
--- includes ---
--- /nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2/share/compat/defs.mk ---
/nix/store/l28y6zy1qfiqhpcs37kvclabj066a8v7-coreutils-8.29/bin/install -c  -D defs.mk /nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2/share/compat/defs.mk
post-installation fixup
strip is /nix/store/r5mcn9vqq80v5pfqp45d7290cis7dwp4-cctools-binutils-darwin/bin/strip
stripping (with command strip and flags -S) in /nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2/lib
patching script interpreter paths in /nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: libbsd

Partial log (click to expand)

--- /nix/store/kaln74gz597hwgzmfs8dix6d3lgi4y7f-bsd-compat-netbsd-7.1.2/share/compat/defs.mk ---
/nix/store/nnkwjkcjqw94knaxpzwl7sysx72xab3z-coreutils-8.29/bin/install -c  -D defs.mk /nix/store/kaln74gz597hwgzmfs8dix6d3lgi4y7f-bsd-compat-netbsd-7.1.2/share/compat/defs.mk
--- includes ---
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/kaln74gz597hwgzmfs8dix6d3lgi4y7f-bsd-compat-netbsd-7.1.2
strip is /nix/store/8yfik687kfccisxnad42j19lfb7ij9b4-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/kaln74gz597hwgzmfs8dix6d3lgi4y7f-bsd-compat-netbsd-7.1.2/lib
patching script interpreter paths in /nix/store/kaln74gz597hwgzmfs8dix6d3lgi4y7f-bsd-compat-netbsd-7.1.2
checking for references to /build in /nix/store/kaln74gz597hwgzmfs8dix6d3lgi4y7f-bsd-compat-netbsd-7.1.2...
/nix/store/kaln74gz597hwgzmfs8dix6d3lgi4y7f-bsd-compat-netbsd-7.1.2

@matthewbauer
Copy link
Member Author

@GrahamcOfBorg build mg

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: mg

Partial log (click to expand)

   n = (int)strtonum(buf, INT_MIN, INT_MAX, &err);
            ^~~~~~~~
            strtou
cscope.c: In function 'addentry':
cscope.c:498:11: warning: implicit declaration of function 'strtonum'; did you mean 'strtou'? [-Wimplicit-function-declaration]
  lineno = strtonum(t.lineno, INT_MIN, INT_MAX, &errstr);
           ^~~~~~~~
           strtou
builder for '/nix/store/j5w3541fhr07kap0x1jiv7qgcdrb7br0-mg-20171014.drv' failed with exit code 2
�[31;1merror:�[0m build of '/nix/store/j5w3541fhr07kap0x1jiv7qgcdrb7br0-mg-20171014.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: mg

Partial log (click to expand)

./def.h:42:9: warning: 'TRUE' macro redefined [-Wmacro-redefined]
#define TRUE    1               /* True, yes, good, etc.         */
        ^
/nix/store/apmsjghssi4wyfbx7wdaar5bxbdn0rcr-bsd-compat-netbsd-7.1.2/include/rpc/types.h:59:10: note: previous definition is here
#       define TRUE     (1)
               ^
2 warnings generated.
2 warnings generated.
builder for '/nix/store/x48sqfxlr6v6hykksp6zdkbx0wq7lsl3-mg-20171014.drv' failed with exit code 2
error: build of '/nix/store/x48sqfxlr6v6hykksp6zdkbx0wq7lsl3-mg-20171014.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: mg

Partial log (click to expand)

                ^~~~~~~~
                strtou
tags.c:11:10: fatal error: sys/tree.h: No such file or directory
 #include <sys/tree.h>
          ^~~~~~~~~~~~
compilation terminated.
make: *** [GNUmakefile:63: tags.o] Error 1
make: *** Waiting for unfinished jobs....
builder for '/nix/store/9jigxr2y1b5cwbzi50rvqkkj0kx6pfdd-mg-20171014.drv' failed with exit code 2
error: build of '/nix/store/9jigxr2y1b5cwbzi50rvqkkj0kx6pfdd-mg-20171014.drv' failed

@@ -21462,6 +21457,10 @@ with pkgs;
mount wall hostname more sysctl getconf
getent;

fts = if hostPlatform.isMusl then netbsd.fts else null;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe there is some meta.available thing you can do instead of null?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be provided by most libcs except for Musl. It will build everywhere, just runs on Musl.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: libbsd

Partial log (click to expand)

/nix/store/7ks9bl96a1793lxjk9vyxyf80a5m6a5f-coreutils-8.29/bin/install -c  -D nbtool_config.h /nix/store/m0r3n0b0wdnanq2y65mmx65s4j2aw0p9-bsd-compat-netbsd-7.1.2/include/compat/nbtool_config.h
--- /nix/store/m0r3n0b0wdnanq2y65mmx65s4j2aw0p9-bsd-compat-netbsd-7.1.2/share/compat/defs.mk ---
/nix/store/7ks9bl96a1793lxjk9vyxyf80a5m6a5f-coreutils-8.29/bin/install -c  -D defs.mk /nix/store/m0r3n0b0wdnanq2y65mmx65s4j2aw0p9-bsd-compat-netbsd-7.1.2/share/compat/defs.mk
--- includes ---
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/m0r3n0b0wdnanq2y65mmx65s4j2aw0p9-bsd-compat-netbsd-7.1.2
strip is /nix/store/92d2ifxcni4n3zx9s8wnkcjlvnx5ajlc-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/m0r3n0b0wdnanq2y65mmx65s4j2aw0p9-bsd-compat-netbsd-7.1.2/lib
patching script interpreter paths in /nix/store/m0r3n0b0wdnanq2y65mmx65s4j2aw0p9-bsd-compat-netbsd-7.1.2
checking for references to /build in /nix/store/m0r3n0b0wdnanq2y65mmx65s4j2aw0p9-bsd-compat-netbsd-7.1.2...

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: libbsd

Partial log (click to expand)

/nix/store/l28y6zy1qfiqhpcs37kvclabj066a8v7-coreutils-8.29/bin/install -c  -D nbtool_config.h /nix/store/r7wk5jrf54vkni76x36vjrycdj2nx9xq-bsd-compat-netbsd-7.1.2/include/compat/nbtool_config.h
--- /nix/store/r7wk5jrf54vkni76x36vjrycdj2nx9xq-bsd-compat-netbsd-7.1.2/lib/libnbcompat.a ---
/nix/store/l28y6zy1qfiqhpcs37kvclabj066a8v7-coreutils-8.29/bin/install -c  -D -m 444 libnbcompat.a /nix/store/r7wk5jrf54vkni76x36vjrycdj2nx9xq-bsd-compat-netbsd-7.1.2/lib/libnbcompat.a
--- /nix/store/r7wk5jrf54vkni76x36vjrycdj2nx9xq-bsd-compat-netbsd-7.1.2/share/compat/defs.mk ---
/nix/store/l28y6zy1qfiqhpcs37kvclabj066a8v7-coreutils-8.29/bin/install -c  -D defs.mk /nix/store/r7wk5jrf54vkni76x36vjrycdj2nx9xq-bsd-compat-netbsd-7.1.2/share/compat/defs.mk
--- includes ---
post-installation fixup
strip is /nix/store/r5mcn9vqq80v5pfqp45d7290cis7dwp4-cctools-binutils-darwin/bin/strip
stripping (with command strip and flags -S) in /nix/store/r7wk5jrf54vkni76x36vjrycdj2nx9xq-bsd-compat-netbsd-7.1.2/lib
patching script interpreter paths in /nix/store/r7wk5jrf54vkni76x36vjrycdj2nx9xq-bsd-compat-netbsd-7.1.2

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: libbsd

Partial log (click to expand)

--- /nix/store/316bnjm5ci5g9zdssbrnrsaly9fzdxjm-bsd-compat-netbsd-7.1.2/share/compat/defs.mk ---
/nix/store/nnkwjkcjqw94knaxpzwl7sysx72xab3z-coreutils-8.29/bin/install -c  -D defs.mk /nix/store/316bnjm5ci5g9zdssbrnrsaly9fzdxjm-bsd-compat-netbsd-7.1.2/share/compat/defs.mk
--- includes ---
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/316bnjm5ci5g9zdssbrnrsaly9fzdxjm-bsd-compat-netbsd-7.1.2
strip is /nix/store/8yfik687kfccisxnad42j19lfb7ij9b4-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/316bnjm5ci5g9zdssbrnrsaly9fzdxjm-bsd-compat-netbsd-7.1.2/lib
patching script interpreter paths in /nix/store/316bnjm5ci5g9zdssbrnrsaly9fzdxjm-bsd-compat-netbsd-7.1.2
checking for references to /build in /nix/store/316bnjm5ci5g9zdssbrnrsaly9fzdxjm-bsd-compat-netbsd-7.1.2...
/nix/store/316bnjm5ci5g9zdssbrnrsaly9fzdxjm-bsd-compat-netbsd-7.1.2

@edolstra
Copy link
Member

edolstra commented Jun 1, 2018

I don't understand what this means. Why would we want to use "more NetBSD stuff"? If the goal is to move away from GNU, 👎.

@matthewbauer
Copy link
Member Author

I don't understand what this means. Why would we want to use "more NetBSD stuff"

I should have been more clear. This gets our BSD derivations directly from the upstream NetBSD CVS tree. Previously we were relying on "Linux"ized derivations of BSD sources. There are basically two things this changes:

  • Replace libbsd with NetBSD compat. The Freedesktop project maintains libbsd but they only support it on Linux platforms. libbsd works great for Linux but unfortunately lacks feature detection & requires heavy patching for macOS or really anything else that's not GNU/Linux. NetBSD compat does proper feature detection so should work almost anywhere. (https://github.com/NetBSD/src/tree/trunk/tools/compat)
  • Replace musl-* stuff with direct NetBSD derivation. These are all derived from NetBSD sources originally but we were relying on Alpine Linux's version of them. Moving to upstream should be more reliable.

@Ericson2314 Ericson2314 changed the title Switch Nixpkgs to using more NetBSD stuff Switch Nixpkgs to using more NetBSD stuff for MUSL Jun 1, 2018
@Ericson2314
Copy link
Member

@edolstra yeah even more pithily put, this is not moving away from GNU, but just using upstream version of the non-GNU stuff we already use.

@Ericson2314 Ericson2314 merged commit 7a2dd97 into NixOS:master Jun 1, 2018
@vcunat
Copy link
Member

vcunat commented Jun 2, 2018

This broke samba build, now discussed on #nixos-dev with @7c6f434c.

7c6f434c added a commit to 7c6f434c/nixpkgs that referenced this pull request Jun 2, 2018
a partial rollback of NixOS#41320

samba is already Linux-only because of acl, and it is unclear what the
problem is with upstream netbsd-compat.
@orivej
Copy link
Contributor

orivej commented Jun 6, 2018

This has broken all packages that depend on libbsd, and the reason is obvious if you compare the include files that they install:

# freedesktop libbsd      # netbsd compat
└── bsd                   ├── cdbr.h
    ├── bitstring.h       ├── cdbw.h
    ├── bsd.h             ├── compat_defs.h
    ├── err.h             ├── db.h
    ├── getopt.h          ├── machine
    ├── inttypes.h        │   ├── bswap.h
    ├── libutil.h         │   └── endian.h
    ├── md5.h             ├── md5.h
    ├── netinet           ├── nbtool_config.h
    │   └── ip_icmp.h     ├── netconfig.h
    ├── nlist.h           ├── rmd160.h
    ├── readpassphrase.h  ├── rpc
    ├── stdio.h           │   └── types.h
    ├── stdlib.h          ├── sha1.h
    ├── string.h          ├── sha2.h
    ├── stringlist.h      ├── sys
    ├── sys               │   ├── bswap.h
    │   ├── bitstring.h   │   ├── endian.h
    │   ├── cdefs.h       │   ├── featuretest.h
    │   ├── endian.h      │   ├── queue.h
    │   ├── poll.h        │   └── tree.h
    │   ├── queue.h       ├── tzfile.h
    │   ├── time.h        ├── util.h
    │   └── tree.h        ├── utmpx.h
    ├── timeconv.h        └── vis.h
    ├── unistd.h
    ├── vis.h
    └── wchar.h

acme-client:

config.h:21:12: fatal error: bsd/stdlib.h: No such file or directory

hfsprogs:

/build/diskdev_cmds-332.25/include/missing.h:9:10: fatal error: bsd/string.h: No such file or directory

radiotray-ng:

-- Checking for one of the modules 'libbsd'
CMake Error at /nix/store/5adacq979k95wi13q6fzhdddgxbqnpz0-cmake-3.11.2/share/cmake-3.11/Modules/FindPkgConfig.cmake:640 (message):
  None of the required 'libbsd' found

where radiotray-ng CMakeLists.txt contains

if (NOT APPLE)
    pkg_search_module(LIBBSD  REQUIRED libbsd)
endif(NOT APPLE)

Clearly nbcompat can not replace libbsd.

@matthewbauer
Copy link
Member Author

Yes if someone wants to undo the libbsd = netbsd.compat they are certainly welcome to. A few do build but mostly just ones using basic symbols like strlcpy. I still want to minimize libbsd usage in nixpkgs but it is obviously not a drop in replacement right now.

@orivej
Copy link
Contributor

orivej commented Jun 6, 2018

OK, I'll undo libbsd = netbsd.compat.

I have noticed that having a direct or an indirect dependency on netbsd.compat adds -include nbtool_config.h to NIX_CFLAGS_COMPILE (here), which prepends a lot of stuff to every compiled file, such as:

#define HAVE_ASPRINTF 1
#define HAVE_FEATURES_H 1
#define STDC_HEADERS 1

#include "compat_defs.h"

# ← from compat_defs.h

#if defined(__linux__) && HAVE_FEATURES_H
#include <features.h>
#undef _POSIX_SOURCE
#undef _POSIX_C_SOURCE
#define __USE_ISOC99 1
#endif

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#undef btodb
#define btodb(x) ((x) << 9)
#undef setbit
#define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))

and e.g. this file compiles and runs:

int main() {
    puts("hello");
    return btodb(10);
}

Is this -include necessary? If it is, can it be limited to direct dependencies? It has high potential to introduce subtle breakages.

@matthewbauer
Copy link
Member Author

It may not be necessary any more but it definitely was at one point. The NetBSD derivations are built on top of this so they need those defines to avoid compatibility issues. This is supposed to get you to a BSD-compatible system. I can look into either disabling the default or making it optional though.

@orivej
Copy link
Contributor

orivej commented Jun 6, 2018

If only stuff under netbsd will depend on netbsd.compat, then it seems OK to leave this as is.

@orivej orivej mentioned this pull request Jun 6, 2018
8 tasks
orivej added a commit to orivej/nixpkgs that referenced this pull request Jun 6, 2018
This reverts commit 480434f.

netbsd.compat does not provide include files that are provided by libbsd [1], and it
encumbers its transitive dependents with an obligatory include file that setups
BSD-compatible C environment [2].

[1] NixOS#41320 (comment)
[2] NixOS#41320 (comment)
@orivej
Copy link
Contributor

orivej commented Jun 6, 2018

Sorry, I was wrong about indirect dependencies in:

I have noticed that having a direct or an indirect dependency on netbsd.compat adds -include nbtool_config.h to NIX_CFLAGS_COMPILE
Is this -include necessary? If it is, can it be limited to direct dependencies?

I have tested this with a package that indirectly depended on netbsd.fts which propagates netbsd.compat.

However, a package with -include nbtool_config.h in its setupHook should not be propagated. The packages that currently propagate it should have the same setupHook instead. I'm going to propose this in a PR.

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

7 participants