Start Daedalus with tmux to use cardano-cli

I thought, I’d share the Daedalus startup script (for Linux) I just wrote.

The idea was that, in order to play around a bit with the command line tools, I don’t need to compile and install them and I don’t need to run another cardano-node. All that is already contained in Daedalus.

The end result will look like:

In the upper left are the messages from Daedalus/cardano-node, on the right is the Daedalus interface and in the lower left I have a shell, where I can use cardano-cli and friends (for example to mint some NFTs or stuff like that).

This was inspired by the fact that the ~/.local/bin/daedalus-mainnet coming with Daedalus already allows to be run with DEBUG_SHELL=true daedalus-mainnet in order to not start the node and the GUI, but just a shell in the NixOS chroot, where all the parts of Daedalus including cardano-node, cardano-cli and cardano-wallet live.

Second inspiration was the Gist Use Daedalus socket for cardano-cli for Mainnet or Testnet the Cardano · GitHub showing how to connect cardano-cli to the cardano-node running inside Daedalus.

So, this my ~/bin/daedalus script:


# Exit immediately on non-zero status:
set -e

# In case the data directory is a broken symbolic link, ask user to mount:
if [ ! -e "${HOME}/.local/share/Daedalus" ]
    if [ -L "${HOME}/.local/share/Daedalus" ]
        target=$(readlink "${HOME}/.local/share/Daedalus")
        echo "Please mount data directory to ${target}."
        exit 1

# Export CARDANO_NODE_SOCKET_PATH to all tmux windows:

# The following is done in ~/.daedalus/:
cd ${HOME}/.daedalus/

# Prepare /etc for the nix chroot:
mkdir -p etc
cat /etc/hosts > etc/hosts
cat /etc/localtime > etc/localtime
cat /etc/machine-id > etc/machine-id
cat /etc/nsswitch.conf > etc/nsswitch.conf
cat /etc/passwd > etc/passwd
cat /etc/resolv.conf > etc/resolv.conf

# Parts of the nix chroot command:
mounts="-m /home:/home -m /etc:/host-etc -m etc:/etc -m /media:/media"

# Start daedalus in the first window of the tmux session:
tmux new -d -s daedalus "${chroot} -n ./nix -c -e ${mounts} ${envvars} -- ${phase2} daedalus"

# Open a chrooted shell in every new window in the tmux session:
tmux set -t daedalus default-command "${chroot} -n ./nix -c -e ${mounts} ${envvars} -- ${phase2} bash"
tmux split -t daedalus

# Attach to the configured session:
tmux attach -t daedalus

The first block dealing with ~/.local/share/Daedalus has nothing to do with this tmux idea, but is there, because my Daedalus data are on a USB stick and I want to be reminded to mount it.

Exporting CARDANO_NODE_SOCKET_PATH is the main idea to make the cardano-node run by Daedalus available to cardano-cli in other windows.

Changes with respect to ~/.local/bin/daedalus-mainnet in the execution of the chroot are that /etc/passwd is made available (avoiding the ugly “I have no name!” prompt), /media is mounted (because my data folder is on a USB stick that has to be available to cardano-node) and CARDANO_NODE_SOCKET_PATH is exported.

tmux is started with a new (new), detached (-d) session that is named daedalus (-s daedalus) and the Nix chroot is started in its first window to run the node and the GUI (done by calling enter-phase2 with daedalus). Then, tmux is configured so that every new window or pane also starts the Nix chroot, but opens a bash in it. Finally, the first window is split into two panes and the current terminal is attached to the session that we have configured.

If you don’t know tmux, the very, very short version is: new windows are opened with Ctrl-b followed by c, you can cycle through the open windows with Ctrl-b n (next) and Ctrl-b p (previous), a window or pane can be split into two panes by Ctrl-b % (vertically) or Ctrl-b " (horizontally) and you can navigate through the panes of a window by Ctrl-b followed by the arrow keys. With Ctrl-b d, you can detach from a session (but everything in it keeps running) and with tmux attach in any terminal window, you can reattach to that session (does also work if you accidentally closed the terminal window). But probably you will want to search a longer introduction that fits your learning habits.

Drawbacks of this solution:

  • This might break horribly on Daedalus updates. Especially the hardcoded, very specific nix-user-chroot package will probably change in the future and I have to observe ~/.local/bin/daedalus-mainnet for such changes. Simply calling it was unfortunately not an option because of the necessary changes to the mounts and environment variables given to the chroot.
  • The environment inside the chroot is pretty minimal. There is no less, no usable editor, no Python, really not much other than the Cardano command line tools and an absolutely minimal Linux userland around it. Editing of files and other more elaborate tasks have to be done in other terminals, but there the Cardano tools are not available.
  • The versions are a bit behind the bleeding edge, since they are the ones packaged with the latest Daedalus release and do not get updated until the next Daedalus release.
1 Like