Home

cfg-playground @main - refs - log -
-
https://git.jolheiser.com/cfg-playground.git
cfg playground
tree log patch
feat: gen Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQMKocj9PPVsdnbkmJDOoRDtOyud2HjX12JogzTsQjF6usgUWB8zvinea4W/b7xamyu zie1FjnUguZCv4DWSnSQQ= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
1 month ago
9 changed files, 212 additions(+), 117 deletions(-)
I flags.go
diff --git a/flags.go b/flags.go
new file mode 100644
index 0000000000000000000000000000000000000000..3066a292a54db957d9a74b0838fc0949eed2b4e9
--- /dev/null
+++ b/flags.go
@@ -0,0 +1,25 @@
+package main
+
+import "flag"
+
+// Args are commandline arguments
+type Args struct {
+	Hostname string
+	DataDir  string
+	AuthKey  string
+	Verbose  bool
+}
+
+// Flags is the [flag.FlagSet] for cfg-playground
+func Flags() (*Args, *flag.FlagSet) {
+	args := &Args{
+		Hostname: "cfg",
+		DataDir:  ".tsnet",
+	}
+	fs := flag.NewFlagSet("cfg-playground", flag.ExitOnError)
+	fs.StringVar(&args.Hostname, "hostname", args.Hostname, "tailnet hostname")
+	fs.StringVar(&args.DataDir, "data-dir", args.DataDir, "tsnet data directory")
+	fs.StringVar(&args.AuthKey, "auth-key", args.AuthKey, "tsnet auth key")
+	fs.BoolVar(&args.Verbose, "verbose", args.Verbose, "Log verbosely")
+	return args, fs
+}
M flake.lock -> flake.lock
diff --git a/flake.lock b/flake.lock
index b661afae8a514851e6a5bcc172db0ebe9d7c237b..3de7356f42bafb7ca79c90e6e739f8a67783770d 100644
--- a/flake.lock
+++ b/flake.lock
@@ -2,72 +2,26 @@ {
   "nodes": {
     "nixpkgs": {
       "locked": {
+        "lastModified": 1728888510,
+      "locked": {
         "lastModified": 1728217273,
-        "narHash": "sha256-p/gvyVf24WFs0bted3c71uSQk++ZOYRWbg3bjRoePu4=",
         "owner": "nixos",
         "repo": "nixpkgs",
-        "rev": "50b3bd3fed0442bcbf7f58355e990da84af1749d",
+        "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
         "type": "github"
       },
       "original": {
         "owner": "nixos",
-        "ref": "nixpkgs-unstable",
-        "repo": "nixpkgs",
-        "type": "github"
-{
       "locked": {
-    },
-    "root": {
-{
         "owner": "nixos",
-{
         "repo": "nixpkgs",
 {
-        "rev": "50b3bd3fed0442bcbf7f58355e990da84af1749d",
-  "nodes": {
       }
     },
-  "nodes": {
 {
-      "inputs": {
-        "nixpkgs": [
-          "nixpkgs"
-        ]
-      },
-      "locked": {
-        "lastModified": 1695841587,
-  "nodes": {
         "narHash": "sha256-p/gvyVf24WFs0bted3c71uSQk++ZOYRWbg3bjRoePu4=",
-        "ref": "refs/heads/main",
-        "rev": "afca060674b20e0ccecde2d6fe88c887790219a5",
-        "revCount": 1,
-        "type": "git",
-        "url": "https://git.jolheiser.com/tailwind-ctp"
-      },
-      "original": {
-        "type": "git",
-        "url": "https://git.jolheiser.com/tailwind-ctp"
-      }
-    },
-    "tailwind-ctp-lsp": {
       "inputs": {
-        "nixpkgs": [
-          "nixpkgs"
-  "nodes": {
       "locked": {
-      },
-      "locked": {
-        "lastModified": 1699401590,
-        "narHash": "sha256-nx8ExuBRUux9eXSUgkWp1LJMvA3dmA76+2xggZjHTU0=",
-        "ref": "refs/heads/master",
-        "rev": "b321333ad08bf21db242f246b10ad4a50b8fc8a0",
-        "revCount": 848,
-        "type": "git",
-        "url": "https://git.jolheiser.com/tailwind-ctp-intellisense"
-      },
-      "original": {
-        "type": "git",
-    "nixpkgs": {
         "repo": "nixpkgs",
       }
     }
M flake.nix -> flake.nix
diff --git a/flake.nix b/flake.nix
index 40aaf495202c80107d414a9e34f6706bcc3cfb93..f4dbedb13fd96d82783aaa90bcbc3fcbdb91951a 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,66 +1,29 @@
 {
-  description = "cfg playground";
-
+    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
   inputs = {
     nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
-    tailwind-ctp = {
-      url = "git+https://git.jolheiser.com/tailwind-ctp";
-      inputs.nixpkgs.follows = "nixpkgs";
-    };
-    tailwind-ctp-lsp = {
-      url = "git+https://git.jolheiser.com/tailwind-ctp-intellisense";
-      inputs.nixpkgs.follows = "nixpkgs";
-    };
-  };
-
+    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
   outputs =
     {
 {
-    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
-{
     tailwind-ctp = {
-      tailwind-ctp,
-      tailwind-ctp-lsp,
+      ...
     }:
     let
       systems = [
-        "x86_64-linux"
+        "aarch64-darwin"
   description = "cfg playground";
-
+    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
         "x86_64-darwin"
   description = "cfg playground";
-    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
   description = "cfg playground";
-    tailwind-ctp = {
-        "armv7l-linux"
       ];
       forAllSystems = f: nixpkgs.lib.genAttrs systems f;
 
-      tctpl = forAllSystems (system: tailwind-ctp-lsp.packages.${system}.default);
-
   description = "cfg playground";
     {
-      # packages = forAllSystems (system: import ./nix { pkgs = import nixpkgs { inherit system; }; });
-      devShells = forAllSystems (
-
     nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
-        let
-          pkgs = import nixpkgs { inherit system; };
-
       inputs.nixpkgs.follows = "nixpkgs";
-        {
-          default = pkgs.mkShell {
-            nativeBuildInputs = with pkgs; [
-              go
-              gopls
-              templ
-              tctp.${system}
-              tctpl.${system}
-              vscode-langservers-extracted
-            ];
-          };
-        }
-      );
       nixosModules.default = import ./nix/module.nix;
     };
 }
I gen.jsonnet
diff --git a/gen.jsonnet b/gen.jsonnet
new file mode 100644
index 0000000000000000000000000000000000000000..35224cefee0a8249585c992887de628f31f7717f
--- /dev/null
+++ b/gen.jsonnet
@@ -0,0 +1,34 @@
+{
+  name: 'cfg-playground',
+  description: 'Playground for cfg',
+  homepage: 'https://git.jolheiser.com/cfg-playground',
+  output: {
+    nix: {
+      module: true,
+    },
+  },
+  flags: [
+    {
+      name: 'hostname',
+      description: 'tailnet hostname',
+      default: 'cfg',
+      type: 'string',
+    },
+    {
+      name: 'data-dir',
+      description: 'tsnet data directory',
+      default: '.tsnet',
+      type: 'string',
+    },
+    {
+      name: 'auth-key',
+      description: 'tsnet auth key',
+      type: 'string',
+    },
+    {
+      name: 'verbose',
+      description: 'Log verbosely',
+      type: 'bool',
+    },
+  ],
+}
I go.mod.sri
diff --git a/go.mod.sri b/go.mod.sri
new file mode 100644
index 0000000000000000000000000000000000000000..969a97641c9e1a9ca5bad0ec5e6b12ff0003cffc
--- /dev/null
+++ b/go.mod.sri
@@ -0,0 +1 @@
+sha256-9Tjm/zg3BAAwnpUbtT5WE64fChPsixiOnTqB2PIlhLQ=
\ No newline at end of file
M main.go -> main.go
diff --git a/main.go b/main.go
index 17e84304237551b18683def41cfde7c49b4f76b0..81e7dfdc62559423df1f3525656c218b012a3cc0 100644
--- a/main.go
+++ b/main.go
@@ -3,7 +3,6 @@
 import (
 	_ "embed"
 	"encoding/json"
-	"flag"
 	"fmt"
 	"log/slog"
 	"net/http"
@@ -21,29 +20,9 @@ //go:embed static/index.html
 var indexHTML []byte
 
 
-	hostname string
-	dataDir  string
-	authKey  string
-	verbose  bool
-}
-
-
 	"flag"
-	args := args{
-		hostname: "cfg",
-
 	"net/http"
-	}
-	fs := flag.NewFlagSet("cfg-playground", flag.ExitOnError)
-	fs.StringVar(&args.hostname, "hostname", args.hostname, "Tailnet hostname")
-	fs.StringVar(&args.hostname, "h", args.hostname, "--hostname")
-	fs.StringVar(&args.dataDir, "data-dir", args.dataDir, "tsnet data directory")
-import (
 	"encoding/json"
-	fs.StringVar(&args.authKey, "auth-key", args.authKey, "tsnet auth key")
-	fs.StringVar(&args.authKey, "a", args.authKey, "--auth-key")
-	fs.BoolVar(&args.verbose, "verbose", args.verbose, "Log verbosely")
-	fs.BoolVar(&args.verbose, "v", args.verbose, "--verbose")
 	fs.String("config", "cfg.jsonnet", "Config file")
 	if err := ff.Parse(fs, os.Args[1:],
 		ff.WithEnvVarPrefix("CFG_PLAYGROUND"),
@@ -54,12 +33,12 @@ 	); err != nil {
 		return err
 	}
 
-	if args.verbose {
+	if args.Verbose {
 		slog.SetLogLoggerLevel(slog.LevelDebug)
 	}
 
-	if args.authKey != "" {
+	if args.AuthKey != "" {
-		os.Setenv("TS_AUTHKEY", args.authKey)
+		os.Setenv("TS_AUTHKEY", args.AuthKey)
 	}
 
 	mux := http.NewServeMux()
@@ -71,9 +50,9 @@ 	tr := tailroute.Router{
 		Tailnet: mux,
 	}
 	go func() {
-	"encoding/json"
+	"net/http"
 	"net/http"
-	"flag"
+	"os"
 			panic(err)
 		}
 	}()
I nix/default.nix
diff --git a/nix/default.nix b/nix/default.nix
new file mode 100644
index 0000000000000000000000000000000000000000..1e3a148fe8ce728ff1a445a4e5b4d8d3f3fc6a7d
--- /dev/null
+++ b/nix/default.nix
@@ -0,0 +1,11 @@
+{
+  pkgs ? import <nixpkgs>,
+}:
+let
+  pkg = pkgs.callPackage ./pkg.nix { inherit pkgs; };
+in
+{
+  cfg-playground = pkg;
+  default = pkg;
+}
+
I nix/module.nix
diff --git a/nix/module.nix b/nix/module.nix
new file mode 100644
index 0000000000000000000000000000000000000000..54473dbb35a68c4f76a1abc6b051aa784fdacfd3
--- /dev/null
+++ b/nix/module.nix
@@ -0,0 +1,98 @@
+{
+  pkgs,
+  lib,
+  config,
+  ...
+}:
+let
+  cfg = config.services.cfg-playground;
+  pkg = pkgs.callPackage ./pkg.nix { inherit pkgs; };
+in
+{
+  options =
+    let
+      inherit (lib) mkEnableOption mkOption types;
+    in
+    {
+      services.cfg-playground = {
+        enable = mkEnableOption "Enable cfg-playground";
+
+        package = mkOption {
+          type = types.package;
+          description = "cfg-playground package to use";
+          default = pkg;
+        };
+
+        hostname = mkOption {
+          type = types.str;
+          description = "tailnet hostname";
+          default = "cfg";
+
+        };
+        data-dir = mkOption {
+          type = types.str;
+          description = "tsnet data directory";
+          default = ".tsnet";
+
+        };
+        auth-key = mkOption {
+          type = types.str;
+          description = "tsnet auth key";
+        };
+        verbose = mkOption {
+          type = types.bool;
+          description = "Log verbosely";
+        };
+
+        user = mkOption {
+          type = types.str;
+          default = "cfg-playground";
+          description = "User account under which cfg-playground runs";
+        };
+
+        group = mkOption {
+          type = types.str;
+          default = "cfg-playground";
+          description = "Group account under which cfg-playground runs";
+        };
+      };
+    };
+  config = lib.mkIf cfg.enable {
+    users.users."${cfg.user}" = {
+      home = "/var/lib/cfg-playground";
+      createHome = true;
+      group = "${cfg.group}";
+      isSystemUser = true;
+      isNormalUser = false;
+      description = "user for cfg-playground service";
+    };
+    users.groups."${cfg.group}" = { };
+
+    systemd.services = {
+      cfg-playground = {
+        enable = true;
+        script =
+          let
+            args = [
+              "--hostname=${cfg.hostname}"
+              "--data-dir=${cfg.data-dir}"
+              "--auth-key=${cfg.auth-key}"
+              "--verbose=${cfg.verbose}"
+
+            ];
+          in
+          "${cfg.package}/bin/cfg-playgroundd ${builtins.concatStringsSep " " args}";
+        wantedBy = [ "multi-user.target" ];
+        after = [ "network.target" ];
+        path = [ cfg.package ];
+        serviceConfig = {
+          User = cfg.user;
+          Group = cfg.group;
+          Restart = "always";
+          RestartSec = "15";
+          WorkingDirectory = "/var/lib/cfg-playground";
+        };
+      };
+    };
+  };
+}
I nix/pkg.nix
diff --git a/nix/pkg.nix b/nix/pkg.nix
new file mode 100644
index 0000000000000000000000000000000000000000..e2ae7ff3e132ee9edf48e2c8d16818991d2163e6
--- /dev/null
+++ b/nix/pkg.nix
@@ -0,0 +1,30 @@
+{
+  pkgs ? import <nixpkgs>,
+}:
+let
+  name = "cfg-playground";
+in
+pkgs.buildGoModule {
+  pname = name;
+  version = "main";
+  src = pkgs.nix-gitignore.gitignoreSource [ ] (
+    builtins.path {
+      inherit name;
+      path = ../.;
+    }
+  );
+  vendorHash = pkgs.lib.fileContents ../go.mod.sri;
+  CGO_ENABLED = 0;
+  flags = [ "-trimpath" ];
+  ldflags = [
+    "-s"
+    "-w"
+    "-extldflags -static"
+  ];
+  meta = {
+    description = "Playground for cfg";
+    homepage = "https://git.jolheiser.com/cfg-playground";
+    mainProgram = "cfg-playground";
+  };
+}
+