Created
March 7, 2018 17:11
-
-
Save chris-martin/657f855bf844a35d8533349f372bd57f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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://example.com --no-check-sigs | |
# Set the system profile to the new build. | |
ssh example.com \ | |
sudo nix-env --profile /nix/var/nix/profiles/system --set "$NIXOS" | |
# Activate the new profile | |
ssh example.com \ | |
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