Skip to content

Instantly share code, notes, and snippets.

@DeedleFake
Last active April 26, 2024 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeedleFake/19247c95171be2a511de31e17b5e652d to your computer and use it in GitHub Desktop.
Save DeedleFake/19247c95171be2a511de31e17b5e652d to your computer and use it in GitHub Desktop.
Livebook Setup with livebook:// URL Support on Linux

A Quick Guide to Setting up Livebook with Support for livebook:// URLs on Linux

Note that the following steps are intended as a rough outline. They are exact steps to replicate my setup, but your setup might differ depending on, for example, using an init system other than systemd or various other factors. Adjust as necessary.

  1. Run docker volume create livebook-data and docker volume create livebook-config.
  2. Place the livebook.service file in $HOME/.config/systemd/user.
  3. Run systemctl --user enable --now livebook.service.
  4. Place the dev.livebook.Livebook.desktop file in $HOME/.local/share/applications.
  5. Place the dev.livebook.Livebook.svg file in $HOME/.local/share/icons/hicolor/scalable/apps.
  6. Place the livebook file somewhere in your $PATH. In my case, I put it in $HOME/.local/bin.
  7. Run chmod a+x <path to file from step 6>.
  8. Run xdg-mime default dev.livebook.Livebook.desktop x-scheme-handler/livebook.
  9. Place the livebook-daemon file somewhere. I put it in my path, but it doesn't have to be.
  10. Run chmod a+x <path to file from step 9>.
  11. Modify livebook.service so that the ExecStart= line has the absolute path to the location of livebook-daemon.

Voila. livebook:// URLs should now work.

[Desktop Entry]
Type=Application
Name=Livebook
Exec=livebook %u
Icon=dev.livebook.Livebook
StartupNotify=false
MimeType=x-scheme-handler/livebook;
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env elixir
Mix.install([
{:jason, "~> 1.4"}
])
{container_info, 0} = System.cmd("docker", ["inspect", "livebook"])
[%{"HostConfig" => %{"PortBindings" => %{"8080/tcp" => [%{"HostPort" => port}]}}}] =
Jason.decode!(container_info)
suffix =
case System.argv() do
["livebook://" <> _ = url] ->
url = %URI{URI.parse(url) | scheme: "https"} |> URI.to_string()
"/import?#{%{url: url} |> URI.encode_query()}"
_ ->
""
end
{_, 0} = System.cmd("xdg-open", ["http://localhost:#{port}#{suffix}"])
#!/usr/bin/env bash
iframe_port="$(elixir -e '
{:ok, socket} = :socket.open(:inet, :stream)
:ok = :socket.bind(socket, %{family: :inet, port: 0, addr: :loopback})
{:ok, %{port: iframe_port}} = :socket.sockname(socket)
:ok = :socket.close(socket)
IO.write(iframe_port)
')"
exec docker run \
--init \
--rm \
--name livebook \
--replace \
--hostname livebook \
-e LIVEBOOK_TOKEN_ENABLED=false \
-e LIVEBOOK_IFRAME_PORT=${iframe_port} \
-v livebook-data:/data \
-v livebook-config:/home/livebook/.local/share/livebook \
-p 127.0.0.1::8080 \
-p 127.0.0.1:${iframe_port}:${iframe_port} \
--pull newer \
ghcr.io/livebook-dev/livebook
[Unit]
Description=Livebook
[Service]
ExecStart=/path/to/livebook-daemon
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment