summaryrefslogtreecommitdiff
path: root/Urbit/Ship.nix
blob: a82d880b7ec994edc597c83d28eddf1d571ad4c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{bild}:
# This represents a single ship running in a container.
let
  # bootstrap & startup process, expects two files:
  # - /ship.name: containing a ship name like 'sampel-palnet'
  # - /ship.key: containing the key
  urbit-start = bild.pkgs.writeScript "urbit-start" ''
    #!${bild.pkgs.runtimeShell}
    set -xeuo pipefail

    ship=$(cat /ship.name)
    pier="/$ship"

    if [ -d "$pier" ]; then
      # pack pier if it exists, to save space
      /bin/urbit-worker pack "$pier"
    else
      # otherwise, setup
      /bin/urbit -c "$pier" -k /ship.key -x
    fi

    /bin/urbit -tq "$pier"
  '';
in
  bild.image {
    name = "urbit-ship";
    tag = "latest";

    fromImage = null; # scratch

    contents = bild.pkgs.urbit;

    config = {
      Cmd = ["${urbit-start}"];
      WorkingDir = "/";
      Volumes = {"/" = {};};
    };
  }