From 8221e7f78fef1fba046e51696d8b5a69104156ea Mon Sep 17 00:00:00 2001 From: Amadej Kastelic Date: Sun, 27 Jul 2025 17:38:25 +0200 Subject: [PATCH] mcp-nixos: init at 1.0.0 --- pkgs/by-name/mc/mcp-nixos/package.nix | 63 +++++++++++++++++++ .../mcp-nixos/tests-mock-nix-channels.patch | 35 +++++++++++ 2 files changed, 98 insertions(+) create mode 100644 pkgs/by-name/mc/mcp-nixos/package.nix create mode 100644 pkgs/by-name/mc/mcp-nixos/tests-mock-nix-channels.patch diff --git a/pkgs/by-name/mc/mcp-nixos/package.nix b/pkgs/by-name/mc/mcp-nixos/package.nix new file mode 100644 index 000000000000..bc44ee41e5be --- /dev/null +++ b/pkgs/by-name/mc/mcp-nixos/package.nix @@ -0,0 +1,63 @@ +{ + lib, + fetchFromGitHub, + python3Packages, +}: + +python3Packages.buildPythonApplication rec { + pname = "mcp-nixos"; + version = "1.0.0"; + pyproject = true; + + src = fetchFromGitHub { + owner = "utensils"; + repo = "mcp-nixos"; + tag = "v${version}"; + hash = "sha256-NwP+zM1VGLOzIm+mLZVK9/9ImFwuiWhRJ9QK3hGpQsY="; + }; + + patches = [ + # This patch mocks nix channel listing network calls in tests + ./tests-mock-nix-channels.patch + ]; + + build-system = [ python3Packages.hatchling ]; + + dependencies = with python3Packages; [ + beautifulsoup4 + mcp + requests + ]; + + nativeCheckInputs = with python3Packages; [ + anthropic + pytestCheckHook + pytest-asyncio + python-dotenv + ]; + + disabledTestMarks = [ + # Require network access + "integration" + ]; + + disabledTestPaths = [ + # Require network access + "tests/test_nixhub_evals.py" + "tests/test_mcp_behavior_evals.py" + "tests/test_option_info_improvements.py" + # Requires configured channels + "tests/test_dynamic_channels.py" + ]; + + pythonImportsCheck = [ "mcp_nixos" ]; + + meta = { + description = "MCP server for NixOS"; + homepage = "https://github.com/utensils/mcp-nixos"; + changelog = "https://github.com/utensils/mcp-nixos/releases/tag/${src.tag}"; + license = lib.licenses.mit; + maintainers = [ lib.maintainers.amadejkastelic ]; + mainProgram = "mcp-nixos"; + }; +} diff --git a/pkgs/by-name/mc/mcp-nixos/tests-mock-nix-channels.patch b/pkgs/by-name/mc/mcp-nixos/tests-mock-nix-channels.patch new file mode 100644 index 000000000000..b7fc92841ab8 --- /dev/null +++ b/pkgs/by-name/mc/mcp-nixos/tests-mock-nix-channels.patch @@ -0,0 +1,35 @@ +diff --git a/tests/conftest.py b/tests/conftest.py +index 0a11295..1172182 100644 +--- a/tests/conftest.py ++++ b/tests/conftest.py +@@ -3,6 +3,30 @@ + import pytest # pylint: disable=unused-import + + ++@pytest.fixture(autouse=True) ++def mock_get_channels(monkeypatch): ++ """Mock get_channels function to return fixed channels for all tests.""" ++ def mock_channels(): ++ return { ++ "unstable": "latest-43-nixos-unstable", ++ "25.05": "latest-43-nixos-25.05", ++ "25.11": "latest-43-nixos-25.11", ++ "24.11": "latest-43-nixos-24.11", ++ "stable": "latest-43-nixos-25.05", ++ "beta": "latest-43-nixos-25.05" ++ } ++ ++ # Patch the function in the server module ++ monkeypatch.setattr('mcp_nixos.server.get_channels', mock_channels) ++ ++ # Also patch any imported references in test modules ++ monkeypatch.setattr('tests.test_channel_handling.get_channels', mock_channels) ++ monkeypatch.setattr('tests.test_dynamic_channels.get_channels', mock_channels, raising=False) ++ monkeypatch.setattr('tests.test_mcp_behavior_comprehensive.get_channels', mock_channels, raising=False) ++ monkeypatch.setattr('tests.test_real_world_scenarios.get_channels', mock_channels, raising=False) ++ monkeypatch.setattr('tests.test_server_comprehensive.get_channels', mock_channels, raising=False) ++ ++ + def pytest_addoption(parser): + """Add test filtering options.""" + parser.addoption("--unit", action="store_true", help="Run unit tests only")