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
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SED := $(shell command -v gsed 2>/dev/null)
else
SED := sed
endif

BINARY_NAME := dnsimple
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags "-X main.version=$(VERSION)"

.PHONY: build install test lint clean
.PHONY: build install test lint clean nix-update-hash

build:
go build $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/dnsimple
Expand All @@ -18,3 +25,14 @@ lint:

clean:
rm -rf bin/

nix-update-hash:
ifndef SED
$(error gsed is required on macOS — install with: brew install gnu-sed)
endif
@OLD_HASH=$$(grep 'vendorHash' default.nix | $(SED) 's/.*"\(.*\)".*/\1/') && \
$(SED) -i 's|vendorHash = ".*"|vendorHash = lib.fakeHash|' default.nix && \
NEW_HASH=$$(nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}' 2>&1 | grep 'got:' | awk '{print $$2}') && \
$(SED) -i "s|vendorHash = lib.fakeHash|vendorHash = \"$$NEW_HASH\"|" default.nix && \
echo "Updated vendorHash to $$NEW_HASH" || \
($(SED) -i "s|vendorHash = lib.fakeHash|vendorHash = \"$$OLD_HASH\"|" default.nix && echo "Failed to compute hash" && exit 1)
31 changes: 31 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
pkgs ? import <nixpkgs> { },
lib ? pkgs.lib,
buildGoModule ? pkgs.buildGoModule,
version ? "dev",
}:

buildGoModule {
pname = "dnsimple";
inherit version;

src = lib.cleanSource ./.;

vendorHash = "sha256-9lVLlPokN+tIaKHgVhaCGzsnlpmjgLunBEoPhRZkrVU=";

ldflags = [
"-s"
"-w"
"-X main.version=${version}"
];

subPackages = [ "cmd/dnsimple" ];

meta = {
description = "Command-line interface for the DNSimple API";
homepage = "https://github.com/dnsimple/cli";
license = lib.licenses.mit;
maintainers = [ "DNSimple" ];
mainProgram = "dnsimple";
};
}
27 changes: 27 additions & 0 deletions flake.lock

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

44 changes: 44 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
description = "Command-line interface for the DNSimple API";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For performance reasons it is recommended to use hydra tarballs, especially for independant repos.

See
https://discourse.nixos.org/t/questions-about-inputs-nixpkgs/69095/14?u=malix
and an example in repo of https://github.com/NixOS/nixos-hardware/blob/6358ff76821101c178e3ab4919a62799bfe3652e/flake.nix#L4

};

outputs =
{ self, nixpkgs }:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
version = self.shortRev or self.dirtyShortRev or "dev";
in
{
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
dnsimple = pkgs.callPackage ./default.nix { inherit version; };
default = self.packages.${system}.dnsimple;
}
);

devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = pkgs.mkShell {
buildInputs = [ pkgs.go ];
};
}
);
};
}
8 changes: 8 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
pkgs ? import <nixpkgs> { },
}:
pkgs.mkShell {
packages = [
pkgs.go
];
}