111111 ln -svf $(type -P cardano-node)
112112 ln -svf $(type -P cardano-wallet)
113113 ln -svf $(type -P cardano-cli)
114- mkdir -p ${ BUILDTYPE } /
115- ${ let
116- # (TODO: investigate why – @michalrus)
117- sourceBUILDTYPE = "Release" ;
118- in ''
119- ln -svf $PWD/node_modules/usb/build/${ sourceBUILDTYPE } /usb_bindings.node ${ BUILDTYPE } /
120- ln -svf $PWD/node_modules/node-hid/build/${ sourceBUILDTYPE } /HID.node ${ BUILDTYPE } /
121- ln -svf $PWD/node_modules/node-hid/build/${ sourceBUILDTYPE } /HID_hidraw.node ${ BUILDTYPE } /
122- ln -svf $PWD/node_modules/usb-detection/build/${ sourceBUILDTYPE } /detection.node ${ BUILDTYPE } /
123- '' }
124114
125115 ${ pkgs . lib . optionalString ( nodeImplementation == "cardano" ) ''
126116 source <(cardano-node --bash-completion-script `type -p cardano-node`)
@@ -135,14 +125,51 @@ let
135125 ''
136126 }
137127 yarn install --frozen-lockfile
128+
129+ # Rebuild native modules for <https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules>:
130+ find Debug/ Release/ -name '*.node' | xargs rm -v || true
138131 yarn build:electron
132+
133+ ${ let
134+ # Several native modules have to be linked in ${BUILDTYPE}/ in
135+ # root directory, for `yarn dev` to work correctly. If a Debug
136+ # version of such extension exists, we use it, otherwise, we
137+ # use Release:
138+ tryLink = dependency : fileName : ''
139+ symlinkTarget=$(ls 2>/dev/null -d \
140+ "$PWD/node_modules/${ dependency } /build/Debug/${ fileName } " \
141+ "$PWD/node_modules/${ dependency } /build/Release/${ fileName } " \
142+ | head -1
143+ )
144+
145+ if [ -z "$symlinkTarget" ] ; then
146+ echo >&2 "error: symlink target not found: ‘${ fileName } ’ in ‘${ dependency } ’"
147+ # ~exit 1~ — do not exit, let the person fix from inside `nix-shell`
148+ fi
149+
150+ ${ localLib . optionalString pkgs . stdenv . isLinux ''
151+ ${ pkgs . patchelf } /bin/patchelf --set-rpath ${ pkgs . lib . makeLibraryPath [
152+ pkgs . stdenv . cc . cc pkgs . udev
153+ ] } "$symlinkTarget"
154+ '' }
155+
156+ mkdir -p ${ BUILDTYPE } /
157+ ln -svf "$symlinkTarget" ${ BUILDTYPE } /
158+ unset symlinkTarget
159+ '' ;
160+ in ''
161+ ${ tryLink "usb" "usb_bindings.node" }
162+ ${ tryLink "usb-detection" "detection.node" }
163+ ${ tryLink "node-hid" "HID.node" }
164+ ${ localLib . optionalString pkgs . stdenv . isLinux ''
165+ ${ tryLink "node-hid" "HID_hidraw.node" }
166+ '' }
167+ '' }
168+
139169 ${ localLib . optionalString pkgs . stdenv . isLinux ''
140- ${ pkgs . patchelf } /bin/patchelf --set-rpath ${ pkgs . lib . makeLibraryPath [ pkgs . stdenv . cc . cc pkgs . udev ] } ${ BUILDTYPE } /usb_bindings.node
141- ${ pkgs . patchelf } /bin/patchelf --set-rpath ${ pkgs . lib . makeLibraryPath [ pkgs . stdenv . cc . cc pkgs . udev ] } ${ BUILDTYPE } /HID.node
142- # TODO: is this needed for `detection.node`?
143- ${ pkgs . patchelf } /bin/patchelf --set-rpath ${ pkgs . lib . makeLibraryPath [ pkgs . stdenv . cc . cc pkgs . udev ] } ${ BUILDTYPE } /detection.node
144170 ln -svf ${ daedalusPkgs . electron } /bin/electron ./node_modules/electron/dist/electron
145171 '' }
172+
146173 echo 'jq < $LAUNCHER_CONFIG'
147174 echo debug the node by running debug-node
148175 '' ;
0 commit comments