Skip to main content

Set up your NixOS VPS

  • If you're doing this tutorial at the btc++ conference in Berlin on Friday, October 6, 2023, I've already set up a VPS for you to use in this workshop.
  • If you're doing this tutorial sometime later, you can use any NixOS machine. The config will be a bit different since the tutorial uses a config tailored to DigitalOcean. Reach out to me and I'll be happy to help you set it up :)
  • If you just want to do the same thing I did with terraform and morph, follow this excellent tutorial. The files I used for Terraform and Morph are included in the github repo for the current tutorial.

Exercise: Generate and switch to a new config

Get your ip address and log into it:

  • user: bitcoiner
  • password: btcpp
ssh bitcoiner@<your ip>

The following command will generate a new configuration.nix and hardware-configuration.nix for your system.

This command will spit out a warning: warning: not overwriting existing /etc/nixos/configuration.nix. You can safely ignore this warning.

We don't need the configuration.nix as we're replacing it in the next step. We just need hardware-configuration.nix.

sudo nixos-generate-config

Delete the automatically generated config and make a new one:

sudo rm /etc/nixos/configuration.nix
sudo vim /etc/nixos/configuration.nix

Then type i (for insert) and copy and paste this into the file:

{ modulesPath, lib, pkgs, ... }:
{
imports = lib.optional (builtins.pathExists ./do-userdata.nix) ./do-userdata.nix ++ [

# import the autogenerated `hardware-configuration.nix`
./hardware-configuration.nix

# import the digitalocean-specific settings
(modulesPath + "/virtualisation/digital-ocean-config.nix")
];

# Resolve a conflict between the DO-specific config and `hardware-configuration.nix`
fileSystems."/".device = lib.mkForce "/dev/disk/by-label/nixos";

# set the stateVersion
system.stateVersion = "23.11";

# enable flakes and nix commands
nix.extraOptions = "experimental-features = nix-command flakes";

# declare user `bitcoiner`
users.users.bitcoiner = {
isNormalUser = true;
description = "bitcoiner";

# feel free to change this or use an ssh key
# delete this if you only want SSH key access
password = "btcpp";

# here's how to set an SSH key:
# openssh.authorizedKeys.keys = [
# "<SSH key goes here>"
# ];

# Allow the `bitcoiner` user to use `sudo`
extraGroups = [ "wheel" ];

# install vim. I like it better than `nano`, but you can use either
packages = with pkgs; [
vim

# you'll want `jq` to parse your CLN node's command output
jq
];
};

# Configure OpenSSH
services.openssh = {

# Allow password authentication
settings.PasswordAuthentication = true;

# Lengthen the default SSH session timeout
# (The DO default is annoyingly short)
extraConfig = ''
ClientAliveInterval 120
ClientAliveCountMax 720
'';
};
}

Then hit ESCAPE (to exit insert mode) and type ZZ to save and exit vim

Now let's switch to the new config (same as the old config, but now you're editing it locally instead of me editing it remotely)

sudo nixos-rebuild switch

Now log out and log back in. Your password should still work, and this command should still work:

sudo vim /etc/nixos/configuration.nix

Type :q! then press ENTER to quit vim without saving.

  • Generate config
  • Edit it
  • Switch to the new config
  • Test config by running sudo vim /etc/nixos/configuration.nix

Now on to the more exciting part!