h: switch to env file for golink

This commit is contained in:
Aaron Bieber 2022-12-12 06:45:26 -07:00
parent 72a0442649
commit 9b93a4a973
No known key found for this signature in database
3 changed files with 6 additions and 41 deletions

View File

@ -24,7 +24,7 @@ in {
'';
};
keyFile = mkOption {
envFile = mkOption {
type = types.path;
default = "/run/secrets/golink";
description = ''
@ -81,8 +81,10 @@ in {
CacheDirectory = "golink";
CacheDirectoryMode = "0755";
EnvironmentFile = cfg.envFile;
ExecStart =
"${cfg.package}/bin/golink -sqlitedb ${cfg.dataDir}/golink.db -keyfile ${cfg.keyFile}";
"${cfg.package}/bin/golink -sqlitedb ${cfg.dataDir}/golink.db";
};
};
};

View File

@ -10,12 +10,10 @@ buildGoModule rec {
src = fetchFromGitHub {
owner = "tailscale";
repo = pname;
rev = "0755e37a910b73b586544e2805c075dcec7d0207";
sha256 = "sha256-zzup/TR9iRNPrEEOzhIL5PTF8iKF8NlPqXBuRKt8AEc=";
rev = "5fefe2519ffd9f1c6a3dd86a764d69717ee66d20";
sha256 = "sha256-H4mwyQVFH/Yp6gIpN1o+L7S3Rupwbxl5CCLltcBh1Vk=";
};
patches = [ ./golink_keyfile.diff ];
vendorSha256 = vendorHash;
proxyVendor = true;

View File

@ -1,35 +0,0 @@
diff --git a/golink.go b/golink.go
index 3bc3353..fb0e791 100644
--- a/golink.go
+++ b/golink.go
@@ -37,6 +37,7 @@ var (
sqlitefile = flag.String("sqlitedb", "", "path of SQLite database to store links")
dev = flag.String("dev-listen", "", "if non-empty, listen on this addr and run in dev mode; auto-set sqlitedb if empty and don't use tsnet")
snapshot = flag.String("snapshot", "", "file path of snapshot file")
+ keyfile = flag.String("keyfile", "", "file path of file containing tskey")
)
var stats struct {
@@ -116,6 +117,13 @@ func Run() error {
Hostname: "go",
Logf: func(format string, args ...any) {},
}
+ if *keyfile != "" {
+ keyData, err := os.ReadFile(*keyfile)
+ if err != nil {
+ log.Fatalf("error reading keyfile file %q: %v", *keyfile, err)
+ }
+ srv.AuthKey = string(keyData)
+ }
if *verbose {
srv.Logf = log.Printf
}
@@ -353,7 +361,7 @@ type expandEnv struct {
var expandFuncMap = texttemplate.FuncMap{
"PathEscape": url.PathEscape,
"QueryEscape": url.QueryEscape,
- "TrimSuffix": strings.TrimSuffix,
+ "TrimSuffix": strings.TrimSuffix,
}
// expandLink returns the expanded long URL to redirect to, executing any