Library problem at making derivation/compilation of Linux package source code

I am trying to setup a NIXOS server as NIS server.

ypbind-mt, ypserv and yp-tools seem to be minumum under Linux, if I understand the system correctly. But unfortunately only ypbind-mt has been ported.

So I started working on ypserve.

I did some research and if I understand the circumstances correctly, the most fitting way would be to turn the Linux package’s source code into a NixOS package by making a derivation that compiles the source code to be fitting with NixOS.

But I struggle getting

#include <rpcsvc/yp_prot.h>

to work.

I am not sure if I have been correct at choosing the NixOS package rpcsvc-proto as source for this incluse. Should I have used glibc? Or is there an other better fitting one?

Is my compilation configuration correct?

Or is my error somewhere else?

I have been searching for some time, but now I am entirely stuck at this #include problem.

Here the relevant files:

Excerpts from configuration.nix

  [...]  
  
  # Use latest kernel.
  boot.kernelPackages = pkgs.linuxPackages_latest;

  [...]  

  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
    wget
    gedit
    
    # Recommended for develoment, e.g. code search:
    git ripgrep
    nix-index
    
    # Compiler:
    gcc

    # libraries
    gdbm
    #rpclib
    libtirpc # rpc
    rpcsvc-proto
    glibc#.dev
    (glibcLocales.override { locales = [ "en_US.UTF-8" ]; })

    ypbind-mt
    #Not directly possible:
    #ypserv
    #yp-tools
  ];

  [...]

  system.stateVersion = "25.11";

}

In the folder ypserv (it is for the files that I use to make the derivation):

default.nix:

# default.nix
let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in
{
  ypserv = pkgs.callPackage ./ypserv.nix { };
}

ypserv.nix:

# ypserv.nix
{
  stdenv,
  fetchFromGitHub,
  fetchzip, 
  gdbm, 
  #gcc, # Doesn't seem to be necessary.
  libtirpc,
  rpcsvc-proto
}:

stdenv.mkDerivation {
  pname = "ypserv";
  version = "4.2";

  #src = fetchFromGitHub {
  #  owner = "thkukuk";
  #  repo = "ypserv";
  #  rev = "4.2";
  #  sha256 = "sha256-qio4zCbOj8VjSPkP5oxI07GOd2WTLmGq2d72gZpOjXY=";
  #};
  
  src = fetchzip {
    url = "https://github.com/thkukuk/ypserv/releases/download/v4.2/ypserv-4.2.tar.xz";
    sha256 = "sha256-hUr1RKLSyEaitOJ7CBgKnVIDew97tkNnEk3uojrcHag=";
  };
  
  # NixOS counter part for "./configure CFLAGS=-I/usr/include/tirpc" under Linux
  
  # Ensure the compiler finds the headers
  NIX_CFLAGS_COMPILE = "-I${libtirpc.dev}/include/tirpc"; # Needed for #include <rpc/rpc.h>
  
  # How to get #include <rpcsvc/yp_prot.h> working?
  
  # Ensure the linker finds the library
  #NIX_LDFLAGS = "-ltirpc"; # Seems not to be necessary if libtirpc is listed in nativeBuildInputs
  
  nativeBuildInputs = [
    libtirpc
    rpcsvc-proto
    #pkg-config # Often needed to find headers
  ];
  
  buildInputs = [
    gdbm
    #gcc
    libtirpc
    rpcsvc-proto
  ];

}

Console command and output:

[servertestuser5@nixos:~/packaging_existing_software/ypserv]$ nix-build -A ypserv
unpacking 'https://github.com/NixOS/nixpkgs/tarball/nixos-24.05' into the Git cache...
this derivation will be built:
  /nix/store/wf8680ykmgc2vawq2fz2dr72dnbdq4dw-ypserv-4.2.drv
building '/nix/store/wf8680ykmgc2vawq2fz2dr72dnbdq4dw-ypserv-4.2.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/hjf5na4iyr50dcwf8qg989wcbr0242iq-source
source root is source
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
patching script interpreter paths in ./configure
./configure: interpreter directive changed from "#! /bin/sh" to "/nix/store/1jzhbwq5rjjaqa75z88ws2b424vh7m53-bash-5.2p32/bin/sh"
configure flags: --disable-dependency-tracking --prefix=/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2
checking for a BSD-compatible install... /nix/store/n9gh8gxx5xx51ihgll2l20ar9b2vmgzy-coreutils-9.5/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /nix/store/n9gh8gxx5xx51ihgll2l20ar9b2vmgzy-coreutils-9.5/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... none
checking for library containing strerror... none required
checking how to run the C preprocessor... gcc -E
checking whether make sets $(MAKE)... (cached) yes
checking for ranlib... ranlib
checking for grep that handles long lines and -e... /nix/store/8nss7h1yk4jihkmr4xj5ihrbdkv4y1wy-gnugrep-3.11/bin/grep
checking for egrep... /nix/store/8nss7h1yk4jihkmr4xj5ihrbdkv4y1wy-gnugrep-3.11/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for __attribute__... yes
checking for -fpie... yes
checking whether byte ordering is bigendian... no
checking size of long... 8
checking for mawk... no
checking for gawk... /nix/store/jziybc6yn78sf0bbh0kmmx50bxjsnr15-gawk-5.2.2/bin/gawk
checking for bash... /nix/store/1jzhbwq5rjjaqa75z88ws2b424vh7m53-bash-5.2p32/bin/bash
checking for gmake... no
checking for make... /nix/store/0554jm1l1qw1pcfqsliw91hnifn11w8m-gnumake-4.4.1/bin/make
checking for aliases... /etc/mail/aliases
checking for --with-dbmliborder... 
checking for gdbm_open in -lgdbm... yes
checking for crypt in -lcrypt... no
checking crypt.h usability... no
checking crypt.h presence... no
checking for crypt.h... no
checking for pkg-config... no
checking for libnsl... no
checking for yp_match in -lnsl... no
checking for libtirpc... no
checking for getrpcport... no
checking for rpcb_getaddr... no
checking for libsystemd >= 209... no
checking for res_gethostbyname in -lresolv... no
checking for gethostbyname in -lresolv+... no
checking for xsltproc... no
checking for xmllint... /bin/true
checking for XML catalog (/etc/xml/catalog)... not found
checking for xmlcatalog... no
checking for DocBook XML DTD V4.3 in XML catalog... not found
checking for DocBook XSL Stylesheets in XML catalog... not found
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating lib/Makefile
config.status: creating etc/Makefile
config.status: creating ypserv/Makefile
config.status: creating ypxfr/Makefile
config.status: creating yppush/Makefile
config.status: creating makedbm/Makefile
config.status: creating mknetid/Makefile
config.status: creating revnetgroup/Makefile
config.status: creating rpc.yppasswdd/Makefile
config.status: creating rpc.ypxfrd/Makefile
config.status: creating yphelper/Makefile
config.status: creating scripts/Makefile
config.status: creating scripts/ypxfr_1perhour
config.status: creating scripts/ypxfr_1perday
config.status: creating scripts/ypxfr_2perday
config.status: creating scripts/pwupdate
config.status: creating scripts/create_printcap
config.status: creating scripts/match_printcap
config.status: creating scripts/ypinit
config.status: creating scripts/ypMakefile
config.status: creating config.h
config.status: executing depfiles commands

Configuration:

  Source code location:   .
  Compiler:               gcc
  Compiler flags:         -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes
  Preprocessor:           gcc -E
  Preprocessor flags:     
  Libraries:               -lgdbm    
  Awk:                    /nix/store/jziybc6yn78sf0bbh0kmmx50bxjsnr15-gawk-5.2.2/bin/gawk
  Shell:                  /nix/store/1jzhbwq5rjjaqa75z88ws2b424vh7m53-bash-5.2p32/bin/bash
  NIS map dir:            /var/yp
  Install path prefix:    /nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2
  Install ypserv.conf in:  /nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc
  Allow root password:     yes
  Use FQDN as master name: 1
  Notify systemd:          0

Running phase: buildPhase
build flags: SHELL=/nix/store/1jzhbwq5rjjaqa75z88ws2b424vh7m53-bash-5.2p32/bin/bash
/nix/store/0554jm1l1qw1pcfqsliw91hnifn11w8m-gnumake-4.4.1/bin/make  all-recursive
make[1]: Entering directory '/build/source'
Making all in etc
make[2]: Entering directory '/build/source/etc'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/build/source/etc'
Making all in lib
make[2]: Entering directory '/build/source/lib'
gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o log_msg.o log_msg.c
gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o ypserv_conf.o ypserv_conf.c
gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o ypxfrd_xdr.o ypxfrd_xdr.c
gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o ypproc_match_2.o ypproc_match_2.c
In file included from ypproc_match_2.c:22:
yp.h:10:10: fatal error: rpcsvc/yp_prot.h: No such file or directory
   10 | #include <rpcsvc/yp_prot.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:603: ypproc_match_2.o] Error 1
make[2]: Leaving directory '/build/source/lib'
make[1]: *** [Makefile:394: all-recursive] Error 1
make[1]: Leaving directory '/build/source'
make: *** [Makefile:335: all] Error 2
error: Cannot build '/nix/store/wf8680ykmgc2vawq2fz2dr72dnbdq4dw-ypserv-4.2.drv'.
       Reason: builder failed with exit code 2.
       Output paths:
         /nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2
       Last 25 log lines:
       >
       > Running phase: buildPhase
       > build flags: SHELL=/nix/store/1jzhbwq5rjjaqa75z88ws2b424vh7m53-bash-5.2p32/bin/bash
       > /nix/store/0554jm1l1qw1pcfqsliw91hnifn11w8m-gnumake-4.4.1/bin/make  all-recursive
       > make[1]: Entering directory '/build/source'
       > Making all in etc
       > make[2]: Entering directory '/build/source/etc'
       > make[2]: Nothing to be done for 'all'.
       > make[2]: Leaving directory '/build/source/etc'
       > Making all in lib
       > make[2]: Entering directory '/build/source/lib'
       > gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o log_msg.o log_msg.c
       > gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o ypserv_conf.o ypserv_conf.c
       > gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o ypxfrd_xdr.o ypxfrd_xdr.c
       > gcc -DHAVE_CONFIG_H -D_REENTRANT=1 -DCONFDIR=\"/nix/store/1vmr70c5hfpih640q5jmbvg0bbdnd6gd-ypserv-4.2/etc\" -DYPMAPDIR=\"/var/yp\" -DUSE_SD_NOTIFY=0 -I. -I..  -I.. -I.. -I.  -fpie   -Werror -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes -c -o ypproc_match_2.o ypproc_match_2.c
       > In file included from ypproc_match_2.c:22:
       > yp.h:10:10: fatal error: rpcsvc/yp_prot.h: No such file or directory
       >    10 | #include <rpcsvc/yp_prot.h>
       >       |          ^~~~~~~~~~~~~~~~~~
       > compilation terminated.
       > make[2]: *** [Makefile:603: ypproc_match_2.o] Error 1
       > make[2]: Leaving directory '/build/source/lib'
       > make[1]: *** [Makefile:394: all-recursive] Error 1
       > make[1]: Leaving directory '/build/source'
       > make: *** [Makefile:335: all] Error 2
       For full logs, run:
         nix-store -l /nix/store/wf8680ykmgc2vawq2fz2dr72dnbdq4dw-ypserv-4.2.drv


Try rpcsvc-proto.dev instead of rpcsvc-proto in your nativeBuildInputs.

Thank you, but unfortunately the process still fails at this include.

But still thank you very much.

Maybe I also have to add something to NIX_CFLAGS_COMPILE.
I tried -I${rpcsvc-proto.dev}/include/rpcsvc-proto and -I${rpcsvc-proto.dev}/include/rpcsvc, but neither solve the problem.

Perhaps I should take a look at cross compilation fur NixOS under Linux.
If I remember correctly, then I could have an easier time finding (and including) missing libraries there.

The rpcsvc-proto package simply doesn’t include that header.

See package contents...
~> nix build 'nixpkgs#rpcsvc-proto^*' --no-link --print-out-paths
/nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev
/nix/store/bxx45k7c0xn86y1sm46m1qjkj25i5aaz-rpcsvc-proto-1.4.4-man
/nix/store/bisrjrzizba7bw1yajbk57hih5zvzynh-rpcsvc-proto-1.4.4
~> ls /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/
                                                name                                                  type    size       modified
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/bootparam_prot.h   file    3.1 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/bootparam_prot.x   file    3.1 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/key_prot.h         file    6.7 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/key_prot.x         file    6.5 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/klm_prot.h         file    3.2 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/klm_prot.x         file    3.7 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/mount.h            file    3.8 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/mount.x            file    4.6 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/nfs_prot.h         file   11.4 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/nfs_prot.x         file    7.9 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/nlm_prot.h         file    9.3 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/nlm_prot.x         file    4.9 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rex.h              file    5.2 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rex.x              file    7.4 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rquota.h           file    2.2 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rquota.x           file    1.5 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rstat.h            file    4.0 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rstat.x            file    4.0 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rusers.h           file    3.2 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/rusers.x           file    5.8 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/sm_inter.h         file    3.1 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/sm_inter.x         file    3.7 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/spray.h            file    1.8 kB   56 years ago
 /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/spray.x            file    2.5 kB   56 years ago

I imagine a build flag for it is missing, or maybe the package needs to be updated or something.


While I’m here, let’s fix some misconceptions and issues with your code:

Yeah, so, don’t use 3 year old software please. Using fetch* functions without a hash also results in brokenness and constant rebuilds. Just… Don’t. If a tutorial or blog tells you to do this, close that browser tab and ignore everything the author says about nix from now on

Except for https://nix.dev, there is an open issue about removing this silliness from there too.

Change your default.nix to:

{ pkgs ? import <nixpkgs> { } }: {
  ypserv = pkgs.callPackage ./ypserv.nix { };
}

If you wish to pin your inputs instead of using channels, use npins or flakes.

Indeed. stdenv.mkDerivation includes gcc by default; It’s necessary for building pretty much all software. You can find what stdenv includes in the nixpkgs manual.

I would recommend strongly against putting development libraries and tools (compilers, etc.) in configuration.nix. They won’t work there anyway most of the time.

Use a devshell with nix-shell or nix shell, and specify the dev utilities you need with pkgs.mkShell, e.g.:

# shell.nix
#
# Put this in a directory and start it by running `nix-shell` in a terminal
{ pkgs ? import <nixpkgs> { } }: pkgs.mkShell {
  # Note the *packages* here; for `mkShell`, please don't use
  # `buildInputs`, even if you see tutorials suggesting it.
  packages = [
    gdbm
    # rpclib
    libtirpc
    rpcsvc-proto
  ];
}

Overriding the glibc locale with that override and placing it in environment.systemPackages or a devshell will most probably not work, because you end up using the gcc from stdenv, not whatever you put there, and that will depend on another glibcLocales.

I’m guessing you anyway don’t know why you’re setting this in the first place; Just don’t do it, or if you figure out why you’re setting it and decide that you really need to, dig into the stdenv code to see how to override that properly. But overriding toolchains is a very advanced thing to be doing, not just in the nix world; I doubt you need this to build a random package.

mkDerivation uses the .dev output for buildInputs. Besides, in nativeBuildInputs you actually want the bin output, not the dev output, because the packages set in nativeBuildInputs are intended to be executed, not linked against. This advice doesn’t make sense.

This is unnecessary. stdenv.mkDerivation automatically does something equivalent to this for all packages you add to buildInputs.

1 Like

That’s a nifty trick I didn’t know about! (I’m not sure I like that though; it also automatically injects .dev if you put it in nativeBuildInputs as well. I don’t think stdenv should be effectively hiding the package split detail from new packagers.) I suggested using .dev because .dev might include the header file they’re missing. It’s not clear that they would necessarily also need to run the one binary the package provides, the configure script doesn’t check for it. The packages in nativeBuildInputs are simply the ones meant to be used at build time but not runtime, so the .dev output would still be needed in it (possibly automatically), possibly in conjunction with the .out output.

So, yp_prot.h isn’t even in the upstream GitHub repository for rpcsvc-proto/rpcsvc at master · thkukuk/rpcsvc-proto · GitHub. The package you’re actually looking for might be libnsl. rpcsvc/yp_prot.h is in its .dev output, and ypserv’s configure script looks for libnsl.so.

That’s precisely the point; you should never think about the package split. It’s unnecessary to even know you can access the split outputs separately; the builders and module options use the correct outputs as appropriate.

The abstraction is useful, because it allows fledgling packagers to write correct, minimal packages without having to fully understand the difference between the outputs, especially between different ecosystems.

Wow, thank you very much to all of you!
All of this is very interesting!

~> nix build ‘nixpkgs#rpcsvc-proto^*’ --no-link --print-out-paths /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev /nix/store/bxx45k7c0xn86y1sm46m1qjkj25i5aaz-rpcsvc-proto-1.4.4-man /nix/store/bisrjrzizba7bw1yajbk57hih5zvzynh-rpcsvc-proto-1.4.4

~> ls /nix/store/g8cff7prvkydv2wkfz1908a4cmp5akpj-rpcsvc-proto-1.4.4-dev/include/rpcsvc/

I read something like this one time, but couldn’t find it again! Thank you!

While I’m here, let’s fix some misconceptions and issues with your code:

Yeah, so, don’t use 3 year old software please. Using fetch* functions without a hash also results in brokenness and constant rebuilds. Just… Don’t. If a tutorial or blog tells you to do this, close that browser tab and ignore everything the author says about nix from now on

Except for https://nix.dev, there is an open issue about removing this silliness from there too.

Change your default.nix to:

{ pkgs ? import <nixpkgs> { } }: {
  ypserv = pkgs.callPackage ./ypserv.nix { };
}

This is something I got wrong from a tutorial I looked up, because I found different approaches, which in turn confused me. The old tutorials are also causing some otherr problems
Thank you very much for the clarification and the better example!

Indeed. stdenv.mkDerivation includes gcc by default; It’s necessary for building pretty much all software. You can find what stdenv includes in the nixpkgs manual.

This is partly because of some time in which I was compiling something in a different Linux distribution (the gcc-Compiler was necessary, so kinda old habit) and partly because stdenv.mkDerivation wasn’t recognized. During a test compilation run I read a feedback message listing software to use for compiling the code. gdbm or GNU dbm is my choice for that.

I would recommend strongly against putting development libraries and tools (compilers, etc.) in configuration.nix. They won’t work there anyway most of the time.

Use a devshell with nix-shell or nix shell, and specify the dev utilities you need with pkgs.mkShell, e.g.:

# shell.nix
#
# Put this in a directory and start it by running `nix-shell` in a terminal
{ pkgs ? import <nixpkgs> { } }: pkgs.mkShell {
  # Note the *packages* here; for `mkShell`, please don't use
  # `buildInputs`, even if you see tutorials suggesting it.
  packages = [
    gdbm
    # rpclib
    libtirpc
    rpcsvc-proto
  ];
}

Oh, that’s the story behind the nix-shell or nix shell scripts!
And thank you very much, again!

So, yp_prot.h isn’t even in the upstream GitHub repository for rpcsvc-proto/rpcsvc at master · thkukuk/rpcsvc-proto · GitHub . The package you’re actually looking for might be libnsl. rpcsvc/yp_prot.h is in its .dev output, and ypserv’s configure script looks for libnsl.so.

The whole situation with the libraries, their names, what they contain and what not under NixOS…

Thanks for the library and for pointing it out in the config!
I overlooked it.

Edit: Now the compilation progresses further!
All of you, thank you very much!