From ade1b7377972830030e4e3fe84996191e3a7faae Mon Sep 17 00:00:00 2001
From: Juan Font Alonso <juanfontalonso@gmail.com>
Date: Sun, 14 Aug 2022 12:35:14 +0200
Subject: [PATCH] Output an error when a user runs headscale without
 noise_private_key_path defined

---
 cmd/headscale/cli/root.go | 4 ++--
 config.go                 | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/cmd/headscale/cli/root.go b/cmd/headscale/cli/root.go
index 270ca55..2c28c58 100644
--- a/cmd/headscale/cli/root.go
+++ b/cmd/headscale/cli/root.go
@@ -28,12 +28,12 @@ func initConfig() {
 	if cfgFile != "" {
 		err := headscale.LoadConfig(cfgFile, true)
 		if err != nil {
-			log.Fatal().Caller().Err(err)
+			log.Fatal().Caller().Err(err).Msgf("Error loading config file %s", cfgFile)
 		}
 	} else {
 		err := headscale.LoadConfig("", false)
 		if err != nil {
-			log.Fatal().Caller().Err(err)
+			log.Fatal().Caller().Err(err).Msgf("Error loading config")
 		}
 	}
 
diff --git a/config.go b/config.go
index a792bab..99e7a4c 100644
--- a/config.go
+++ b/config.go
@@ -184,6 +184,10 @@ func LoadConfig(path string, isFile bool) error {
 		errorText += "Fatal config error: set either tls_letsencrypt_hostname or tls_cert_path/tls_key_path, not both\n"
 	}
 
+	if !viper.IsSet("noise_private_key_path") {
+		errorText += "Fatal config error: headscale now requires a new `noise_private_key_path` field in the config file for the Tailscale v2 protocol\n"
+	}
+
 	if (viper.GetString("tls_letsencrypt_hostname") != "") &&
 		(viper.GetString("tls_letsencrypt_challenge_type") == tlsALPN01ChallengeType) &&
 		(!strings.HasSuffix(viper.GetString("listen_addr"), ":443")) {