From 4d68a9d64821367441a5e2a7ac144c458a67faef Mon Sep 17 00:00:00 2001 From: Yun Fachi Date: Sat, 25 Nov 2023 07:15:15 +0000 Subject: [PATCH] feat(make): add check when switching to diff host --- Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b652ceb..b8bb2bb 100644 --- a/Makefile +++ b/Makefile @@ -2,19 +2,28 @@ HOST=$(shell hostname) .MAIN: switch .DEFAULT_GOAL: switch +define rebuild + @if [ "$(HOST)" == "$(1)" ] || [ "$(force)" == "1" ]; then \ + nixos-rebuild switch --flake .#$(1) --use-remote-sudo;\ + else\ + printf "You are trying to switch to a host different from the current one, which can lead to system failure.\n";\ + printf "If you are confident in your actions, then specify \e[32;1mforce=1\e[0m in the options.";\ + fi +endef + #=-=-=-=-# # Switch # #-=-=-=-=# switch: - nixos-rebuild switch --flake .#$(HOST) --use-remote-sudo + @$(call rebuild,$(HOST)) #=-=-=-=# # Hosts # #-=-=-=-# dekomori: - nixos-rebuild switch --flake .#dekomori --use-remote-sudo + @$(call rebuild,dekomori) mitama: - nixos-rebuild switch --flake .#mitama --use-remote-sudo + @$(call rebuild,mitama) #=-=-=-=-# # Update #