From 589c1c04a1b75efee9ea618fc35f28efc6855fe9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 13 Jan 2020 19:56:39 -0500 Subject: [PATCH] Bring back deploy script for remote bootstrap And make linode config a regular module. --- Makefile | 21 ++++------- README.md | 37 ++++++++++++++++--- default.nix | 2 +- deploy | 29 +++++++++++++++ machines/holo.nix | 23 ++++++++++++ .../linode/default.nix => modules/linode.nix | 2 - 6 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 deploy create mode 100644 machines/holo.nix rename machines/linode/default.nix => modules/linode.nix (98%) diff --git a/Makefile b/Makefile index 256e44f9..2d5a67d8 100644 --- a/Makefile +++ b/Makefile @@ -5,19 +5,17 @@ FLAGS := -I "my=$(PWD)" $(FLAGS) COMMAND := test # The real Labowski -all: channels config secrets.nix +all: channels secrets.nix @sudo nixos-rebuild $(FLAGS) $(COMMAND) -install: result channels update config - @nixos-generate-config --root "$(PREFIX)" - @nixos-install --root "$(PREFIX)" - -install-linode: result channels update - @sudo mkdir -p "$(NIXOS_PREFIX)" - @echo "(import $(PWD)/dotfiles \"linode\") \"$$(hostname)\"" | sudo tee "$(NIXOS_PREFIX)/configuration.nix" +install: channels update config + @sudo nixos-install --root "$(PREFIX)" $(FLAGS) upgrade: update switch +update: + @sudo nix-channel --update + switch: @sudo nixos-rebuild $(FLAGS) switch @@ -29,9 +27,6 @@ clean: # Parts -update: - @sudo nix-channel --update - config: $(NIXOS_PREFIX)/configuration.nix channels: @@ -40,8 +35,8 @@ channels: @sudo nix-channel --add "https://nixos.org/channels/nixpkgs-unstable" nixpkgs-unstable $(NIXOS_PREFIX)/configuration.nix: - @sudo mkdir -p "$(NIXOS_PREFIX)" - @echo "import $(PWD)/dotfiles \"$$(hostname)\"" | sudo tee "$(NIXOS_PREFIX)/configuration.nix" + @sudo nixos-generate-config --root "$(PREFIX)" + @echo "import $(PWD)/dotfiles \"$(HOST)\"" | sudo tee "$(NIXOS_PREFIX)/configuration.nix" secrets.nix: secrets.nix.gpg @nix-shell -p gnupg --run "gpg -dq $< > $@" diff --git a/README.md b/README.md index e3e252fc..1515e5bc 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,41 @@ white whale and annihilate what vestiges of my social life remain. ## Quick start ```sh -# Make sure your partitions are set up by this point -git clone https://github.com/hlissner/dotfiles /etc/dotfiles -HOST=hostname make install +# Assumes your partitions are set up and root is mounted on /mnt +curl https://raw.githubusercontent.com/hlissner/dotfiles/nixos/deploy | sh ``` +This is equivalent to: + +```sh +DOTFILES=/home/$USER/.dotfiles +git clone https://github.com/hlissner/dotfiles $DOTFILES +ln -s /etc/dotfiles $DOTFILES +chown -R $USER:users $DOTFILES + +# make channels +nix-channel --add "https://nixos.org/channels/nixos-${NIXOS_VERSION}" nixos +nix-channel --add "https://github.com/rycee/home-manager/archive/release-${NIXOS_VERSION}.tar.gz" home-manager +nix-channel --add "https://nixos.org/channels/nixpkgs-unstable" nixpkgs-unstable + +# make /etc/nixos/configuration.nix +nixos-generate-config --root /mnt +echo "import /etc/dotfiles \"$$(hostname)\"" >/mnt/etc/nixos/configuration.nix + +# make secrets.nix +nix-shell -p gnupg --run "gpg -dq secrets.nix.gpg >secrets.nix" + +# make install +nixos-install --root /mnt -I "my=/etc/dotfiles" +``` + +### Management + + `make` = `nixos-rebuild test` + `make switch` = `nixos-rebuild switch` + `make upgrade` = `nix-channel --update && nixos-rebuild switch` -+ `make install` = `nixos-generate-config --root $PREFIX && nixos-install - --root $PREFIX` ++ `make install` = `nixos-generate-config --root $PREFIX && nixos-install --root + $PREFIX` + `make gc` = `nix-collect-garbage -d` (use sudo to clear system profile) ## Overview @@ -32,7 +57,7 @@ HOST=hostname make install + Shell: zsh + DE/WM: bspwm + polybar + Editor: [Doom Emacs][doom-emacs] (and occasionally [vim][vimrc]) -+ Terminal: st + extensions ++ Terminal: st + Browser: firefox (waiting for qutebrowser to mature) diff --git a/default.nix b/default.nix index 1260d959..c9e6403e 100644 --- a/default.nix +++ b/default.nix @@ -3,7 +3,7 @@ device: { pkgs, options, lib, config, ... }: { - networking.hostName = device; + networking.hostName = lib.mkDefault device; imports = [ diff --git a/deploy b/deploy new file mode 100644 index 00000000..3a53f502 --- /dev/null +++ b/deploy @@ -0,0 +1,29 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p git gnumake + +set -e # bail if an error occurs +if [ $EUID -nq 0 ]; then + >&2 echo "Must be run as root" + exit 1 +fi + +USER=${USER:-hlissner} +HOST=${1:-${HOST:-kuro}} + +DOTFILES="/home/$USER/.dotfiles" +if [ ! -d /etc/dotfiles ]; then + git clone https://github.com/hlissner/dotfiles "$DOTFILES" + chown -R $USER:users "$DOTFILES" +fi +ln -sf "$DOTFILES" /etc/dotfiles + +if [ ! -f "$DOTFILES/machines/$HOST.nix" ]; then + >&2 echo "No configuration exists for host '$HOST'" + exit 1 +fi + +if [ -n "$LINODE" ]; then + ARGS="\"$HOST\"" + HOST=linode +fi +make -C "$DOTFILES" install diff --git a/machines/holo.nix b/machines/holo.nix new file mode 100644 index 00000000..b35509c9 --- /dev/null +++ b/machines/holo.nix @@ -0,0 +1,23 @@ +# FIXME + +{ config, lib, pkgs, ... }: +{ + imports = [ + + ]; + + networking.hostName = "holo"; + time.timeZone = "America/Toronto"; + + services.nginx = { + # user = config.my.username; + virtualHosts = { + # "domain.com" = { + # default = true; + # enableACME = true; + # forceSSL = true; + # root = "..."; + # }; + }; + }; +} diff --git a/machines/linode/default.nix b/modules/linode.nix similarity index 98% rename from machines/linode/default.nix rename to modules/linode.nix index b89111ce..fea78024 100644 --- a/machines/linode/default.nix +++ b/modules/linode.nix @@ -27,7 +27,6 @@ # # 5. Reboot into profile. -host: { config, lib, pkgs, ... }: { environment.systemPackages = @@ -39,7 +38,6 @@ host: - "./${host}.nix" ]; # GRUB