mcp-nixos: init at 1.0.0

This commit is contained in:
Amadej Kastelic
2025-07-28 08:52:03 +02:00
parent 0c7553a96f
commit 8221e7f78f
2 changed files with 98 additions and 0 deletions
+63
View File
@@ -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";
};
}
@@ -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")