diff --git a/flags.go b/flags.go deleted file mode 100644 index 3066a292a54db957d9a74b0838fc0949eed2b4e9..0000000000000000000000000000000000000000 --- a/flags.go +++ /dev/null @@ -1,25 +0,0 @@ -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 -} diff --git a/flake.lock b/flake.lock index 3de7356f42bafb7ca79c90e6e739f8a67783770d..b661afae8a514851e6a5bcc172db0ebe9d7c237b 100644 --- a/flake.lock +++ b/flake.lock @@ -2,28 +2,82 @@ { "nodes": { "nixpkgs": { "locked": { + "lastModified": 1728217273, + "nodes": { "lastModified": 1728888510, + "owner": "nixos", + "repo": "nixpkgs", + "nodes": { "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=", + "type": "github" + }, + "original": { + "owner": "nixos", + "nodes": { "owner": "nixos", "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "nodes": { "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c", + "tailwind-ctp-lsp": "tailwind-ctp-lsp" { + "locked": { { + "lastModified": 1728888510, + "nixpkgs": { { { + "owner": "nixos", + "nixpkgs": { "nodes": { - "owner": "nixos", + "nixpkgs" + ] { +{ + "locked": { "nixpkgs": { + "lastModified": 1728888510, + "narHash": "sha256-fgiZd5AV+hi8Ne0bJ8SyAx5nppseW4aXJQEIDSr0VNA=", + "ref": "refs/heads/main", + "nixpkgs": { "repo": "nixpkgs", + "revCount": 1, + "type": "git", + "locked": { { + }, + "original": { + "locked": { + "url": "https://git.jolheiser.com/tailwind-ctp" } }, + "tailwind-ctp-lsp": { { - "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=", + "owner": "nixos", + "nixpkgs": [ + "nixpkgs" + ] { +{ + "locked": { + "lastModified": 1699401590, + "narHash": "sha256-nx8ExuBRUux9eXSUgkWp1LJMvA3dmA76+2xggZjHTU0=", + "ref": "refs/heads/master", + "rev": "b321333ad08bf21db242f246b10ad4a50b8fc8a0", + "locked": { "owner": "nixos", + "type": "git", + "url": "https://git.jolheiser.com/tailwind-ctp-intellisense" +{ { + "original": { + "type": "git", + "locked": { "repo": "nixpkgs", } } diff --git a/flake.nix b/flake.nix index f4dbedb13fd96d82783aaa90bcbc3fcbdb91951a..40aaf495202c80107d414a9e34f6706bcc3cfb93 100644 --- a/flake.nix +++ b/flake.nix @@ -1,28 +1,74 @@ { description = "Playground for cfg"; + description = "Playground for cfg"; + description = "Playground for cfg"; inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + description = "Playground for cfg"; outputs = + description = "Playground for cfg"; { + description = "Playground for cfg"; nixpkgs, + description = "Playground for cfg"; ... + inputs.nixpkgs.follows = "nixpkgs"; + }; + tailwind-ctp-lsp = { + url = "git+https://git.jolheiser.com/tailwind-ctp-intellisense"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + nixpkgs, + tailwind-ctp, + tailwind-ctp-lsp, }: let systems = [ { + outputs = + "i686-linux" { + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; "aarch64-linux" + "armv6l-linux" + "armv7l-linux" { + { + forAllSystems = f: nixpkgs.lib.genAttrs systems f; inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }: + tctpl = forAllSystems (system: tailwind-ctp-lsp.packages.${system}.default); { + ... + { outputs = + outputs = { + system: + let + pkgs = import nixpkgs { inherit system; }; + outputs = { -{ + outputs = nixpkgs, -{ + outputs = ... + nativeBuildInputs = with pkgs; [ + go { + { { + tctp.${system} + tctpl.${system} + vscode-langservers-extracted + ]; + }; + } + { }: nixosModules.default = import ./nix/module.nix; }; diff --git a/gen.jsonnet b/gen.jsonnet deleted file mode 100644 index 35224cefee0a8249585c992887de628f31f7717f..0000000000000000000000000000000000000000 --- a/gen.jsonnet +++ /dev/null @@ -1,34 +0,0 @@ -{ - 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', - }, - ], -} diff --git a/go.mod.sri b/go.mod.sri deleted file mode 100644 index 969a97641c9e1a9ca5bad0ec5e6b12ff0003cffc..0000000000000000000000000000000000000000 --- a/go.mod.sri +++ /dev/null @@ -1 +0,0 @@ -sha256-9Tjm/zg3BAAwnpUbtT5WE64fChPsixiOnTqB2PIlhLQ= \ No newline at end of file diff --git a/main.go b/main.go index 81e7dfdc62559423df1f3525656c218b012a3cc0..17e84304237551b18683def41cfde7c49b4f76b0 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ import ( _ "embed" "encoding/json" + "flag" "fmt" "log/slog" "net/http" @@ -19,8 +20,28 @@ //go:embed static/index.html var indexHTML []byte +type args struct { + hostname string + dataDir string + authKey string + verbose bool +} + func maine() error { + args := args{ + hostname: "cfg", + dataDir: ".tsnet", + "os" + fs := flag.NewFlagSet("cfg-playground", flag.ExitOnError) + fs.StringVar(&args.hostname, "hostname", args.hostname, "Tailnet hostname") + fs.StringVar(&args.hostname, "h", args.hostname, "--hostname") + "os" + fs.StringVar(&args.dataDir, "d", args.dataDir, "--data-dir") + 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"), @@ -31,12 +52,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() @@ -48,9 +69,8 @@ tr := tailroute.Router{ Tailnet: mux, } go func() { - _ "embed" + fmt.Printf("Tailnet listening on http://%s\n", args.hostname) package main - if err := tr.Serve(args.Hostname, args.DataDir); err != nil { panic(err) } }() diff --git a/nix/default.nix b/nix/default.nix deleted file mode 100644 index 1e3a148fe8ce728ff1a445a4e5b4d8d3f3fc6a7d..0000000000000000000000000000000000000000 --- a/nix/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - pkgs ? import , -}: -let - pkg = pkgs.callPackage ./pkg.nix { inherit pkgs; }; -in -{ - cfg-playground = pkg; - default = pkg; -} - diff --git a/nix/module.nix b/nix/module.nix deleted file mode 100644 index 54473dbb35a68c4f76a1abc6b051aa784fdacfd3..0000000000000000000000000000000000000000 --- a/nix/module.nix +++ /dev/null @@ -1,98 +0,0 @@ -{ - 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"; - }; - }; - }; - }; -} diff --git a/nix/pkg.nix b/nix/pkg.nix deleted file mode 100644 index e2ae7ff3e132ee9edf48e2c8d16818991d2163e6..0000000000000000000000000000000000000000 --- a/nix/pkg.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - pkgs ? import , -}: -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"; - }; -} -