How to add libudev.so.1 and liblua5.1.so to doublecmd

Hi there,

I’m currently trying to configure doublecmd the same way I was used to on Arch. I’m realizing that certain functionality seems to not be available (like doing a user mount of USB sticks or loading lua plugins).

Looking at the strace output it seems like doublecmd is looking for libudev.so.1 and liblua5.1.so at runtime in certain places and is obviously not finding it there:

openat(AT_FDCWD, "/nix/store/xg3ld3c3xip8fx9agx901r1bz3fmnchv-dbus-1.14.10-lib/lib/libudev.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/hbdl12ck2ibhn5zsi8nsfa6v471pf0j6-glib-2.78.4/lib/libudev.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/ga17mlfsss2fndyvp2s1m0s2rx2b4i9s-libX11-1.8.7/lib/libudev.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/prpjym9rnpd17326sk790m21h72fwran-libqt5pas-2.2.2-0/lib/libudev.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/cyrrf49i2hm1w7vn2j945ic3rrzgxbqs-glibc-2.38-44/lib/libudev.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/f5my15qww10swmf66ns13l24yp6j5dmq-xgcc-13.2.0-libgcc/lib/libudev.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/xg3ld3c3xip8fx9agx901r1bz3fmnchv-dbus-1.14.10-lib/lib/libudev.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/hbdl12ck2ibhn5zsi8nsfa6v471pf0j6-glib-2.78.4/lib/libudev.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/ga17mlfsss2fndyvp2s1m0s2rx2b4i9s-libX11-1.8.7/lib/libudev.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/prpjym9rnpd17326sk790m21h72fwran-libqt5pas-2.2.2-0/lib/libudev.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/cyrrf49i2hm1w7vn2j945ic3rrzgxbqs-glibc-2.38-44/lib/libudev.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/f5my15qww10swmf66ns13l24yp6j5dmq-xgcc-13.2.0-libgcc/lib/libudev.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

I’ve tried adding systemd and lua as buildInputs via an override but unfortunately that does not seem to help:

final: prev: {
  doublecmd = prev.doublecmd.overrideAttrs (finalAttrs: previousAttrs: {
    buildInputs = previousAttrs.buildInputs ++ [ final.systemd final.lua ];
  });
};

Does anyone have any pointer in the right direction? :slight_smile:

I managed to solve it using the following overlay:

final: prev: {
  doublecmd = let
      luaWithPackages = final.lua5_1.withPackages (ps: with ps; [
        # 'socket' module is needed by custom plugin
        luasocket
      ]);
    in prev.doublecmd.overrideAttrs (finalAttrs: previousAttrs: {
      # this will patch rpath of the doublecmd binary to include systemd and
      # lua library paths for loading runtime libraries using dlopen
      # see: https://nixos.org/manual/nixpkgs/stable/#setup-hook-autopatchelfhook
      runtimeDependencies = [ final.systemd luaWithPackages ];
      # additionally we need to make sure the lua interpreter knows where to look
      # for included modules. we do this by setting the LUA_PATH and LUA_CPATH
      # env vars for the doublecmd process
      postFixup = ''
        wrapProgram "$out/bin/doublecmd" \
          --prefix LUA_PATH ";" "${luaWithPackages}/share/lua/5.1/?.lua" \
          --prefix LUA_CPATH ";" "${luaWithPackages}/lib/lua/5.1/?.so"
      '';
      # to be able to use runtimeDependencies and wrapProgram we need to include
      # additional built time dependencies
      nativeBuildInputs = previousAttrs.nativeBuildInputs ++ [
        # needed for runtimeDependencies
        final.autoPatchelfHook
        # needed for wrapProgram
        final.makeWrapper
      ];
    });
};

Additionally I had to make sure that ~/.config/doublecmd/doublecmd.xml contains the correct name of the liblua library file:

<?xml version="1.0" encoding="UTF-8"?>
<doublecmd DCVersion="1.1.9 beta" ConfigVersion="15">
  [...]
  <Lua>
    <PathToLibrary>liblua.so.5.1</PathToLibrary>
  </Lua>
  [...]
</doublecmd>