tailscale-dev / tailscale-dev/tclip

Offer NixOS module

Open
#63 2 comments 0 reactions 1 assignee View on GitHub

@fzakaria is already working on this.

Since Aug 14, 2024.

enhancement
Dominant language
CSS
Stars
265
Forks
25
PR merge metrics
No merged PRs in 30d

Description

A nixos module similar to what is offered in golink would be great.

Here is a starter version I am using

{
  config,
  pkgs,
  lib,
  inputs,
  ...
}:
with lib; let
  cfg = config.services.tclip;
in {
  options.services.tclip = {
    enable = mkEnableOption "Enable tclip service";

    package = mkOption {
      type = types.package;
      description = ''
        tclip package to use
      '';
      default = inputs.tailscale-tclip.packages."${pkgs.system}".tclipd;
    };

    dataDir = mkOption {
      type = types.path;
      default = "/var/lib/tclip";
      description = "Path to data dir";
    };

    hostname = mkOption {
      type = types.str;
      default = "paste";
      description = "Hostname to use on your tailnet";
    };

    funnel = mkOption {
      type = types.bool;
      default = false;
      description = "if set, expose individual pastes to the public internet with Funnel";
    };

    user = mkOption {
      type = types.str;
      default = "tclip";
      description = "User account under which tclip runs.";
    };

    group = mkOption {
      type = types.str;
      default = "tclip";
      description = "Group account under which tclip runs.";
    };

    tailscaleAuthKeyFile = mkOption {
      type = types.path;
      description = "Path to file containing the Tailscale Auth Key";
    };

    verbose = mkOption {
      type = types.bool;
      default = false;
    };
  };
  config = mkIf cfg.enable {
    environment.systemPackages = [
      inputs.tailscale-tclip.packages."${pkgs.system}".tclip
    ];

    users.users."${cfg.user}" = {
      home = cfg.dataDir;
      createHome = true;
      group = "${cfg.group}";
      isSystemUser = true;
      isNormalUser = false;
      description = "User for tclip service";
    };
    users.groups."${cfg.group}" = {};

    systemd.services.tclip = {
      enable = true;
      script = let
        args =
          [
            "--data-dir"
            cfg.dataDir
            "--hostname"
            cfg.hostname
          ]
          ++ lib.optionals cfg.verbose ["--tsnet-verbose"]
          ++ lib.optionals cfg.funnel ["--use-funnel"];
      in ''
        ${lib.optionalString (cfg.tailscaleAuthKeyFile != null) ''
          export TS_AUTHKEY="$(head -n1 ${lib.escapeShellArg cfg.tailscaleAuthKeyFile})"
        ''}
        ${cfg.package}/bin/tclipd ${builtins.concatStringsSep " " args};
      '';
      wantedBy = ["multi-user.target"];
      serviceConfig = {
        User = cfg.user;
        Group = cfg.group;
        Restart = "always";
        RestartSec = "15";
        WorkingDirectory = "${cfg.dataDir}";
      };
    };
  };
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.