Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#! /usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error when substituting
# The .nix directory is where we put all our Nix output symlinks. Create it if it doesn't already exist.
mkdir --parents .nix
# Pin Nix to the exact version of nixpkgs we're using.
nix build -f nixpkgs.nix --out-link .nix/nixpkgs
export NIX_PATH=nixpkgs=$PWD/.nix/nixpkgs
# Build NixOS for the server.
nix build -v '(import ./default.nix).webserver1' \
--out-link .nix/webserver1
# Get the path of the NixOS build in /nix/store.
NIXOS=$(readlink .nix/webserver1)
# Upload the build to the server.
nix copy "$NIXOS" --to ssh:// --no-check-sigs
# Set the system profile to the new build.
ssh \
sudo nix-env --profile /nix/var/nix/profiles/system --set "$NIXOS"
# Activate the new profile
ssh \
sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment