mirror of
https://github.com/tuxdotrs/trok.git
synced 2026-09-19 23:19:03 +05:30
Compare commits
7 Commits
e451f17df0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
adf7c84269
|
|||
|
a86a290e88
|
|||
|
6c13858d46
|
|||
|
ad3792139d
|
|||
|
c1ba1e55d0
|
|||
|
a616409ee0
|
|||
|
3cceda5835
|
@@ -90,7 +90,7 @@ trok = {
|
||||
inputs.trok.nixosModules.default
|
||||
];
|
||||
|
||||
tux.services.trok = {
|
||||
services.trok = {
|
||||
enable = true;
|
||||
host = "0.0.0.0";
|
||||
port = 1337;
|
||||
|
||||
57
flake.lock
generated
57
flake.lock
generated
@@ -1,5 +1,23 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1788450739,
|
||||
"narHash": "sha256-glZLQlzIn1fXH6PazR2iUmTo7kzzyYSshrWhLS9TqCU=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "31729ca8cbdb4fa927b34e5f4353e6a83f39e993",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1740547748,
|
||||
@@ -16,9 +34,46 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1788057806,
|
||||
"narHash": "sha256-DTQSMxzDWmT0zhguthvegnVkn7CFqGCv4IHCzk5ZUpM=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "596e2e3940e09b2abbeb03f75fa1828c57fcd72c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
}
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1786901030,
|
||||
"narHash": "sha256-WSFCsDSE5ffgD2MqzkM2CYjeFiKhRF/dJUN8uedb6YE=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "27b3b12a8e6375f28ebe122f07d230ca5459bbfa",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
62
flake.nix
62
flake.nix
@@ -1,29 +1,43 @@
|
||||
{
|
||||
description = "Simple tunneler in Go that exposes local ports to the internet";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
description =
|
||||
"Simple tunneler in Go that exposes local ports to the internet";
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
}: let
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
|
||||
forAllSystems = function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system});
|
||||
in {
|
||||
packages = forAllSystems (pkgs: rec {
|
||||
default = trok;
|
||||
trok = pkgs.callPackage ./default.nix {};
|
||||
});
|
||||
|
||||
nixosModules.default = ./module.nix;
|
||||
|
||||
devShells = forAllSystems (pkgs: {
|
||||
default = pkgs.callPackage ./shell.nix {};
|
||||
});
|
||||
treefmt-nix = {
|
||||
url = "github:numtide/treefmt-nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = inputs:
|
||||
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [ inputs.treefmt-nix.flakeModule ];
|
||||
|
||||
systems =
|
||||
[ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
|
||||
perSystem = { config, pkgs, ... }: {
|
||||
treefmt = {
|
||||
projectRootFile = "flake.nix";
|
||||
|
||||
programs = {
|
||||
nixfmt.enable = true;
|
||||
gofumpt.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
packages = rec {
|
||||
default = tfolio;
|
||||
tfolio = pkgs.callPackage ./nix/package.nix { };
|
||||
};
|
||||
|
||||
devShells.default = pkgs.callPackage ./nix/shell.nix { };
|
||||
};
|
||||
|
||||
flake.nixosModules.default = ./nix/module.nix;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ type Trok struct {
|
||||
|
||||
func (t *Trok) Init(addr string) error {
|
||||
t.publicConns = make(map[string]Conn)
|
||||
t.webServer = NewTrokWeb(":443")
|
||||
t.webServer = NewTrokWeb(":1338")
|
||||
err := t.controlServer.Init(addr, "Controller")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/tuxdotrs/trok/internal/web"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
)
|
||||
|
||||
type TrokWeb struct {
|
||||
@@ -36,29 +34,7 @@ func (t *TrokWeb) Start() {
|
||||
Browse: true,
|
||||
}))
|
||||
|
||||
cfg := t.GetTLSCert()
|
||||
|
||||
ln, err := tls.Listen("tcp", t.addr, cfg)
|
||||
if err != nil {
|
||||
log.Panic().Msgf("unable to start trok webserver: %v", err)
|
||||
}
|
||||
|
||||
t.app.Listener(ln)
|
||||
}
|
||||
|
||||
func (t *TrokWeb) GetTLSCert() *tls.Config {
|
||||
m := &autocert.Manager{
|
||||
Prompt: autocert.AcceptTOS,
|
||||
HostPolicy: autocert.HostWhitelist("trok.cloud"),
|
||||
Cache: autocert.DirCache("./certs"),
|
||||
}
|
||||
|
||||
return &tls.Config{
|
||||
GetCertificate: m.GetCertificate,
|
||||
NextProtos: []string{
|
||||
"http/1.1", "acme-tls/1",
|
||||
},
|
||||
}
|
||||
log.Panic().Err(t.app.Listen(t.addr)).Msg("unable to start trok webserver")
|
||||
}
|
||||
|
||||
func (t *TrokWeb) Stop() {
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.tux.services.trok;
|
||||
{ config, lib, pkgs, ... }:
|
||||
with lib;
|
||||
let cfg = config.services.trok;
|
||||
in {
|
||||
options.tux.services.trok = {
|
||||
options.services.trok = {
|
||||
enable = mkEnableOption "Enable trok";
|
||||
|
||||
host = mkOption {
|
||||
@@ -50,7 +45,8 @@ in {
|
||||
Type = "simple";
|
||||
User = "trok";
|
||||
Group = "trok";
|
||||
ExecStart = "${getExe pkgs.trok} server -a ${cfg.host}:${toString cfg.port}";
|
||||
ExecStart =
|
||||
"${getExe pkgs.trok} server -a ${cfg.host}:${toString cfg.port}";
|
||||
Restart = "always";
|
||||
|
||||
LockPersonality = true;
|
||||
@@ -89,8 +85,6 @@ in {
|
||||
};
|
||||
};
|
||||
|
||||
users.groups = mkIf (cfg.group == "trok") {
|
||||
${cfg.group} = {};
|
||||
};
|
||||
users.groups = mkIf (cfg.group == "trok") { ${cfg.group} = { }; };
|
||||
};
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
{
|
||||
lib,
|
||||
buildGoModule,
|
||||
}:
|
||||
{ lib, buildGoModule }:
|
||||
buildGoModule {
|
||||
pname = "trok";
|
||||
version = "0.2.0";
|
||||
|
||||
src = ./.;
|
||||
src = ../.;
|
||||
vendorHash = "sha256-KwcLxkW3pbzujjc6JOZRwATlAA/qndf4FWpkJANv2z8=";
|
||||
|
||||
meta = {
|
||||
4
nix/shell.nix
Normal file
4
nix/shell.nix
Normal file
@@ -0,0 +1,4 @@
|
||||
{ callPackage, go, }:
|
||||
let mainPkg = callPackage ./package.nix { };
|
||||
in mainPkg.overrideAttrs
|
||||
(oa: { nativeBuildInputs = [ go ] ++ (oa.nativeBuildInputs or [ ]); })
|
||||
Reference in New Issue
Block a user