diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 408b310..e1caefa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,22 @@ jobs: go test -v -mod=vendor ./... ./integrationtest.sh + nix-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v31 + + - name: Build + run: nix build + + - name: Flake check + run: nix flake check + windows-test: runs-on: windows-latest diff --git a/.gitignore b/.gitignore index 8cf38ed..4bbfb8d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,8 @@ dist # Vendor directory vendor + +# Nix build output +result # Added by goreleaser init: dist/ diff --git a/README.md b/README.md index 0ebbb46..de3b147 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,27 @@ Alternatively, hardcode the absolute path to the repository if `PSScriptRoot` is . "C:\\Users\\\\source\\repos\\dstask-win-port\\completions\\powershell.ps1" ``` +## Nix Flake + +Run directly without installing: + +```sh +nix run github:naggie/dstask -- version +``` + +Install into your profile: + +```sh +nix profile install github:naggie/dstask +``` + +Dev shell (Go + golangci-lint): + +```sh +nix develop # with flakes +nix-shell # legacy, uses flake-compat shim +``` + There are also unofficial packages for: - [Nix](https://nixos.org/nixos/packages.html?attr=dstask&channel=nixpkgs-unstable&query=dstask) diff --git a/commands.go b/commands.go index 571b7e3..e133421 100644 --- a/commands.go +++ b/commands.go @@ -704,10 +704,8 @@ func CommandUndo(conf Config, args []string, ctx, query Query) error { // CommandVersion prints version information for the dstask binary. func CommandVersion() { - fmt.Printf( - "Version: %s\nGit commit: %s\nBuild date: %s\n", - VERSION, - GIT_COMMIT, - BUILD_DATE, - ) + fmt.Printf("Version: %s\nGit commit: %s\n", VERSION, GIT_COMMIT) + if BUILD_DATE != "Unknown" { + fmt.Printf("Build date: %s\n", BUILD_DATE) + } } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1a6aac3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1774709303, + "narHash": "sha256-D3Q07BbIA2KnTcSXIqqu9P586uWxN74zNoCH3h2ESHg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8110df5ad7abf5d4c0f6fb0f8f978390e77f9685", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "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", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7070f66 --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +{ + description = "dstask - single binary terminal-based TODO manager"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + let + version = "1.0.1"; + in + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.default = pkgs.buildGoModule { + pname = "dstask"; + inherit version; + src = ./.; + + # To update after changing go.mod/go.sum: + # 1. Set vendorHash = pkgs.lib.fakeHash; + # 2. Run `nix build` and let it fail + # 3. Copy the "got" hash from the error into vendorHash + vendorHash = "sha256-HSqAbxkkjuMulFymeqApWr/JZ+a7OUTu5EYLGPL/j2U="; + + subPackages = [ "cmd/dstask" "cmd/dstask-import" ]; + + ldflags = [ + "-s" "-w" + "-X github.com/naggie/dstask.GIT_COMMIT=${self.shortRev or "dirty"}" + "-X github.com/naggie/dstask.VERSION=${version}" + ]; + + meta = with pkgs.lib; { + description = "Single binary terminal-based TODO manager"; + homepage = "https://github.com/naggie/dstask"; + license = licenses.mit; + mainProgram = "dstask"; + }; + }; + + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + go + golangci-lint + ]; + }; + } + ); +} diff --git a/shell.nix b/shell.nix index d19356b..d443083 100644 --- a/shell.nix +++ b/shell.nix @@ -1,9 +1,4 @@ -{ pkgs ? import {} }: - -pkgs.mkShell { - - buildInputs = with pkgs; [ - go - ]; - -} +# Compat shim so `nix-shell` uses the same devShell as `nix develop`. +(import (fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz") { + src = ./.; +}).shellNix.default