Derivation not finding files in /etc

Hi,

I am working on my first real derivation, packaging vmware-player (see full derivation below, note that it is still very much a work in progress and is not entirely complete).
I can run nix-build and it builds the package, and it installs properly with nix-env -i -f vmware-player.nix. But when I try to run the binary vmplayer, but this instantly errors out with:

$ vmplayer
/home//.nix-profile/bin/vmplayer: line 15: /etc/vmware/bootstrap: No such file or directory

I try to provide the bootstrap file in the derivation, and it is put properly in the derivation in /nix/store/zvcqnyy0m1lnifx8chq94jnmzfcp3zlj-vmware-player-16.1.1-17801498 but since the file is in the derivation and not /etc it does not find it.

So, what is the correct way to make vmplayer find the /etc/vmware/bootstrap (or redirect)?

Also, if there is a better way to provide libgdbm.so.3 than my hack below I would appreciate the input.

{ pkgs ? import <nixpkgs> {}, ... }:
with pkgs;

let
  vmware-player-unpack-env = buildFHSUserEnv rec {
    name = "vmware-player-unpack-env";
    targetPkgs = pkgs: with pkgs; [ zlib ];
  };
  gdbm3 = stdenv.mkDerivation rec {
    pname = "gdbm3";
    version = "1.8.3";

    src = fetchurl {
      url = "mirror://gnu/gdbm/gdbm-${version}.tar.gz";
      sha256 = "sha256-zDQDOKLii0AFirnrU1SiHVP4ihWC6iG6C7GFw3ooHck=";
    };

    doCheck = true; # not cross;

    # Linking static stubs on cygwin requires correct ordering.
    # Consider upstreaming this.

    # Disable dbmfetch03.at test because it depends on unlink()
    # failing on a link in a chmod -w directory, which cygwin
    # apparently allows.
    postPatch = lib.optionalString stdenv.buildPlatform.isCygwin ''
        substituteInPlace tests/Makefile.in --replace \
          '_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la' \
          '_LDADD = ../compat/libgdbm_compat.la ../src/libgdbm.la'
        substituteInPlace tests/testsuite.at --replace \
          'm4_include([dbmfetch03.at])' ""
    '';

    enableParallelBuilding = true;
    configureFlags = [ "--enable-libgdbm-compat" ];

    installPhase = ''
      mkdir -p $out/lib
      cp .libs/libgdbm.so.3 $out/lib/
      cp .libs/libgdbm.so.3.0.0 $out/lib/
      cp .libs/libgdbm_compat.so.3 $out/lib/
      cp .libs/libgdbm_compat.so.3.0.0 $out/lib/
      '';

    # create symlinks for compatibility
    postInstall = ''
      install -dm755 $out/include/gdbm
      (
        cd $out/include/gdbm
        ln -s ../gdbm.h gdbm.h
        ln -s ../ndbm.h ndbm.h
        ln -s ../dbm.h  dbm.h
      )
    '';

    meta = with lib; {
      description = "GNU dbm key/value database library";
      longDescription = ''
         GNU dbm (or GDBM, for short) is a library of database functions that
         use extensible hashing and work similar to the standard UNIX dbm.
         These routines are provided to a programmer needing to create and
         manipulate a hashed database.
         The basic use of GDBM is to store key/data pairs in a data file.
         Each key must be unique and each key is paired with only one data
         item.
         The library provides primitives for storing key/data pairs,
         searching and retrieving the data by its key and deleting a key
         along with its data.  It also support sequential iteration over all
         key/data pairs in a database.
         For compatibility with programs using old UNIX dbm function, the
         package also provides traditional dbm and ndbm interfaces.
        '';
      homepage = "https://www.gnu.org/software/gdbm/";
      license = licenses.gpl3Plus;
      platforms = platforms.all;
      maintainers = [ maintainers.vrthra ];
    };
  };
  bzip2-compat = bzip2.overrideAttrs ( old: rec {
    postPhases = [ "linkCompatPhase" ];

    linkCompatPhase = ''
      ln -s $out/lib/libbz2.so.1.0.6 $out/lib/libbz2.so.1.0
      '';
  });
in
stdenv.mkDerivation rec {
  pname = "vmware-player";
  version = "16.1.1-17801498";

  buildInputs = [ bash libxslt libxml2 libuuid gdbm3 readline lzma bzip2-compat cups ];
  nativeBuildInputs = [ python3 sqlite vmware-player-unpack-env autoPatchelfHook ];

  src = fetchurl {
      url = "https://download3.vmware.com/software/player/file/VMware-Player-${version}.x86_64.bundle";
      name = "vmware-player-src";
      sha256 = "1zqha24s91al365afc6j0djrckkddhm476ypqp3mxqbkpiqim6nf";
  };

  vmwareBootstrapConfig = writeScript "vmware-bootstrap" ''
    PREFIX="/usr"
    BINDIR="/usr/bin"
    SBINDIR="/usr/sbin"
    LIBDIR="/usr/lib"
    DATADIR="/usr/share"
    SYSCONFDIR="/etc"
    DOCDIR="/usr/share/doc"
    MANDIR="/usr/share/man"
    INCLUDEDIR="/usr/include"
    INITDIR=""
    INITSCRIPTDIR="/usr/lib/systemd/scripts"
  '';

  unpackPhase = ''
    ${vmware-player-unpack-env}/bin/vmware-player-unpack-env -c "sh ${src} --extract unpacked"
  '';


  installPhase = ''
    # determine installer version
    local vmware_installer_version=$(cat "unpacked/vmware-installer/manifest.xml" | grep -oPm1 "(?<=<version>)[^<]+")

    echo $vmware_installer_version

    # Make install directories
    mkdir -p \
      $out/etc/cups \
      $out/etc/thnuclnt \
      $out/etc/vmware \
      $out/bin \
      $out/share \
      $out/lib/vmware \
      $out/lib/vmware-installer/$vmware_installer_version \
      $out/lib/vmware-ovftool \
      $out/lib/cups

    cp -r \
      unpacked/vmware-player-app/bin/* \
      unpacked/vmware-vmx/sbin/* \
      unpacked/vmware-vmx/bin/* \
      $out/bin

    cp -r \
      unpacked/vmware-player-app/etc/cups \
      $out/etc/cups

    cp -r \
      unpacked/vmware-player-app/extras/thnucups \
      $out/etc/cups/filter

    cp -r \
      unpacked/vmware-player-app/extras/.thnumod \
      $out/etc/thnuclnt

    cp -r \
      unpacked/vmware-vmx/extra/modules.xml \
      $out/etc/vmware/

    cp -r \
      unpacked/vmware-network-editor/lib/* \
      unpacked/vmware-player-app/lib/* \
      unpacked/vmware-player/lib/* \
      unpacked/vmware-vmx/lib/* \
      unpacked/vmware-vmx/roms \
      unpacked/vmware-usbarbitrator/bin \
      $out/lib/vmware

    # copy lib/vmware/setup
    cp -r \
      unpacked/vmware-player-setup/vmware-config \
      $out/lib/vmware/setup

    # copy lib/vmware-installer/VERSION
    cp -r \
      unpacked/vmware-installer/{python,sopython,vmis,vmis-launcher,vmware-installer,vmware-installer.py} \
      $out/lib/vmware-installer/$vmware_installer_version

    # copy lib/vmware-ovftool
    cp -r \
      unpacked/vmware-ovftool/* \
      $out/lib/vmware-ovftool

    cp -r \
      unpacked/vmware-player-app/share/* \
      $out/share

    chmod +x \
        $out/bin/* \
        $out/lib/vmware/bin/* \
        $out/lib/vmware/setup/* \
        $out/lib/vmware/lib/libvmware-gksu.so/gksu-run-helper \
        $out/lib/vmware-ovftool/{ovftool,ovftool.bin} \
        $out/lib/vmware-installer/$vmware_installer_version/{vmware-installer,vmis-launcher} \
        $out/lib/cups/filter/* \
        $out/lib/vmware-vix/setup/* \
        $out/etc/thnuclnt/.thnumod

    # create symlinks (replicate installer) - bin
    ln -s $out/lib/vmware/bin/vmware-usbarbitrator $out/bin/vmware-usbarbitrator

    # create symlinks (replicate installer) - misc
    ln -s $out/lib/vmware/bin/appLoader $out/bin/vmrest
    ln -s $out/lib/vmware/icu $out/etc/vmware/icu
    ln -s $out/lib/vmware-ovftool/ovftool $out/bin/ovftool

    # install licenses
    #ln -s $out/lib/vmware-ovftool/vmware.eula "$out/share/licenses/vmware-player-app/VMware OVF Tool - EULA.txt"
    #install -Dm 644 vmware-player-app/doc/open_source_licenses.txt "$out/share/licenses/vmware-player-app/VMware Player open source license.txt"
    #install -Dm 644 vmware-player-app/doc/ovftool_open_source_licenses.txt "$out/share/licenses/vmware-workstation/VMware OVF Tool open source license.txt"

    # install config files
    install -d -m 755 $out/lib/vmware-installer/$vmware_installer_version/{lib/lib,artwork}
    install -Dm 644 unpacked/vmware-vmx/extra/modules.xml $out/lib/vmware/modules/modules.xml
    install -Dm 644 unpacked/vmware-installer/bootstrap $out/etc/vmware-installer/bootstrap
    #install -Dm 644 $vmwareVixBootstrapConfig $out/etc/vmware-vix/bootstrap
    install -Dm 644 $vmwareBootstrapConfig $out/etc/vmware/bootstrap
    #install -Dm 644 $vmwareConfig $out/etc/vmware/config
    #install -Dm 644 $vmwareHostdConfig $out/etc/vmware/hostd/config.xml
    #install -Dm 644 $vmwareHostdDatastores $out/etc/vmware/hostd/datastores.xml
    #install -Dm 644 $vmwareHostdEnvironments $out/etc/vmware/hostd/environments.xml
    #install -Dm 644 $vmwareHostdProxy $out/etc/vmware/hostd/proxy.xml
    #install -Dm 644 $vmwareHostdVMAutostart $out/etc/vmware/hostd/vmAutoStart.xml
    #install -Dm 644 $vmwarePAMConfig $out/etc/pam.d/vmware-authd

    sed \
        -e "s,@@VERSION@@,$vmware_installer_version," \
        -e "s,@@VMWARE_INSTALLER@@,/usr/lib/vmware-installer/$vmware_installer_version," \
        -i $out/etc/vmware-installer/bootstrap
  '';
}

Patch this script to search at $out/... instead

Thank you, I did not realize that vmplayer was also a shell script :slight_smile: