Skip to content

Commit

Permalink
feat: local install utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Swarsel committed Dec 18, 2024
1 parent 6cba256 commit 54b3106
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 10 deletions.
19 changes: 9 additions & 10 deletions SwarselSystems.org
Original file line number Diff line number Diff line change
Expand Up @@ -3033,19 +3033,18 @@ This program sets up a new NixOS host.
shift
done

if [[ -z ${FLAKE} ]]; then
FLAKE=/home/"$target_user"/.dotfiles
fi
if [ ! -d "$FLAKE" ]; then
cd /home/"$target_user"
yellow "Flake directory not found - cloning repository from GitHub"
git clone git@github.com:Swarsel/.dotfiles.git || (yellow "Could not clone repository via SSH - defaulting to HTTPS" && git clone https://github.com/Swarsel/.dotfiles.git)
FLAKE=/home/"$target_user"/.dotfiles
cd /home/"$target_user"

if [ ! -d /home"$target_user"/.dotfiles ]; then
green "Cloning repository from GitHub"
git clone https://github.com/Swarsel/.dotfiles.git
fi

cd "$FLAKE"
cd .dotfiles
sudo nixos-generate-config --dir /home/"$target_user"/.dotfiles/hosts/nixos/"$target_flake"/hardware-configuration.nix
git add /home/"$target_user"/.dotfiles/hosts/nixos/"$target_flake"/hardware-configuration.nix
green "Installing flake $target_flake"
sudo nixos-rebuild --show-trace --flake .#"$target_flake" switch
sudo nixos-rebuild --show-trace --flake .#"$target_flake" --keep-going switch
#+end_src


Expand Down
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
type = "app";
program = "${self.packages.${system}.bootstrap}/bin/bootstrap";
};

install = {
type = "app";
program = "${self.packages.${system}.swarsel-install}/bin/swarsel-install";
};
});
devShells = forAllSystems (
system:
Expand Down
1 change: 1 addition & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let
"github-notifications"
"screenshare"
"bootstrap"
"swarsel-install"
"t2ts"
"ts2t"
"vershell"
Expand Down
7 changes: 7 additions & 0 deletions pkgs/swarsel-install/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ writeShellApplication, git }:

writeShellApplication {
name = "swarsel-install";
runtimeInputs = [ git ];
text = builtins.readFile ../../scripts/swarsel-install.sh;
}
64 changes: 64 additions & 0 deletions scripts/swarsel-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
set -eo pipefail

target_flake="chaostheatre"
target_user="swarsel"

function help_and_exit() {
echo
echo "Remotely installs NixOS on a target machine using this nix-config."
echo
echo "USAGE: $0 [OPTIONS]"
echo
echo "ARGS:"
echo " -f <target_flake> specify flake to deploy the nixos config of."
echo " Default: chaostheatre"
echo " -u <target_user> specify user to deploy for."
echo " Default: swarsel"
echo " -h | --help Print this help."
exit 0
}

function green() {
echo -e "\x1B[32m[+] $1 \x1B[0m"
if [ -n "${2-}" ]; then
echo -e "\x1B[32m[+] $($2) \x1B[0m"
fi
}
function yellow() {
echo -e "\x1B[33m[*] $1 \x1B[0m"
if [ -n "${2-}" ]; then
echo -e "\x1B[33m[*] $($2) \x1B[0m"
fi
}

while [[ $# -gt 0 ]]; do
case "$1" in
-f)
shift
target_flake=$1
;;
-u)
shift
target_user=$1
;;
-h | --help) help_and_exit ;;
*)
echo "Invalid option detected."
help_and_exit
;;
esac
shift
done

cd /home/"$target_user"

if [ ! -d /home"$target_user"/.dotfiles ]; then
green "Cloning repository from GitHub"
git clone https://github.com/Swarsel/.dotfiles.git
fi

cd .dotfiles
sudo nixos-generate-config --dir /home/"$target_user"/.dotfiles/hosts/nixos/"$target_flake"/hardware-configuration.nix
git add /home/"$target_user"/.dotfiles/hosts/nixos/"$target_flake"/hardware-configuration.nix
green "Installing flake $target_flake"
sudo nixos-rebuild --show-trace --flake .#"$target_flake" --keep-going switch

0 comments on commit 54b3106

Please sign in to comment.