From 6eb98e5b92c69ccfe747844d4fef93ae5e17e8e5 Mon Sep 17 00:00:00 2001 From: LuoChen Date: Wed, 4 Jun 2025 11:02:57 +0800 Subject: [PATCH] Add Nix packaging and flake.nix for MCPM --- .gitignore | 3 +++ README.nix.md | 43 ++++++++++++++++++++++++++++++ default.nix | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++ flake.nix | 57 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 237 insertions(+) create mode 100644 README.nix.md create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 1a8780de..66cc057b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,9 @@ wheels/ .installed.cfg *.egg +# Nix Build +result + # Virtual environments .venv venv/ diff --git a/README.nix.md b/README.nix.md new file mode 100644 index 00000000..9a5cffbf --- /dev/null +++ b/README.nix.md @@ -0,0 +1,43 @@ +# MCPM Nix Packaging + +This repository contains Nix packaging for MCPM (Model Context Protocol Manager). + +## Using with Nix Flakes + +If you have flakes enabled, you can use this package directly: + +```bash +# Run MCPM directly +nix run . + +# Install MCPM to your profile +nix profile install github:pathintegral-institute/mcpm.sh + +# Enter a development shell +nix develop . +``` + +## Building from Source + +To build the package from source: + +1. Clone the repository: + ```bash + git clone https://github.com/pathintegral-institute/mcpm.sh + cd mcpm.sh + ``` + +2. Build the package: + ```bash + nix build + ``` + +3. Run the built package: + ```bash + ./result/bin/mcpm --help + ``` + +## Notes + +- The nix package requires Python 3.12 or higher. + diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..bdab6543 --- /dev/null +++ b/default.nix @@ -0,0 +1,73 @@ +{ + lib, + python3, +}: + +let + # Use Python 3.12 + python = python3; # pkgs.python312; + + # Override Python to include our custom packages + pythonWithPackages = python.override { + packageOverrides = self: super: { + # Add our custom packages + }; + }; +in +pythonWithPackages.pkgs.buildPythonApplication rec { + pname = "mcpm"; + version = "1.13.1"; # From src/mcpm/version.py + + src = ./.; # Use the local directory as the source + + format = "pyproject"; + + nativeBuildInputs = with pythonWithPackages.pkgs; [ + hatchling + setuptools + wheel + pip + ]; + + propagatedBuildInputs = with pythonWithPackages.pkgs; [ + # Core dependencies from pyproject.toml + click + rich + requests + pydantic + duckdb + psutil + prompt-toolkit + deprecated + + # dependencies only available for Python>=3.12 on nixpkgs + mcp + ruamel-yaml + watchfiles + + # Additional dependencies that might be needed + typer + httpx + anyio + fastapi + uvicorn + websockets + jinja2 + pyyaml + toml + python-dotenv + packaging + colorama + ]; + + # Disable tests for now + #doCheck = false; + + meta = with lib; { + description = "MCPM - Model Context Protocol Manager"; + homepage = "https://mcpm.sh"; + license = licenses.mit; + maintainers = with maintainers; [ luochen1990 ]; + mainProgram = "mcpm"; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..887a7670 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "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": 1748693115, + "narHash": "sha256-StSrWhklmDuXT93yc3GrTlb0cKSS0agTAxMGjLKAsY8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "910796cabe436259a29a72e8d3f5e180fc6dfacc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "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", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..17671694 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "MCPM - Model Context Protocol Manager"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + config = { + allowUnfree = true; + permittedInsecurePackages = [ ]; + }; + }; + in + { + packages = { + default = pkgs.callPackage ./default.nix { }; + }; + + apps.default = flake-utils.lib.mkApp { + drv = self.packages.${system}.default; + }; + + devShells.default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + + buildInputs = with pkgs.python3.pkgs; [ + self.packages.${system}.default + + # From pyproject.toml's dev dependencies + ipython + pytest + pytest-asyncio + ruff + jsonschema + openai + ]; + + shellHook = '' + echo "MCPM development environment" + ''; + }; + } + ); +}