Skip to content

About

Reusable NixOS modules and home-manager bundles for a bitcoin developer workstation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

nix-dev-server

NixOS modules and an installer for Bitcoin developer servers on Hetzner bare metal.

Status: alpha. The module options may change.

Contents

Output Description
packages.<system>.init Interactive installer. Runs on the developer's laptop.
nixosModules.default Workstation preset with home-manager and nixvim.
nixosModules.workstation Workstation preset without home-manager.
nixosModules.hetzner-bare-metal Bootloader and networking settings for Hetzner bare metal.
homeModules.nixvim nixvim editor configuration.
devShells.<system>.bitcoin-core Bitcoin Core development shell (x86_64-linux, aarch64-darwin).
templates.default Server repository scaffold, used by init.
templates.bitcoin-core Bitcoin Core dev-shell scaffold.

The workstation preset provides:

  • Tools: compilers, debuggers, gh, claude-code, codex and similar developer tools.
  • Shell setup: git, tmux, starship, direnv and zoxide.
  • Services: guix, mosh and rootless docker.
  • Memory: zram with earlyoom.
  • Housekeeping: automatic nix store cleanup.
  • SSH: a hardened sshd with SSH and GPG agent forwarding.

Onboarding a developer

Requirements

Who Needs
Admin Hetzner Robot access to the server.
Developer macOS or Linux laptop.
Nix with flakes enabled.
An SSH key loaded in ssh-agent.
Optional: a GPG key and a graphical pinentry, for commit signing on the server. See Commit signing.

Nothing is built on the laptop. The system is built on the server.

1. Admin: boot the rescue system

  1. In Robot, open the server.
  2. Rescue tab: choose Linux, 64 bit, select the developer's SSH key and activate.
    • Add the key under Key Management first if it is not listed.
    • If no key is selected, the rescue system only accepts a password and init cannot log in.
  3. Reset tab: run an automatic hardware reset. Rescue only takes effect on the next boot.
  4. Send the developer the server's IP address.

2. Developer: check the laptop

nix --version
nix run nixpkgs#hello      # fails if flakes are not enabled
ssh-add -l                 # lists the key given to the admin
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@<ip> true

If flakes are not enabled, add this line to ~/.config/nix/nix.conf:

experimental-features = nix-command flakes

3. Developer: run the installer

Run it from a new, empty directory:

mkdir ~/dev-server && cd ~/dev-server
nix run github:2140-dev/nix-dev-server#init

The installer asks for the following:

Prompt Default
Server IP —
Disk layout Smallest disk for /, others mounted at /data, /data2, ...
Hostname <laptop user>-dev
Username on the server Laptop username
Git name and email git config --global user.name / user.email
GPG signing key Secret keys from gpg --list-secret-keys, or "don't sign"
Time zone Laptop time zone
Locale en_US.UTF-8

The installer takes the server's SSH keys from the rescue login. It keeps only the keys that are also on the laptop, and shows them before any changes are made.

The installer then:

  1. Writes configuration.nix and disko.nix and commits them to the current directory.
  2. Asks for confirmation, then erases all listed disks and installs NixOS with nixos-anywhere. This takes about 15 minutes.
  3. Adds the server's host key to ~/.ssh/known_hosts.
  4. Commits the generated hardware-configuration.nix.
  5. Imports and trusts the GPG public key on the server, if one was selected.
  6. Copies the repository to ~/dev-server on the server.
  7. Offers to add a Host entry to ~/.ssh/config.

The installer creates nothing outside the laptop and the server.

init --dry-run stops after step 1, before anything is installed.

4. Developer: connect

ssh <hostname>

If the installer did not add the Host entry (for example because ~/.ssh/config is read-only), add it by hand:

Host <hostname>
  HostName <ip>
  User <user>
  HostKeyAlias <hostname>
  ForwardAgent yes
  RemoteForward /run/user/<uid>/gnupg/S.gpg-agent <agent-extra-socket>
  ExitOnForwardFailure yes
Placeholder Value
<uid> Output of id -u on the server (usually 1000).
<agent-extra-socket> Output of gpgconf --list-dirs agent-extra-socket on the laptop.

The RemoteForward line is only needed for commit signing.

Daily use

The server's configuration is in ~/dev-server on the server.

Task Command (in ~/dev-server)
Apply a configuration change sudo nixos-rebuild switch --flake .#workstation
Update nix-dev-server and nixpkgs nix flake update, then apply
Roll back sudo nixos-rebuild switch --rollback
Add an SSH key Add it to services.workstation.user.sshKeys, then apply
Add packages Add them to services.workstation.extraPackages, then apply

Commit changes to the repository. Pushing it to a remote is optional.

Commit signing

Signing on the server uses the GPG agent on the laptop, forwarded over SSH. Private keys never leave the laptop.

Laptop setup:

  1. Install a graphical pinentry. A terminal pinentry cannot prompt for requests that arrive from the server.
    • macOS: brew install pinentry-mac
    • Linux: pinentry-gnome3 or pinentry-qt
  2. Point gpg-agent at it in ~/.gnupg/gpg-agent.conf:
    pinentry-program /opt/homebrew/bin/pinentry-mac
    default-cache-ttl 3600
    max-cache-ttl 28800
    
    On Intel Macs the path is /usr/local/bin/pinentry-mac.
  3. Set GPG_TTY for local signing in the shell config:
    • zsh or bash: export GPG_TTY=$(tty)
    • fish: set -gx GPG_TTY (tty)
  4. Restart the agent: gpgconf --kill gpg-agent

Check that signing works, on the server:

cd ~/dev-server
git commit --allow-empty -m test
git log --show-signature -1     # expect: Good signature ... [ultimate]

Do not run gpgconf --kill all on the server. The agent socket there belongs to the laptop's agent.

Troubleshooting

Symptom Cause Fix
could not log in to root@<ip> with your SSH key Rescue activated without the developer's key, the server not reset, or the key not offered by ssh. Re-activate rescue with the key and reset. Check ssh -v root@<ip> true 2>&1 | grep Offering.
no ssh-agent is running No agent on the laptop. eval "$(ssh-agent)", then ssh-add <key>.
run in an empty directory Leftovers from an earlier run. Use a new directory. If the current directory was deleted, cd ~ first.
REMOTE HOST IDENTIFICATION HAS CHANGED on a manual ssh The server was reinstalled or is in rescue. ssh-keygen -R <ip>. The installer itself ignores old entries.
gpg: signing failed: Inappropriate ioctl for device gpg-agent cannot show a passphrase prompt. Signing on the laptop: set GPG_TTY. Signing on the server: install a graphical pinentry on the laptop. See Commit signing.
gpg: signing failed: No agent running on the server Connected without the RemoteForward line. Use the Host entry above and reconnect.
Permission denied (publickey) after install The key on the server is not one the laptop holds. Boot rescue and run init again.
missing or unsuitable terminal The server lacks the terminal's terminfo (e.g. Ghostty). TERM=xterm-256color ssh <hostname>

Using the modules directly

init generates a repository like templates.default. To write one by hand:

nix flake init -t github:2140-dev/nix-dev-server

Then fill in the FIXMEs.

Minimal configuration:

{
  imports = [
    nix-dev-server.nixosModules.default
    nix-dev-server.nixosModules.hetzner-bare-metal
  ];

  nixpkgs.config.allowUnfree = true; # claude-code, codex

  services.workstation = {
    enable = true;
    user.name = "alice";
    user.sshKeys = [ "ssh-ed25519 AAAA... alice@laptop" ];
  };
}

Make nixpkgs and disko follow nix-dev-server, so the system uses the versions this library is tested against:

inputs = {
  nix-dev-server.url = "github:2140-dev/nix-dev-server";
  nixpkgs.follows = "nix-dev-server/nixpkgs";
  disko.follows = "nix-dev-server/disko";
};

Options

Option Type Default
services.workstation.enable bool false
services.workstation.user.name string —
services.workstation.user.sshKeys list of strings [ ]
services.workstation.timeZone string "UTC"
services.workstation.locale string "en_US.UTF-8"
services.workstation.extraPackages list of packages [ ]

The developer's git identity is set with home-manager.users.<name>.programs.git. See templates/default/configuration.nix.

Without the bundled home-manager

nixosModules.workstation is the same preset without home-manager or nixvim:

{
  imports = [
    home-manager.nixosModules.home-manager
    nix-dev-server.nixosModules.workstation
  ];

  services.workstation = {
    enable = true;
    user.name = "alice";
  };

  home-manager.users.alice = {
    imports = [ nix-dev-server.homeModules.nixvim ];
    home.stateVersion = "25.05";
  };
}

Bitcoin Core dev shell

In a Bitcoin Core checkout:

echo "use flake github:2140-dev/nix-dev-server#bitcoin-core" > .envrc
direnv allow

Or scaffold a local flake, which pins its own flake.lock, plus a justfile:

nix flake init -t github:2140-dev/nix-dev-server#bitcoin-core
direnv allow
just --list

The shell includes:

  • clang with mold, cmake and ninja
  • gdb
  • the Python dependencies for the functional tests
  • on Linux, bcc, bpftrace and systemtap for the USDT tests

Development

nix flake check
Check Description
workstation-vm Boots nixosModules.default in a VM and checks the user, services, agent forwarding setup and home-manager.
init Builds the installer. shellcheck runs as part of the build.

CI also evaluates nixosConfigurations.template, the scaffold built against the current checkout.

License

MIT. See LICENSE.

About

Reusable NixOS modules and home-manager bundles for a bitcoin developer workstation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages