From 4b8d8ef9782f296355323081f047cb9125614f1c Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 27 Jun 2026 15:17:40 +0800 Subject: [PATCH] Add flake and nix run packaging --- .envrc | 1 + .gitignore | 2 ++ flake.lock | 27 +++++++++++++++++ flake.nix | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..bc0f4a9b --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake path:. diff --git a/.gitignore b/.gitignore index ae035cd2..7e2ac704 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ dist/ .venv*/ var/ .DS_Store +.direnv/ +result .agents/ /.idea/ /CLAUDE.md diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..a94690dc --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1782467914, + "narHash": "sha256-pGvFkM8N0xEkIIXDe5YYfbEAvHrk4IxBrjB/x8OomhE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e73de5be04e0eff4190a1432b946d469c794e7b4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..a6230947 --- /dev/null +++ b/flake.nix @@ -0,0 +1,86 @@ +{ + description = "DingTalk Workspace CLI development environment"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs, ... }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); + in + { + packages = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + in + rec { + dws = pkgs.buildGoModule { + pname = "dingtalk-workspace-cli"; + version = "dev"; + src = ./.; + + subPackages = [ "cmd" ]; + vendorHash = "sha256-8pt8NE5JhY+Ewl528PGaCxTEH4N0rPZudPE8rfhiVrk="; + + ldflags = [ + "-s" + "-w" + ]; + + env.CGO_ENABLED = "0"; + + postInstall = '' + if [ -e "$out/bin/cmd" ] && [ ! -e "$out/bin/dws" ]; then + mv "$out/bin/cmd" "$out/bin/dws" + fi + ''; + + meta = with pkgs.lib; { + description = "DingTalk Workspace CLI"; + homepage = "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli"; + license = licenses.asl20; + mainProgram = "dws"; + platforms = platforms.unix; + }; + }; + + default = dws; + }); + + apps = forAllSystems (system: { + dws = { + type = "app"; + program = "${self.packages.${system}.dws}/bin/dws"; + }; + default = self.apps.${system}.dws; + }); + + devShells = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = pkgs.mkShell { + packages = with pkgs; [ + go_1_25 + gopls + delve + gotools + direnv + git + ]; + + env.CGO_ENABLED = "0"; + + shellHook = '' + echo "Entered dingtalk-workspace-cli dev shell (Go $(go version | awk '{ print $3 }'))" + ''; + }; + }); + }; +}