Table of Contents
The installation is split in 3 major steps - A, B and C. Each individual step is split in parallel tracks and you should follow the one matching your setup.
Step A: Repository.
If you don’t have an existing repository, follow the A.1. bootstrapping method.
If you do have one, follow the A.2. Add in Existing Repo method.
Step B: Beacon. The installation can be done on:
A VM, which is provided by Skarabox.
An on-premise server, for which Skarabox provides an ISO file that you can install on a USB stick and boot from on your on-premise server
A cloud instance, which needs nothing special as you should be able to configure your cloud VM to have ssh access, for example by booting in rescue mode.
Step C. Finally, run the installer.
Following the installation procedure on a server WILL ERASE THE CONTENT of any disk on that server. Take the time to remove any disk you care about.
This will prepare a repository where Skarabox is configured.
Create a directory and download the template.
$ mkdir myskarabox
$ cd myskarabox
$ nix run github:ibizaman/skarabox?ref=v1.6.0#init
The #init command accepts arguments.
Use the -h argument to print them.
Don’t forget the double dash -- like so:
$ nix run github:ibizaman/skarabox?ref=v1.6.0#init -- -h
The #init command by default asks for the password you want for the admin user
and will generate all other secrets.
The hostname will be myskarabox and the files located
under the ./myskarabox folder.
All the files at the root of this new repository are common to all hosts.
It will finally ask you to fill out options in the main ./flake.nix file and in the ./myskarabox/configuration.nix file. Detailed instructions are shown in Step B.
For a concrete example, look at the commit history of this repo which shows how to add a host managed by Skarabox to a repository using nix-starter-configs.
Transform the outputs in a flake-parts module like outlined in the official tutorial.
In short, make your flake.nix look like the template one.
Create Sops main key file named sops.key, if you don’t have one already:
nix run .#sops-create-main-key.
Add Sops main key to Sops config file .sops.yaml:
nix run .#sops-add-main-key.
Create config for target host myskarabox in folder ./myskarabox:
nix run .#gen-new-host myskarabox.
Tweak ./myskarabox/configuration.nix to change for example the username. The username will also be used as the user in the beacon.
Continue with Step B.
Assuming the ./myskarabox/configuration.nix file is left untouched, you can now test the installation process on a VM. To do that, first we tweak some options for more sensible defaults for a VM:
skarabox.hosts.<name> = {
system = "x86_64-linux";
ip = "127.0.0.1";
};
Then, start the VM using the following command which will create a graphical window:
$ nix run .#myskarabox-beacon-vm &
If you would rather get the dmesg output in your terminal and use the VM from there, you can too but you will need to dedicate a terminal window for it as the VM will not be able to run in the background, like above.
$ nix run .#myskarabox-beacon-vm -- -nographic
For info, this VM has 4 hard drives:
/dev/nvme0
/dev/nvme1
/dev/sda
/dev/sdb
Now, skip to step C.
This guide assumes you know how to boot your server on a USB stick. Usually this involves opening your computer’s BIOS and selecting the USB stick.
The beacon can either connect to the local network
and/or setup its own WiFi hotspot with SSID Skarabox.
Connecting to the beacon will thus depend on the chosen method.
Choose either DHCP or static IP configuration.
In ./myskarabox/configuration.nix, set the configuration of the server. The default is DHCP:
skarabox.staticNetwork = null;
To setup a static IP, replace the null value with something like:
skarabox.staticNetwork = {
ip = "192.168.1.30";
gateway = "192.168.1.1";
}
The same configuration will be used in the beacon.
Modify the ssh ports if needed.
In ./myskarabox/configuration.nix, set the ssh ports the OpenSSH server will listen on. The default is:
skarabox = {
sshPort = 2222;
boot.sshPort = 2223;
}
In ./flake.nix, set the ssh ports that will be used to connect to the server. The default is the same as above:
skarabox.hosts.<name> = {
sshPort = 2222;
sshBootPort = 2223;
}
Usually, they should be the same, but if you access the server through a router with port forwarding, they can differ.
Setup system in the ./flake.nix.
skarabox.hosts.<name> = {
system = "x86_64-linux";
}
Create the .iso file.
$ nix build .#myskarabox-beacon
Copy the .iso file to a USB key. This WILL ERASE THE CONTENT of the USB key.
$ nix run .#beacon-usbimager
Select ./result/iso/beacon.iso file in row 1 (...).
Select USB key in row 3.
Click write (arrow down) in row 2.
Plug the USB stick in the server. Choose to boot on it.
You will be logged in automatically with the user skarabox.username.
Setup IP to reach the server in ./flake.nix.
If a static IP was used, it will be the same as the one in skarabox.staticNetwork.ip.
If DHCP was used, first find the IP given to the beacon
by following the steps that appeared when booting on the USB stick.
To reprint the steps, run the command skarabox-help.
For example, if the IP is 192.168.1.30:
skarabox.hosts.<name> = {
ip = "192.168.1.30";
}
It is also possible to use a hostname as long as it can resolve to the correct IP, for example if you set up your ssh config accordingly.
Open the various files just to see if everything looks good.
No need for the beacon here. You just need to start the instance and enable ssh access. The easiest is usually to boot in rescue mode.
Retrieve the IP of the server, then update the values in the flake.nix file:
skarabox.hosts.<name> = {
system = "x86_64-linux";
ip = "12.34.56.78";
}
Update the beacon options to be able to ssh into the instance,
with the values given by your cloud provider:
skarabox.hosts.<name>.beacon = {
username = "<given by cloud provider>";
sshPort = "<given by cloud provider>";
sshPrivateKeyPath = "<given by cloud provider>";
sshPublicKeyPath = "<given by cloud provider>";
}
(Optional) Get into NixOS installer
This step is only needed if the beacon is not a NixOS system, like a cloud instance in rescue mode. It you’re not sure, it doesn’t hurt to run it even on a NixOS system.
$ nix run .#myskarabox-install-on-beacon -- --phases kexec
Test ssh to beacon
Test the ssh connection with:
$ nix run .#myskarabox-ssh-beacon
Set verbose mode if something goes wrong with:
$ nix run .#myskarabox-ssh-beacon -- -v
Upon rebooting the beacon, a new host key is generating leading to the message saying there might be a man in the middle attack. This warning can be dismissed when connecting to the beacon.
This is not the case for the target host after installation. The ssh host key will not change after a reboot. Getting the warning a that time must be investigated and not blindly dismissed.
Print the disk layout
$ nix run .#myskarabox-ssh-beacon -- sudo fdisk -l
$ nix run .#myskarabox-ssh-beacon -- lsblk
Set the options skarabox.disks in ./myskarabox/configuration.nix accordingly.
Generate target host hardware configuration
Generate a ./myskarabox/facter.json file containing
the hardware specification of the host (or the VM) with:
$ nix run .#myskarabox-get-facter > ./myskarabox/facter.json
Add the ./myskarabox/facter.json to git (run git add ./myskarabox/facter.json).
Do not forget this step otherwise the report will not be taken into account.
Optionally, if you want to see exactly what nixos-facter did find
and will configure, run one or both of:
$ nix run .#myskarabox-debug-facter-nix-diff
$ nix run .#myskarabox-debug-facter-nvd
Generate the known hosts file:
$ nix run .#myskarabox-gen-knownhosts-file
Redo this step if any of the ssh port or IP under the flake skarabox.hosts.<name> option changes.
Note that the host key generated by Skarabox is not used in the beacon so it is expected for the steps in this section to not care about it.
Run the installer
Now, run the installation process on the target host:
$ nix run .#myskarabox-install-on-beacon
:::{.info} If the command fails by not being able to ssh into the beacon, then the issue might be because your ssh agent is interfering. If that is the case, run the command as so:
$ SSH_AUTH_SOCK= nix run .#myskarabox-install-on-beacon
:::
Additional flags can be added like:
$ nix run .#myskarabox-install-on-beacon -- -h
$ nix run .#myskarabox-install-on-beacon -- --debug
The server will reboot into NixOS on its own. Upon booting, the root partition will need to be decrypted as outlined in the Normal Operations section. But first, read the next section.
These items act as a checklist that you should go through to make sure your installation is robust. How to proceed with each item is highly dependent on which hardware you have so it is hard for Skarabox to give a detailed explanation here.
Get your external IP Address by connecting to your home network and going to https://api.ipify.org/.
Buy a cheap domain name. I recommend https://porkbun.com/ because I use it and know it works but others work too.
Configure the domain’s DNS entries to have:
A record: Your domain name to your external IP Address.
A record: * (yes, a literal “asterisk”) to your external IP Address.
To check if this setup works, you will first need to go through the step below too.
These items should happen on your router.
Usually, connecting to it is done by entering one of the following IP addresses in your browser: 192.168.1.1 or 192.168.1.254.
Reduce the DHCP pool to the bounds .100 to .200, inclusive. This way, you are left with some space to statically allocate some IPs.
Statically assign the IP address of the server. Router usually allow to “pin” a lease. This is not needed if the IP was set statically above.
Enable port redirection for ports to the server IP:
80 to 80.
443 to 443.
skarabox.sshPort to skarabox.sshPort (default 2222) to be able to ssh into your server from abroad.
skarabox.sshBootPort to skarabox.sshBootPort 2223 to be able to start the server from abroad.
To check if this setup works,
you can connect to another network (like using the tethered connection from your phone or connecting to another WiFi network)
and then ssh into your server like shown in the Normal Operations section,
but instead of using the IP address, use the domain name in skarabox.hosts.<name>.ip.
I do recommend using the sibling project SelfHostBlocks to setup services like Vaultwarden, Nextcloud and others.
The flake template is wired to use SelfHostBlocks already.