pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk mk: Initial support for NixOS (Linux variant)



details:   https://anonhg.NetBSD.org/pkgsrc/rev/1624c1a0e105
branches:  trunk
changeset: 378256:1624c1a0e105
user:      nia <nia%pkgsrc.org@localhost>
date:      Sun May 01 08:03:40 2022 +0000

description:
mk: Initial support for NixOS (Linux variant)

A particular challenge for pkgsrc on NixOS is that it usurps all
Unix conventions and stores its system binaries and libraries in
a crazy system of hashed sub-directories:

$ which ls
/run/current-system/sw/bin/ls
$ ls -l /run/current-system/sw/bin/ls
Lrwxrwxrwx 1 root root 65 Jan  1  1970 /run/current-system/sw/bin/ls -> /nix/store/xs02fpnpkq
frhqqfsxx3lpj48wrapd00-coreutils-8.32/bin/ls

We can make a "best effort" attempt to accomodate this by invoking
the compiler to figure out where libc is.  In general, it's required to
adjust the Linux files to make fewer assumptions about the layout of the
filesystem.

However, since using a compiler and libc from NixOS results in /nix/store
paths being embedded in binaries, running the NixOS "garbage collector"
can result in binaries installed from pkgsrc becoming unusable.  Use with
care:

$ readelf -a ~/pkg/bin/perl | grep nix
      [Requesting program interpreter: /nix/store/p5sam91qwz995pi0160rfr7dkh6pibil-glibc-2.32
-39/lib/ld-linux-aarch64.so.1]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/nia/pkg/lib:/home/nia/pkg/li
b/perl5/5.32.0/aarch64-linux/CORE:/nix/store/p5sam91qwz995pi0160rfr7dkh6pibil-glibc-2.32-39/l
ib:/nix/store/vv9nz0bwv1pfl70w14k7dgz6yx7hjwxk-gcc-9.3.0-lib/lib]

Apparently, the "stdenv.cc" package must be installed prior to
bootstrapping pkgsrc.

I worked on this patch last year for a friend who wanted to test
something on pkgsrc but had no other system available.

diffstat:

 mk/bsd.prefs.mk         |    4 +-
 mk/platform/Linux.mk    |   48 ++-
 mk/tools/tools.Linux.mk |  584 ++++++++++++++++++++++++------------------------
 3 files changed, 327 insertions(+), 309 deletions(-)

diffs (truncated from 722 to 300 lines):

diff -r 2b9bf4241863 -r 1624c1a0e105 mk/bsd.prefs.mk
--- a/mk/bsd.prefs.mk   Sun May 01 08:03:13 2022 +0000
+++ b/mk/bsd.prefs.mk   Sun May 01 08:03:40 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.prefs.mk,v 1.420 2022/04/30 21:27:57 tnn Exp $
+# $NetBSD: bsd.prefs.mk,v 1.421 2022/05/01 08:03:40 nia Exp $
 #
 # This file includes the mk.conf file, which contains the user settings.
 #
@@ -81,6 +81,8 @@
 UNAME=/usr/bin/uname
 .elif exists(/bin/uname)
 UNAME=/bin/uname
+.elif exists(/run/current-system/sw/bin/uname)
+UNAME=/run/current-system/sw/bin/uname
 .else
 UNAME=echo Unknown
 .endif
diff -r 2b9bf4241863 -r 1624c1a0e105 mk/platform/Linux.mk
--- a/mk/platform/Linux.mk      Sun May 01 08:03:13 2022 +0000
+++ b/mk/platform/Linux.mk      Sun May 01 08:03:40 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Linux.mk,v 1.88 2022/02/10 21:22:44 schmonz Exp $
+# $NetBSD: Linux.mk,v 1.89 2022/05/01 08:03:41 nia Exp $
 #
 # Variable definitions for the Linux operating system.
 
@@ -9,27 +9,36 @@
 .endif
 IMAKEOPTS+=    -DBuildHtmlManPages=NO
 PKGLOCALEDIR?= share
+
+TYPE?=         type                    # Shell builtin
+
+.if exists(/etc/NIXOS)
+PS?=           /run/current-system/sw/bin/ps
+SU?=           /run/current-system/sw/bin/su
+USERADD?=      /run/current-system/sw/bin/useradd
+GROUPADD?=     /run/current-system/sw/bin/groupadd
+NOLOGIN?=      /run/current-system/sw/bin/nologin
+.endif
+
 PS?=           /bin/ps
-# XXX: default from defaults/mk.conf.  Verify/correct for this platform
-# and remove this comment.
 .if exists(/usr/bin/su)
 SU?=           /usr/bin/su
 .else
 SU?=           /bin/su
 .endif
-TYPE?=         type                    # Shell builtin
+.if exists(/sbin/nologin)
+NOLOGIN?=      /sbin/nologin
+.else
+NOLOGIN?=      /bin/false
+.endif
+USERADD?=      /usr/sbin/useradd
+GROUPADD?=     /usr/sbin/groupadd
 
 CPP_PRECOMP_FLAGS?=    # unset
 DEF_UMASK?=            022
 DEFAULT_SERIAL_DEVICE?=        /dev/null
 EXPORT_SYMBOLS_LDFLAGS?=       # Don't add symbols to the dynamic symbol table
-GROUPADD?=             /usr/sbin/groupadd
 MOTIF_TYPE_DEFAULT?=   motif   # default 2.0 compatible libs type
-.if exists(/etc/ssdlinux_version)
-NOLOGIN?=              /sbin/nologin
-.else
-NOLOGIN?=              /bin/false
-.endif
 PKG_TOOLS_BIN?=                ${LOCALBASE}/sbin
 ROOT_CMD?=             ${SU} - root -c
 .if exists(/etc/ssdlinux_version)
@@ -43,7 +52,6 @@
 ULIMIT_CMD_stacksize?= ulimit -s `ulimit -H -s`
 ULIMIT_CMD_memorysize?=        ulimit -m `ulimit -H -m`
 ULIMIT_CMD_cputime?=   ulimit -t `ulimit -H -t`
-USERADD?=              /usr/sbin/useradd
 
 _OPSYS_EMULDIR.linux=  # empty
 _OPSYS_EMULDIR.linux32=        # empty
@@ -80,6 +88,11 @@
 .elif exists(/etc/arch-release)
 _OPSYS_SYSTEM_RPATH=   /lib:/usr/lib
 _OPSYS_LIB_DIRS?=      /lib /usr/lib
+.elif exists(/etc/NIXOS)
+# NixOS has no fixed locations for system libraries.
+_OPSYS_INCLUDE_DIRS!=  echo "" | cpp -v 2>&1 | grep '^[[:space:]]*/.*include$$' | tr '\n' ' '
+
+_OPSYS_LIB_DIRS!=      cc -print-search-dirs | awk '/^libraries:/ { $$1=""; $$2=substr($$2, 2); print $$0; }' | tr ':' '\n' 
 .else
 _OPSYS_SYSTEM_RPATH=   /lib${LIBABISUFFIX}:/usr/lib${LIBABISUFFIX}
 _OPSYS_LIB_DIRS?=      /lib${LIBABISUFFIX} /usr/lib${LIBABISUFFIX}
@@ -103,11 +116,7 @@
 _OPSYS_PREFER.dl?=             native
 _OPSYS_PREFER.pthread?=                native
 
-.if exists(/usr/include/netinet6) || exists(/usr/include/linux/in6.h)
 _OPSYS_HAS_INET6=      yes     # IPv6 is standard
-.else
-_OPSYS_HAS_INET6=      no      # IPv6 is not standard
-.endif
 _OPSYS_HAS_JAVA=       no      # Java is not standard
 _OPSYS_HAS_MANZ=       no      # no MANZ for gzipping of man pages
 _OPSYS_HAS_OSSAUDIO=   no      # libossaudio is unavailable
@@ -184,10 +193,17 @@
                                ldd --version | \
                                sed -ne's/^ldd.* \(.*\)$$/\1/p'; \
                        fi
-GLIBC_VERSION=         ${_GLIBC_VERSION_CMD:sh}
 .  endif
 .endfor
 
+# In case we can't find glibc in any of the normal library paths
+# (i.e. we're on NixOS), try ldconfig. Ironically, NixOS does not
+# actually use ldconfig...
+_GLIBC_VERSION_CMD?=   ldconfig --version | \
+                               sed -ne's/ldconfig (GNU libc) \(.*\)$$/\1/p'
+
+GLIBC_VERSION=         ${_GLIBC_VERSION_CMD:sh}
+
 # If this is defined pass it to the make process. 
 .if defined(NOGCCERROR)
 MAKE_ENV+=     NOGCCERROR=true
diff -r 2b9bf4241863 -r 1624c1a0e105 mk/tools/tools.Linux.mk
--- a/mk/tools/tools.Linux.mk   Sun May 01 08:03:13 2022 +0000
+++ b/mk/tools/tools.Linux.mk   Sun May 01 08:03:40 2022 +0000
@@ -1,302 +1,302 @@
-# $NetBSD: tools.Linux.mk,v 1.65 2020/12/05 13:15:58 js Exp $
+# $NetBSD: tools.Linux.mk,v 1.66 2022/05/01 08:03:41 nia Exp $
 #
 # System-supplied tools for the Linux operating system.
+#
+# Yet all ye who enter be warned: various Linux distributions
+# place binaries in a myriad of different paths and have a myriad
+# of different userspaces.  No assumptions can be made, so this
+# is best-effort.  Some distributions do not follow a remotely
+# Unix-like file hierarchy.
+#
+# This file still assumes (until it is proven wrong) that some
+# tools are provided by GNU.
+
+.if exists(/etc/NIXOS)
+_LINUX_BINPATHS?=      /run/current-system/sw/bin
+.else
+_LINUX_BINPATHS?=      /bin /usr/bin /sbin /usr/sbin
+.endif
+
+.for _path in ${_LINUX_BINPATHS}
+.  if exists(${_path}/autopoint)
+TOOLS_PLATFORM.autopoint?=     ${_path}/autopoint
+.  endif
+.  if exists(${_path}/basename)
+TOOLS_PLATFORM.basename?=      ${_path}/basename
+.  endif
+.  if exists(${_path}/bash)
+TOOLS_PLATFORM.bash?=          ${_path}/bash
+.  endif
+.  if exists(${_path}/bison)
+TOOLS_PLATFORM.bison?=         ${_path}/bison
+.  endif
+.  if exists(${_path}/bzcat)
+TOOLS_PLATFORM.bzcat?=         ${_path}/bzcat
+.  endif
+.  if exists(${_path}/bzip2)
+TOOLS_PLATFORM.bzip2?=         ${_path}/bzip2
+.  endif
+.  if exists(${_path}/cat)
+TOOLS_PLATFORM.cat?=           ${_path}/cat
+.  endif
+.  if exists(${_path}/chgrp)
+TOOLS_PLATFORM.chgrp?=         ${_path}/chgrp
+.  endif
+.  if exists(${_path}/chmod)
+TOOLS_PLATFORM.chmod?=         ${_path}/chmod
+.  endif
+.  if exists(${_path}/chown)
+TOOLS_PLATFORM.chown?=         ${_path}/chown
+.  endif
+.  if exists(${_path}/cmp)
+TOOLS_PLATFORM.cmp?=           ${_path}/cmp
+.  endif
+.  if exists(${_path}/cp)
+TOOLS_PLATFORM.cp?=            ${_path}/cp
+.  endif
+.  if exists(${_path}/tcsh)
+TOOLS_PLATFORM.csh?=           ${_path}/tcsh
+.  endif
+.  if exists(${_path}/curl)
+TOOLS_PLATFORM.curl?=          ${_path}/curl
+.  endif
+.  if exists(${_path}/cut)
+TOOLS_PLATFORM.cut?=           ${_path}/cut
+.  endif
+.  if exists(${_path}/diff)
+TOOLS_PLATFORM.diff?=          ${_path}/diff
+.  endif
+.  if exists(${_path}/diff3)
+TOOLS_PLATFORM.diff3?=         ${_path}/diff3
+.  endif
+.  if exists(${_path}/dirname)
+TOOLS_PLATFORM.dirname?=       ${_path}/dirname
+.  endif
+.  if exists(${_path}/egrep)
+TOOLS_PLATFORM.egrep?=         ${_path}/egrep
+.  endif
+.  if exists(${_path}/env)
+TOOLS_PLATFORM.env?=           ${_path}/env
+.  endif
+.  if exists(${_path}/expr)
+TOOLS_PLATFORM.expr?=          ${_path}/expr
+.  endif
+.  if exists(${_path}/fgrep)
+TOOLS_PLATFORM.fgrep?=         ${_path}/fgrep
+.  endif
+.  if exists(${_path}/file)
+TOOLS_PLATFORM.file?=          ${_path}/file
+.  endif
+.  if exists(${_path}/find)
+TOOLS_PLATFORM.find?=          ${_path}/find
+.  endif
+.  if exists(${_path}/gettext)
+TOOLS_PLATFORM.gettext?=       ${_path}/gettext
+.  endif
+.  if exists(${_path}/m4)
+TOOLS_PLATFORM.m4?=            ${_path}/m4
+.  endif
+.  if exists(${_path}/make)
+TOOLS_PLATFORM.gmake?=         ${_path}/make
+.  endif
+.  if exists(${_path}/gawk)
+TOOLS_PLATFORM.gawk?=          ${_path}/gawk
+.  endif
+.  if exists(${_path}/grep)
+TOOLS_PLATFORM.grep?=          ${_path}/grep
+.  endif
+.  if exists(${_path}/groff)
+TOOLS_PLATFORM.groff?=         ${_path}/groff
+.  endif
+.  if exists(${_path}/sed)
+TOOLS_PLATFORM.sed?=           ${_path}/sed
+.  endif
+.  if exists(${_path}/soelim)
+TOOLS_PLATFORM.gsoelim?=       ${_path}/soelim
+.  endif
+.  if exists(${_path}/tar)
+TOOLS_PLATFORM.tar?=           ${_path}/tar
+.  endif
+.  if exists(${_path}/gunzip)
+TOOLS_PLATFORM.gunzip?=                ${_path}/gunzip -f
+.  endif
+.  if exists(${_path}/zcat)
+TOOLS_PLATFORM.gzcat?=         ${_path}/zcat
+.  endif
+.  if exists(${_path}/gzip)
+TOOLS_PLATFORM.gzip?=          ${_path}/gzip -nf ${GZIP}
+.  endif
+.  if exists(${_path}/head)
+TOOLS_PLATFORM.head?=          ${_path}/head
+.  endif
+.  if exists(${_path}/hostname)
+TOOLS_PLATFORM.hostname?=      ${_path}/hostname
+.  endif
+.  if exists(${_path}/id)
+TOOLS_PLATFORM.id?=            ${_path}/id
+.  endif
+.  if exists(${_path}/ident)
+TOOLS_PLATFORM.ident?=         ${_path}/ident
+.  endif
+.  if exists(${_path}/install)
+TOOLS_PLATFORM.install?=       ${_path}/install
+.  endif
+.  if exists(${_path}/install-info)
+TOOLS_PLATFORM.install-info?=  ${_path}/install-info
+.  endif
+.  if exists(${_path}/ldconfig)
+TOOLS_PLATFORM.ldconfig?=      ${_path}/ldconfig
+.  endif
+.  if exists(${_path}/ln)
+TOOLS_PLATFORM.ln?=            ${_path}/ln
+.  endif
+.  if exists(${_path}/ls)
+TOOLS_PLATFORM.ls?=            ${_path}/ls
+.  endif
+.  if exists(${_path}/mail)
+TOOLS_PLATFORM.mail?=          ${_path}/mail   # Debian, Slackware, SuSE
+.  endif
+.  if exists(${_path}/makeinfo)
+TOOLS_PLATFORM.makeinfo?=      ${_path}/makeinfo
+.  endif
+.  if exists(${_path}/mkdir)
+TOOLS_PLATFORM.mkdir?=         ${_path}/mkdir -p
+.  endif
+.  if exists(${_path}/mktemp)
+TOOLS_PLATFORM.mktemp?=                ${_path}/mktemp
+.  endif
+.  if exists(${_path}/msgconv)
+TOOLS_PLATFORM.msgconv?=       ${_path}/msgconv
+.  endif
+.  if exists(${_path}/msgfmt)



Home | Main Index | Thread Index | Old Index