mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
feat: local install utility
This commit is contained in:
parent
6cba256e0b
commit
c47ad454a0
5 changed files with 86 additions and 10 deletions
|
|
@ -3033,19 +3033,18 @@ This program sets up a new NixOS host.
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z ${FLAKE} ]]; then
|
cd /home/"$target_user"
|
||||||
FLAKE=/home/"$target_user"/.dotfiles
|
|
||||||
fi
|
if [ ! -d /home"$target_user"/.dotfiles ]; then
|
||||||
if [ ! -d "$FLAKE" ]; then
|
green "Cloning repository from GitHub"
|
||||||
cd /home/"$target_user"
|
git clone https://github.com/Swarsel/.dotfiles.git
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$FLAKE"
|
cd .dotfiles
|
||||||
|
sudo nixos-generate-config --dir /home/"$target_user"/.dotfiles/hosts/nixos/"$target_flake"/
|
||||||
|
git add /home/"$target_user"/.dotfiles/hosts/nixos/"$target_flake"/hardware-configuration.nix
|
||||||
green "Installing flake $target_flake"
|
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
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,11 @@
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${self.packages.${system}.bootstrap}/bin/bootstrap";
|
program = "${self.packages.${system}.bootstrap}/bin/bootstrap";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
install = {
|
||||||
|
type = "app";
|
||||||
|
program = "${self.packages.${system}.swarsel-install}/bin/swarsel-install";
|
||||||
|
};
|
||||||
});
|
});
|
||||||
devShells = forAllSystems (
|
devShells = forAllSystems (
|
||||||
system:
|
system:
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ let
|
||||||
"github-notifications"
|
"github-notifications"
|
||||||
"screenshare"
|
"screenshare"
|
||||||
"bootstrap"
|
"bootstrap"
|
||||||
|
"swarsel-install"
|
||||||
"t2ts"
|
"t2ts"
|
||||||
"ts2t"
|
"ts2t"
|
||||||
"vershell"
|
"vershell"
|
||||||
|
|
|
||||||
7
pkgs/swarsel-install/default.nix
Normal file
7
pkgs/swarsel-install/default.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{ writeShellApplication, git }:
|
||||||
|
|
||||||
|
writeShellApplication {
|
||||||
|
name = "swarsel-install";
|
||||||
|
runtimeInputs = [ git ];
|
||||||
|
text = builtins.readFile ../../scripts/swarsel-install.sh;
|
||||||
|
}
|
||||||
64
scripts/swarsel-install.sh
Normal file
64
scripts/swarsel-install.sh
Normal file
|
|
@ -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"/
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue