mirror of https://git.jolheiser.com/ugit.git
feat: allow enabling of each service individually
Signed-off-by: jolheiser <git@jolheiser.com>tui
parent
9a15c8a3dd
commit
519db4565f
|
@ -21,6 +21,7 @@ type cliArgs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshArgs struct {
|
type sshArgs struct {
|
||||||
|
Enable bool
|
||||||
AuthorizedKeys string
|
AuthorizedKeys string
|
||||||
CloneURL string
|
CloneURL string
|
||||||
Port int
|
Port int
|
||||||
|
@ -28,6 +29,7 @@ type sshArgs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpArgs struct {
|
type httpArgs struct {
|
||||||
|
Enable bool
|
||||||
CloneURL string
|
CloneURL string
|
||||||
Port int
|
Port int
|
||||||
}
|
}
|
||||||
|
@ -54,6 +56,7 @@ type logArgs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type tailscaleArgs struct {
|
type tailscaleArgs struct {
|
||||||
|
Enable bool
|
||||||
Hostname string
|
Hostname string
|
||||||
DataDir string
|
DataDir string
|
||||||
}
|
}
|
||||||
|
@ -65,12 +68,14 @@ func parseArgs(args []string) (c cliArgs, e error) {
|
||||||
c = cliArgs{
|
c = cliArgs{
|
||||||
RepoDir: ".ugit",
|
RepoDir: ".ugit",
|
||||||
SSH: sshArgs{
|
SSH: sshArgs{
|
||||||
|
Enable: true,
|
||||||
AuthorizedKeys: ".ssh/authorized_keys",
|
AuthorizedKeys: ".ssh/authorized_keys",
|
||||||
CloneURL: "ssh://localhost:8448",
|
CloneURL: "ssh://localhost:8448",
|
||||||
Port: 8448,
|
Port: 8448,
|
||||||
HostKey: ".ssh/ugit_ed25519",
|
HostKey: ".ssh/ugit_ed25519",
|
||||||
},
|
},
|
||||||
HTTP: httpArgs{
|
HTTP: httpArgs{
|
||||||
|
Enable: true,
|
||||||
CloneURL: "http://localhost:8449",
|
CloneURL: "http://localhost:8449",
|
||||||
Port: 8449,
|
Port: 8449,
|
||||||
},
|
},
|
||||||
|
@ -82,6 +87,7 @@ func parseArgs(args []string) (c cliArgs, e error) {
|
||||||
Level: log.InfoLevel,
|
Level: log.InfoLevel,
|
||||||
},
|
},
|
||||||
Tailscale: tailscaleArgs{
|
Tailscale: tailscaleArgs{
|
||||||
|
Enable: false,
|
||||||
Hostname: "ugit",
|
Hostname: "ugit",
|
||||||
DataDir: ".tsnet",
|
DataDir: ".tsnet",
|
||||||
},
|
},
|
||||||
|
@ -97,10 +103,12 @@ func parseArgs(args []string) (c cliArgs, e error) {
|
||||||
})
|
})
|
||||||
fs.BoolVar(&c.Log.JSON, "log.json", c.Log.JSON, "Print logs in JSON(L) format")
|
fs.BoolVar(&c.Log.JSON, "log.json", c.Log.JSON, "Print logs in JSON(L) format")
|
||||||
fs.StringVar(&c.RepoDir, "repo-dir", c.RepoDir, "Path to directory containing repositories")
|
fs.StringVar(&c.RepoDir, "repo-dir", c.RepoDir, "Path to directory containing repositories")
|
||||||
|
fs.BoolVar(&c.SSH.Enable, "ssh.enable", c.SSH.Enable, "Enable SSH server")
|
||||||
fs.StringVar(&c.SSH.AuthorizedKeys, "ssh.authorized-keys", c.SSH.AuthorizedKeys, "Path to authorized_keys")
|
fs.StringVar(&c.SSH.AuthorizedKeys, "ssh.authorized-keys", c.SSH.AuthorizedKeys, "Path to authorized_keys")
|
||||||
fs.StringVar(&c.SSH.CloneURL, "ssh.clone-url", c.SSH.CloneURL, "SSH clone URL base")
|
fs.StringVar(&c.SSH.CloneURL, "ssh.clone-url", c.SSH.CloneURL, "SSH clone URL base")
|
||||||
fs.IntVar(&c.SSH.Port, "ssh.port", c.SSH.Port, "SSH port")
|
fs.IntVar(&c.SSH.Port, "ssh.port", c.SSH.Port, "SSH port")
|
||||||
fs.StringVar(&c.SSH.HostKey, "ssh.host-key", c.SSH.HostKey, "SSH host key (created if it doesn't exist)")
|
fs.StringVar(&c.SSH.HostKey, "ssh.host-key", c.SSH.HostKey, "SSH host key (created if it doesn't exist)")
|
||||||
|
fs.BoolVar(&c.HTTP.Enable, "http.enable", c.HTTP.Enable, "Enable HTTP server")
|
||||||
fs.StringVar(&c.HTTP.CloneURL, "http.clone-url", c.HTTP.CloneURL, "HTTP clone URL base")
|
fs.StringVar(&c.HTTP.CloneURL, "http.clone-url", c.HTTP.CloneURL, "HTTP clone URL base")
|
||||||
fs.IntVar(&c.HTTP.Port, "http.port", c.HTTP.Port, "HTTP port")
|
fs.IntVar(&c.HTTP.Port, "http.port", c.HTTP.Port, "HTTP port")
|
||||||
fs.StringVar(&c.Meta.Title, "meta.title", c.Meta.Title, "App title")
|
fs.StringVar(&c.Meta.Title, "meta.title", c.Meta.Title, "App title")
|
||||||
|
@ -118,6 +126,7 @@ func parseArgs(args []string) (c cliArgs, e error) {
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
fs.BoolVar(&c.Tailscale.Enable, "tailscale.enable", c.Tailscale.Enable, "Enable Tailscale")
|
||||||
fs.StringVar(&c.Tailscale.Hostname, "tailscale.hostname", c.Tailscale.Hostname, "Tailscale host to show private repos on")
|
fs.StringVar(&c.Tailscale.Hostname, "tailscale.hostname", c.Tailscale.Hostname, "Tailscale host to show private repos on")
|
||||||
fs.StringVar(&c.Tailscale.DataDir, "tailscale.data-dir", c.Tailscale.DataDir, "Tailscale data/state directory")
|
fs.StringVar(&c.Tailscale.DataDir, "tailscale.data-dir", c.Tailscale.DataDir, "Tailscale data/state directory")
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args.SSH.Enable {
|
||||||
sshSettings := ssh.Settings{
|
sshSettings := ssh.Settings{
|
||||||
AuthorizedKeys: args.SSH.AuthorizedKeys,
|
AuthorizedKeys: args.SSH.AuthorizedKeys,
|
||||||
CloneURL: args.SSH.CloneURL,
|
CloneURL: args.SSH.CloneURL,
|
||||||
|
@ -79,6 +80,7 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
httpSettings := http.Settings{
|
httpSettings := http.Settings{
|
||||||
Title: args.Meta.Title,
|
Title: args.Meta.Title,
|
||||||
|
@ -98,6 +100,7 @@ func main() {
|
||||||
URL: link.URL,
|
URL: link.URL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if args.HTTP.Enable {
|
||||||
httpSrv := http.New(httpSettings)
|
httpSrv := http.New(httpSettings)
|
||||||
go func() {
|
go func() {
|
||||||
log.Debugf("HTTP listening on http://localhost:%d\n", httpSettings.Port)
|
log.Debugf("HTTP listening on http://localhost:%d\n", httpSettings.Port)
|
||||||
|
@ -105,8 +108,9 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := os.LookupEnv("TS_AUTHKEY"); ok {
|
if args.Tailscale.Enable {
|
||||||
tailnetSettings := httpSettings
|
tailnetSettings := httpSettings
|
||||||
tailnetSettings.ShowPrivate = true
|
tailnetSettings.ShowPrivate = true
|
||||||
tailnetSrv := http.New(tailnetSettings)
|
tailnetSrv := http.New(tailnetSettings)
|
||||||
|
|
18
flake.nix
18
flake.nix
|
@ -76,7 +76,9 @@
|
||||||
configFile = pkgs.writeText "ugit.yaml" (builtins.readFile (yamlFormat.generate "ugit-yaml" cfg.config));
|
configFile = pkgs.writeText "ugit.yaml" (builtins.readFile (yamlFormat.generate "ugit-yaml" cfg.config));
|
||||||
authorizedKeysFile = pkgs.writeText "ugit_keys" (builtins.concatStringsSep "\n" cfg.authorizedKeys);
|
authorizedKeysFile = pkgs.writeText "ugit_keys" (builtins.concatStringsSep "\n" cfg.authorizedKeys);
|
||||||
in {
|
in {
|
||||||
options = with lib; {
|
options = let
|
||||||
|
inherit (lib) mkEnableOption mkOption types;
|
||||||
|
in {
|
||||||
services.ugit = {
|
services.ugit = {
|
||||||
enable = mkEnableOption "Enable ugit";
|
enable = mkEnableOption "Enable ugit";
|
||||||
|
|
||||||
|
@ -86,6 +88,12 @@
|
||||||
default = ugit;
|
default = ugit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tsAuthKey = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Tailscale one-time auth-key";
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
|
||||||
repoDir = mkOption {
|
repoDir = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "where ugit stores repositories";
|
description = "where ugit stores repositories";
|
||||||
|
@ -155,7 +163,12 @@
|
||||||
if (builtins.length cfg.authorizedKeys) > 0
|
if (builtins.length cfg.authorizedKeys) > 0
|
||||||
then authorizedKeysFile
|
then authorizedKeysFile
|
||||||
else cfg.authorizedKeysFile;
|
else cfg.authorizedKeysFile;
|
||||||
args = ["--config=${configFile}" "--repo-dir=${cfg.repoDir}" "--ssh.authorized-keys=${authorizedKeysPath}" "--ssh.host-key=${cfg.hostKeyFile}"];
|
args = [
|
||||||
|
"--config=${configFile}"
|
||||||
|
"--repo-dir=${cfg.repoDir}"
|
||||||
|
"--ssh.authorized-keys=${authorizedKeysPath}"
|
||||||
|
"--ssh.host-key=${cfg.hostKeyFile}"
|
||||||
|
];
|
||||||
in "${cfg.package}/bin/ugitd ${builtins.concatStringsSep " " args}";
|
in "${cfg.package}/bin/ugitd ${builtins.concatStringsSep " " args}";
|
||||||
wantedBy = ["multi-user.target"];
|
wantedBy = ["multi-user.target"];
|
||||||
after = ["network.target"];
|
after = ["network.target"];
|
||||||
|
@ -166,6 +179,7 @@
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
RestartSec = "15";
|
RestartSec = "15";
|
||||||
WorkingDirectory = "/var/lib/ugit";
|
WorkingDirectory = "/var/lib/ugit";
|
||||||
|
Environment = ["TS_AUTHKEY=${cfg.tsAuthKey}"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue