home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 8e4597b728a9140a138e38786a221631567679b8
parent efd7fc799d4d3a276d34b52dd788603a68db84cb
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Mon,  1 Jun 2020 16:48:39 +0200

switch: move to hack/system

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
M.gitignore | 1+
MMakefile | 22+++++++++-------------
Ahack/system | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Dswitch | 51---------------------------------------------------
4 files changed, 61 insertions(+), 64 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -10,6 +10,7 @@ qemu accounts.nix assets/* private/* +secrets/* networking.nix wireguard*.key .secrets diff --git a/Makefile b/Makefile @@ -31,6 +31,11 @@ emacs-dump: emacs --batch -q -l ~/.config/emacs/dump.el # home-manager setup +.PHONY: secrets +secrets: + mkdir -p secrets + cp -Rv $(SYNCDIR)/* secrets/ + .PHONY: assets assets: mkdir -p assets @@ -39,24 +44,15 @@ assets: .PHONY: build build: assets setup - home-manager build - -.PHONY: nixos-build -nixos-build: assets setup - nixos-rebuild build + ./hack/system build .PHONY: nixos-dry-build -nixos-dry-build: assets setup - nixos-rebuild dry-build +dry-build: assets setup + ./hack/system dry-build .PHONY: switch switch: assets setup - home-manager switch - -.PHONY: nixos-switch -.PHONY: nixos-switch -nixos-switch: assets setup - nixos-rebuild switch + ./hack/system switch .PHONY: install-hooks install-hooks: diff --git a/hack/system b/hack/system @@ -0,0 +1,51 @@ +#! /usr/bin/env bash +set -o pipefail -o noclobber -o nounset + +function error() { + local red + local reset + red="$(tput setaf 1)" + reset="$(tput sgr0)" + + printf "%s%s%s\n" "$red" "$*" "$reset" + exit 1 +} + +function set_work_dir() { + if [[ ! -v WORK_DIR ]]; then + WORK_DIR="$(mktemp --tmpdir -u nix-config-sync.XXXXXXXXXX)" + # shellcheck disable=2064 + trap "rm -rf '$WORK_DIR'" EXIT + fi +} + +function build() { + [ "$#" -eq 0 ] || error "build" + set_work_dir + local machine + machine="$(hostname)" + unset NIX_PATH + nix-build --out-link "$WORK_DIR" -A "$machine" || + error "Failed to build system" +} + +function switch() { + [ "$#" -eq 0 ] || error "switch" + set_work_dir + local switch_bin="$WORK_DIR/bin/switch-to-configuration" + sudo nix-env --set \ + --profile "/nix/var/nix/profiles/system" \ + "$WORK_DIR" || + error "Failed to activate profile" + sudo "$switch_bin" "switch" || + error "Failed to activate system" +} + +function main() { + for target in $@; do + $target + done + exit 0 +} + +main "$@" diff --git a/switch b/switch @@ -1,50 +0,0 @@ -#! /usr/bin/env bash -set -o pipefail -o noclobber -o nounset - -function error() { - local red - local reset - red="$(tput setaf 1)" - reset="$(tput sgr0)" - - printf "%s%s%s\n" "$red" "$*" "$reset" - exit 1 -} - -function set_work_dir() { - if [[ ! -v WORK_DIR ]]; then - WORK_DIR="$(mktemp --tmpdir -u nix-config-sync.XXXXXXXXXX)" - # shellcheck disable=2064 - trap "rm -rf '$WORK_DIR'" EXIT - fi -} - -function build() { - [ "$#" -eq 0 ] || error "build" - set_work_dir - local machine - machine="$(hostname)" - unset NIX_PATH - nix-build --out-link "$WORK_DIR" -A "$machine" || - error "Failed to build system" -} - -function switch() { - [ "$#" -eq 0 ] || error "switch" - set_work_dir - local switch_bin="$WORK_DIR/bin/switch-to-configuration" - sudo nix-env --set \ - --profile "/nix/var/nix/profiles/system" \ - "$WORK_DIR" || - error "Failed to activate profile" - sudo "$switch_bin" "switch" || - error "Failed to activate system" -} - -function main() { - build - switch - exit 0 -} - -main "$@"- \ No newline at end of file