From c13c80ac3dae637cdf0d31dcf371a0f549b67455 Mon Sep 17 00:00:00 2001 From: Horace Liu Date: Tue, 5 May 2026 14:26:28 +0800 Subject: [PATCH] feat(package): add nix package --- .gitignore | 4 ++ flake.lock | 66 +++++++++++++++++++++++++++++++ flake.nix | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ nix/package.nix | 56 ++++++++++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/package.nix diff --git a/.gitignore b/.gitignore index 90595039..3dbbcbab 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,7 @@ apps/ # Maintainer-internal design notes (trade-secret material, never published) .private/ + +# direnv +.envrc +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..eb24d0db --- /dev/null +++ b/flake.lock @@ -0,0 +1,66 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1777884425, + "narHash": "sha256-MzIEqXcx2EzJXOqrGETHFlzx6aGP2NhLVLxrM+ej41s=", + "owner": "nix-community", + "repo": "fenix", + "rev": "18454832b8f5d6cb33910382defc793dd78306f2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1777578337, + "narHash": "sha256-Ad49moKWeXtKBJNy2ebiTQUEgdLyvGmTeykAQ9xM+Z4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "15f4ee454b1dce334612fa6843b3e05cf546efab", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1777843182, + "narHash": "sha256-AO068PumYkLmubBSjlEQKAsnhVdF1Es7NC25X3KmuOw=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "f04c37286472e3687a2d32d3d1fad2772de515a1", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..3716bd08 --- /dev/null +++ b/flake.nix @@ -0,0 +1,103 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + fenix, + ... + }@inputs: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + forEachSystem = + f: + inputs.nixpkgs.lib.genAttrs systems ( + system: + f { + inherit system; + pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ + inputs.self.overlays.default + ]; + }; + } + ); + rev = self.shortRev or self.dirtyShortRev or "dirty"; + in + { + packages = forEachSystem ( + { pkgs, system }: + { + default = self.packages.${system}.deepseek-tui; + deepseek-tui = pkgs.callPackage ./nix/package.nix { + inherit rev; + rustPlatform = pkgs.makeRustPlatform { + cargo = pkgs.rustToolchain; + rustc = pkgs.rustToolchain; + }; + }; + } + ); + + overlays.default = final: prev: { + rustToolchain = + with fenix.packages.${prev.stdenv.hostPlatform.system}; + combine ( + with stable; + [ + rustc + cargo + clippy + rustfmt + rust-src + ] + ); + }; + + devShells = forEachSystem ( + { pkgs, system }: + { + default = pkgs.mkShell { + packages = with pkgs; [ + rustToolchain + rust-analyzer + lldb + + pkg-config + openssl + dbus + python3 + + self.formatter.${system} + ]; + + env = { + # Required by rust-analyzer + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; + + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath ( + with pkgs; + [ + openssl + dbus + ] + ); + }; + }; + } + ); + + formatter = forEachSystem ({ pkgs, ... }: pkgs.nixfmt); + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 00000000..4d306b4c --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,56 @@ +{ + lib, + rustPlatform, + pkg-config, + openssl, + dbus, + + # for cargo test + python3, + gitMinimal, + cacert, + + rev ? "dirty", +}: +rustPlatform.buildRustPackage (finalAttrs: { + pname = "deepseek-tui"; + version = "git-${rev}"; + + src = ../.; + + cargoLock = { + lockFile = ../Cargo.lock; + }; + + nativeBuildInputs = [ pkg-config ]; + + buildInputs = [ + openssl + dbus + ]; + + nativeCheckInputs = [ + python3 + gitMinimal + cacert + ]; + + cargoBuildFlags = [ + "--package" + "deepseek-tui-cli" + "--package" + "deepseek-tui" + ]; + cargoTestFlags = finalAttrs.cargoBuildFlags; + + preCheck = '' + export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt + ''; + + meta = { + description = "Coding agent for DeepSeek models that runs in your terminal"; + homepage = "https://github.com/Hmbown/DeepSeek-TUI"; + license = lib.licenses.mit; + mainProgram = "deepseek"; + }; +})