Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce nixos module for tclip #64

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fzakaria
Copy link

@fzakaria fzakaria commented Aug 12, 2024

  • Add a nixosModule
  • Add an overlay

This how I tested it:

  • Created separate flake.nix
  • build it via nixos-rebuild build-vm --flake ".#test"
{
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
  inputs.tclip.url = "path:/home/fmzakari/code/github.com/tailscale-dev/tclip";
  outputs = {
    self,
    nixpkgs,
    tclip,
    ...
  }: let
    system = "x86_64-linux";
  in {
    # test is a hostname for our machine
    nixosConfigurations.test = nixpkgs.lib.nixosSystem {
      inherit system;
      modules = [
        tclip.nixosModules.default
        ({config, ...}: {
          users.users.alice = {
            isNormalUser = true;
            extraGroups = ["wheel"]; # Enable ‘sudo’ for the user.
            initialPassword = "test";
          };
          services.tclip.enable = true;
          # just give some fake file for now
          services.tclip.tailscaleAuthKeyFile = ./flake.lock;
          system.stateVersion = "24.05";
        })
      ];
    };
  };
}

Validation

<<< Welcome to NixOS 24.05.20240811.a731b45 (x86_64) - ttyS0 >>>

Run 'nixos-help' for the NixOS manual.

nixos login: alice
Password: 

[alice@nixos:~]$ which tclip
/run/current-system/sw/bin/tclip

[alice@nixos:~]$ tclip --help
Usage: tclip [filename]

Takes a file or standard in and posts it to your tailnet's tclip service. Returns a URL on standard out for sharing.

Flags:
  -n string
    	filename to use for pastes from standard input
  -target string
    	tclip server URL (default "http://paste")

[alice@nixos:~]$ systemctl status tclip
● tclip.service
     Loaded: loaded (/etc/systemd/system/tclip.service; enabled; preset: enable>
     Active: activating (auto-restart) (Result: exit-code) since Tue 2024-08-13>
    Process: 931 ExecStart=/nix/store/qfs9i87qa3m3yx84fq2amfjaijx5s3zb-unit-scr>
   Main PID: 931 (code=exited, status=2)
         IP: 0B in, 0B out
        CPU: 39ms

fixes #63

* Add a nixosModule
* Add an overlay

fixes tailscale-dev#63
}:
{
overlays.default = final: prev: {
tclip = self.packages."${prev.system}".tclip;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I look at other examples https://github.com/ryantm/agenix they are structured differently; t
the overlay defines the packages and then packages attribute just pull it out of nixpkgs itself.

This goes in the other direction; not sure how "wrong" that is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any strong feelings here, as long as it works well and doesn't break or complicate anything.


docker = pkgs.dockerTools.buildLayeredImage {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are from formatting; I added formatter as an attribute so nix fmt should keep this consistent.

@fzakaria
Copy link
Author

I would love if someone else can test this out too; I'll post on my twitter.

@fzakaria
Copy link
Author

@Erisa let me know what you think.
I added more description to demonstrate it running in a VM.

The systemd service was failing to run because I gave it an invalid auth key.

@Erisa Erisa self-requested a review August 14, 2024 01:32
@Erisa Erisa self-assigned this Aug 14, 2024
@Erisa Erisa added the enhancement New feature or request label Aug 14, 2024
Copy link
Member

@Erisa Erisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing this! Sorry for the delay getting around to reviewing this.

Are you able to

My experience with NixOS (especially with flakes) is a little lacking and while I was able to add this as an input for a flake, I had difficulty getting it to work in order to test. I imagine the README changes should help with that!

@fzakaria
Copy link
Author

fzakaria commented Oct 3, 2024

@Erisa I plan to revisit your comments; I've just been busy.

For those who want to see a working version, I've been running in my NixOS configuration
https://github.com/fzakaria/nix-home/blob/master/modules/nixos/tclip.nix

@Erisa
Copy link
Member

Erisa commented Oct 3, 2024

Thanks for the example - and no worries about being busy, I have been as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offer NixOS module
2 participants