From 97de9b512b65d867e4b8589cdb098c608f923a52 Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Tue, 31 Mar 2026 13:06:10 +0200 Subject: [PATCH 1/6] feat: add Nix flake for building, running, and installing dstask Provides buildGoModule derivation for both dstask and dstask-import, with proper ldflags for version info. Includes a dev shell with go and golangci-lint. Closes #209 --- flake.lock | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix 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..aee441b --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + 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"; + + lastModifiedDate = builtins.substring 0 4 self.lastModifiedDate + + "-" + builtins.substring 4 2 self.lastModifiedDate + + "-" + builtins.substring 6 2 self.lastModifiedDate; + 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}" + "-X github.com/naggie/dstask.BUILD_DATE=${lastModifiedDate}" + ]; + + 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 + ]; + }; + } + ); +} From c9103c38db57cbcb164e0e43d78d51c7b1fb2ff9 Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Tue, 31 Mar 2026 13:06:25 +0200 Subject: [PATCH 2/6] refactor: replace shell.nix with flake-compat shim Delegates to the flake's devShell so both `nix-shell` and `nix develop` use the same environment. --- shell.nix | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) 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 From 858dd3702d3443df8f28fef4d8b45392c6700980 Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Tue, 31 Mar 2026 13:06:40 +0200 Subject: [PATCH 3/6] ci: add nix-build job to catch stale vendorHash Runs `nix build` and `nix flake check` on every push/PR. A stale vendorHash causes a hash mismatch error, so dependency changes that forget to update the hash will fail CI. --- .github/workflows/ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 From 322802b741b06faf8b5ca1a5182f1e8f28f4854b Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Tue, 31 Mar 2026 13:07:01 +0200 Subject: [PATCH 4/6] docs: add Nix flake installation instructions to README --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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) From 15e69ccda12c71d50ca36ae667087477324876d3 Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Tue, 31 Mar 2026 13:07:21 +0200 Subject: [PATCH 5/6] chore: gitignore nix build result symlink --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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/ From 26ceac0fe73ef3ebf3f6ceb1d2bdb534e13c648d Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Tue, 31 Mar 2026 15:28:23 +0200 Subject: [PATCH 6/6] refactor: drop BUILD_DATE from flake and hide when unset The commit hash already identifies the build. The date added complexity (reformatting self.lastModifiedDate) for little value, especially since Nix builds prioritize reproducibility. Only print the 'Build date' line when a real value is injected (e.g. by goreleaser). Plain `go build` and Nix builds leave it as the default 'Unknown', which is just noise. --- commands.go | 10 ++++------ flake.nix | 5 ----- 2 files changed, 4 insertions(+), 11 deletions(-) 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.nix b/flake.nix index aee441b..7070f66 100644 --- a/flake.nix +++ b/flake.nix @@ -13,10 +13,6 @@ outputs = { self, nixpkgs, flake-utils, ... }: let version = "1.0.1"; - - lastModifiedDate = builtins.substring 0 4 self.lastModifiedDate - + "-" + builtins.substring 4 2 self.lastModifiedDate - + "-" + builtins.substring 6 2 self.lastModifiedDate; in flake-utils.lib.eachDefaultSystem (system: let @@ -39,7 +35,6 @@ "-s" "-w" "-X github.com/naggie/dstask.GIT_COMMIT=${self.shortRev or "dirty"}" "-X github.com/naggie/dstask.VERSION=${version}" - "-X github.com/naggie/dstask.BUILD_DATE=${lastModifiedDate}" ]; meta = with pkgs.lib; {