Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
.DS_Store
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@ test:
fmt:
goimports -local github.com/ThreeDotsLabs -l -w .


.PHONY: update-nix-hash
update-nix-hash:
@echo "Resetting vendorHash in Nix files..."
@sed -i.bak 's/vendorHash = ".*"/vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="/' flake.nix default.nix
@rm -f flake.nix.bak default.nix.bak
@echo "Calculating new vendorHash..."
@NEW_HASH=$$(nix build 2>&1 | awk '/got:/{print $$2}' | head -n 1) && \
if [ -n "$$NEW_HASH" ]; then \
echo "Found new hash: $$NEW_HASH"; \
sed -i.bak "s/vendorHash = \".*\"/vendorHash = \"$$NEW_HASH\"/" flake.nix default.nix; \
rm -f flake.nix.bak default.nix.bak; \
echo "Nix files updated successfully."; \
else \
echo "Failed to calculate new hash. Are there other Nix build errors?"; \
git checkout flake.nix default.nix; \
exit 1; \
fi
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ brew install ThreeDotsLabs/tap/tdl
sudo /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/ThreeDotsLabs/cli/master/install.sh)" -- -b /usr/local/bin
```

### Nix (macOS, Linux)

```sh
nix profile add github:ThreeDotsLabs/cli
```

### Script (Windows)

Install to your home directory:
Expand Down
17 changes: 17 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ pkgs ? import <nixpkgs> {}, version ? "dev" }:

pkgs.buildGoModule rec {
pname = "tdl";
inherit version;

src = ./.;

subPackages = [ "tdl" ];

vendorHash = "sha256-Q3MwzslcVv9h3QZAfqnAYmkdVtWeJnhXqYvhZmb3hps=";
Copy link
Member

Choose a reason for hiding this comment

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

when it will require re-generation?

could it make sense to add script in makefile to regenerate it and if it may change often add CI task that can verify it?

Copy link
Author

Choose a reason for hiding this comment

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

It will only require regeneration whenever the Go dependencies (go.mod/go.sum) change.


ldflags = [
"-s" "-w"
"-X main.version=${version}"
];
}
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
description = "ThreeDotsLabs CLI";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
version = if self ? rev then self.rev else "dev";
Copy link
Member

Choose a reason for hiding this comment

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

just to double check, will it work with our tags/github semver releases?

Copy link
Author

Choose a reason for hiding this comment

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

Yep, it works perfectly with tags Users can install a specific release by just appending the tag, like nix profile add github:ThreeDotsLabs/cli/v1.0.0.

in
{
packages.default = pkgs.buildGoModule {
pname = "tdl";
version = version;
src = ./.;

subPackages = [ "tdl" ];

vendorHash = "sha256-Q3MwzslcVv9h3QZAfqnAYmkdVtWeJnhXqYvhZmb3hps=";

ldflags = [
"-s" "-w"
"-X main.version=${version}"
"-X main.commit=${if self ? rev then self.rev else "dirty"}"
];
};
}
);
}