diff --git a/.gitignore b/.gitignore index ffaee5dc..b829c98c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ bin/ # Direnv /.direnv/ +# Nix +result + # Completion debug files completion.txt diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5538059c..0c99e7f6 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,11 +1,13 @@ -project_name: omloxctl +version: 2 + +project_name: omlox-cli git: tag_sort: "-version:creatordate" prerelease_suffix: "-" builds: - - main: ./cmd/omlox + - main: ./cmd/omlox-cli env: - CGO_ENABLED=0 goos: @@ -20,7 +22,7 @@ builds: - -trimpath ldflags: - "-s -w" - - "-X main.version={{.Version}} -X main.commitHash={{.Commit}} -X main.buildDate={{.Date}}" + - "-X main.version={{.Version}} -X main.commitHash={{.Commit}}" archives: - format: tar.gz diff --git a/Makefile b/Makefile index 041d539e..a17223db 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,8 @@ VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD) COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null) -DATE_FMT = +%FT%TZ # ISO 8601 -BUILD_DATE ?= $(shell date "$(DATE_FMT)") # "-u" for UTC time (zero offset) - BUILD_DIR ?= bin -LDFLAGS += "-X main.version=$(VERSION) -X main.commitHash=$(COMMIT_HASH) -X main.buildDate=$(BUILD_DATE)" +LDFLAGS += "-X main.version=$(VERSION) -X main.commitHash=$(COMMIT_HASH) .DEFAULT_GOAL: help default: help diff --git a/cmd/omlox-cli/omlox.go b/cmd/omlox-cli/omlox.go index c768cf8c..01d40abd 100644 --- a/cmd/omlox-cli/omlox.go +++ b/cmd/omlox-cli/omlox.go @@ -12,7 +12,6 @@ import ( var ( version string commitHash string - buildDate string ) const ( diff --git a/cmd/omlox-cli/version.go b/cmd/omlox-cli/version.go index 8650d52d..66152be4 100644 --- a/cmd/omlox-cli/version.go +++ b/cmd/omlox-cli/version.go @@ -26,5 +26,5 @@ func newVersionCmd(out io.Writer) *cobra.Command { // getVersion returns a string version information. func getVersion() string { - return fmt.Sprintf("%s version %s (%s) built on %s\n", appName, version, commitHash, buildDate) + return fmt.Sprintf("%s version %s (%s)\n", appName, version, commitHash) } diff --git a/flake.lock b/flake.lock index 7faedb3c..ad0cbfe5 100644 --- a/flake.lock +++ b/flake.lock @@ -1,30 +1,12 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1701436327, - "narHash": "sha256-tRHbnoNI8SIM5O5xuxOmtSLnswEByzmnQcGGyNRjxsE=", + "lastModified": 1750134718, + "narHash": "sha256-v263g4GbxXv87hMXMCpjkIxd/viIF7p3JpJrwgKdNiI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "91050ea1e57e50388fa87a3302ba12d188ef723a", + "rev": "9e83b64f727c88a7711a2c463a7b16eedb69a84c", "type": "github" }, "original": { @@ -35,24 +17,8 @@ }, "root": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 9b0d24ef..e2cb2fa5 100644 --- a/flake.nix +++ b/flake.nix @@ -3,43 +3,61 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, - flake-utils, ... }: - flake-utils.lib.eachDefaultSystem ( - system: - let - overlay = import ./nix/pkgs; + let + supportedSystems = [ + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + "x86_64-linux" + ]; - pkgs = import nixpkgs { + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); + nixpkgsFor = forAllSystems ( + system: + import nixpkgs { inherit system; - overlays = [ overlay ]; + overlays = [ self.overlays.default ]; + } + ); + + version = self.shortRev or self.dirtyShortRev; + commitHash = self.rev or self.dirtyRev; + in + { + overlays.default = final: _: { + omlox-cli = final.callPackage ./package.nix { + inherit version commitHash; }; + }; + + formatter = forAllSystems (system: (nixpkgsFor.${system}).nixfmt-tree); - buildDeps = with pkgs; [ - git - go_1_21 - gnumake - ]; + packages = forAllSystems (system: { + default = (nixpkgsFor.${system}).omlox-cli; + omlox-cli = (nixpkgsFor.${system}).omlox-cli; + }); - devDeps = - with pkgs; - buildDeps - ++ [ - easyjson - goreleaser - copywrite - ]; - in - { - devShell = pkgs.mkShell { buildInputs = devDeps; }; - } - ); + devShells = forAllSystems ( + system: with nixpkgsFor.${system}; { + default = mkShell { + inputsFrom = [ omlox-cli ]; + packages = [ + git + gnumake + easyjson + goreleaser + copywrite + ]; + }; + } + ); + }; } diff --git a/nix/pkgs/copywrite.nix b/nix/pkgs/copywrite.nix deleted file mode 100644 index 6a2a058f..00000000 --- a/nix/pkgs/copywrite.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ - 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 deleted file mode 100644 index c4170779..00000000 --- a/nix/pkgs/default.nix +++ /dev/null @@ -1,3 +0,0 @@ -final: prev: { - copywrite = final.callPackage ./copywrite.nix { }; -} \ No newline at end of file diff --git a/package.nix b/package.nix new file mode 100644 index 00000000..c6002466 --- /dev/null +++ b/package.nix @@ -0,0 +1,22 @@ +{ + lib, + buildGoModule, + version ? 0.0.0, + commitHash ? "unknown", +}: + +buildGoModule (finalAttrs: { + pname = "omlox-cli"; + inherit version; + + src = ./.; + + vendorHash = "sha256-Gwkse7dl/EYxHSibgc6PMGwtDhKiMJYFajwAICpluzw="; + + ldflags = [ + "-s" + "-w" + "-X main.version=${version}" + "-X main.commitHash=${commitHash}" + ]; +}) \ No newline at end of file