From 1870fa29bd8e73cfe371255345c8883b26dc2319 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 2 Aug 2020 15:24:00 -0600 Subject: [PATCH] Revert "shell.nix: remove `rebuild` command" This reverts commit b954963e36af24dad462ad36146d581a162cf509. --- README.md | 14 ++++++++++---- shell.nix | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c206d7f5..f0ad23af 100644 --- a/README.md +++ b/README.md @@ -57,14 +57,20 @@ ln -s $PWD /etc/nixos # adding a new file to staging is enough: git add ./hosts/${new_host}.nix -# Test your new deployment: -sudo nixos-rebuild $new_host test +# A generic `rebuild` wrapper for `nix build` is provided +# bypassing the need for `nixos-rebuild`. + +# Usage: rebuild [host] {switch|boot|test|dry-activate} +# where `host` is any file living in the `./hosts` directory + +# Test your new deployment; this will be run as root: +rebuild $new_host test # You may wish to start by creating a user: mkdir users/new-user && $EDITOR users/new-user/default.nix # Once your satisfied, permanently deploy with: -sudo nixos-rebuild $new_host switch +rebuild $new_host switch ``` Please read the [doc](DOC.md) in order to understand the impetus @@ -74,7 +80,7 @@ behind the directory structure. ```sh # Make an iso image based on `./hosts/niximg.nix`: -build-iso +rebuild iso # Install any package the flake exports: nix profile install ".#packages.x86_64-linux.myPackage" diff --git a/shell.nix b/shell.nix index 4a84c678..efb2ee87 100644 --- a/shell.nix +++ b/shell.nix @@ -1,14 +1,24 @@ { pkgs ? import { } }: let configs = "${toString ./.}#nixosConfigurations"; + hostname = pkgs.lib.fileContents /etc/hostname; + build = "config.system.build"; - buildIso = pkgs.writeShellScriptBin "build-iso" '' - nix build ${configs}.niximg.config.system.build.isoImage $@ + rebuild = pkgs.writeShellScriptBin "rebuild" '' + if [[ -z $1 ]]; then + echo "Usage: $0 [host] {switch|boot|test|iso}" + elif [[ $1 == "iso" ]]; then + nix build ${configs}.niximg.${build}.isoImage + elif [[ -z $2 ]]; then + sudo -E nix shell -vv ${configs}.${hostname}.${build}.toplevel -c switch-to-configuration $1 + else + sudo -E nix shell -vv ${configs}.$1.${build}.toplevel -c switch-to-configuration $2 + fi ''; in pkgs.mkShell { name = "nixflk"; - nativeBuildInputs = with pkgs; [ git git-crypt nixFlakes buildIso ]; + nativeBuildInputs = with pkgs; [ git git-crypt nixFlakes rebuild ]; shellHook = '' mkdir -p secrets