diff --git a/flake.nix b/flake.nix index 1857e83..9b0d24e 100644 --- a/flake.nix +++ b/flake.nix @@ -6,19 +6,40 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils, ... }: + outputs = + { + self, + nixpkgs, + flake-utils, + ... + }: flake-utils.lib.eachDefaultSystem ( system: let - pkgs = nixpkgs.legacyPackages.${system}; - buildDeps = with pkgs; [ git go_1_21 gnumake ]; - devDeps = with pkgs; - buildDeps ++ [ + overlay = import ./nix/pkgs; + + pkgs = import nixpkgs { + inherit system; + overlays = [ overlay ]; + }; + + buildDeps = with pkgs; [ + git + go_1_21 + gnumake + ]; + + devDeps = + with pkgs; + buildDeps + ++ [ easyjson goreleaser + copywrite ]; in - { devShell = pkgs.mkShell { buildInputs = devDeps; }; } + { + devShell = pkgs.mkShell { buildInputs = devDeps; }; + } ); - } diff --git a/nix/pkgs/copywrite.nix b/nix/pkgs/copywrite.nix new file mode 100644 index 0000000..6a2a058 --- /dev/null +++ b/nix/pkgs/copywrite.nix @@ -0,0 +1,56 @@ +{ + lib, + buildGoModule, + fetchFromGitHub, + installShellFiles, + testers, + copywrite, +}: + +buildGoModule rec { + pname = "copywrite"; + version = "0.19.0"; + + src = fetchFromGitHub { + owner = "hashicorp"; + repo = "copywrite"; + rev = "6ed520a710166c6094098b786c63f212604654a4"; # matches tag release + hash = "sha256-DmlPioaw/wMk8GoBYNG24P4J1C6h0bjVjjOuMYW6Tgo="; + }; + + vendorHash = "sha256-ZIu0/fue3xi+YVE9GFsVjCNs8t3c3TWH8O0xUzJdim8="; + + shortRev = builtins.substring 0 7 src.rev; + + ldflags = [ + "-s" + "-w" + "-X github.com/hashicorp/copywrite/cmd.version=${version}" + "-X github.com/hashicorp/copywrite/cmd.commit=${shortRev}" + ]; + + CGO_ENABLED = 0; + + nativeBuildInputs = [ installShellFiles ]; + postInstall = '' + $out/bin/copywrite completion bash > copywrite.bash + $out/bin/copywrite completion zsh > copywrite.zsh + $out/bin/copywrite completion fish > copywrite.fish + installShellCompletion copywrite.{bash,zsh,fish} + ''; + + passthru.tests.version = testers.testVersion { + package = copywrite; + command = "copywrite --version"; + version = "${version}-${shortRev}"; + }; + + meta = { + description = "Automate copyright headers and license files at scale"; + mainProgram = "copywrite"; + homepage = "https://github.com/hashicorp/copywrite"; + changelog = "https://github.com/hashicorp/copywrite/releases/tag/v${version}"; + license = lib.licenses.mpl20; + maintainers = with lib.maintainers; [ dvcorreia ]; + }; +} \ No newline at end of file diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix new file mode 100644 index 0000000..c417077 --- /dev/null +++ b/nix/pkgs/default.nix @@ -0,0 +1,3 @@ +final: prev: { + copywrite = final.callPackage ./copywrite.nix { }; +} \ No newline at end of file