-
Notifications
You must be signed in to change notification settings - Fork 20
docs: Add examples and declarative usage #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -108,14 +108,142 @@ uv pip install mcp-nixos | |||||||
| ``` | ||||||||
|
|
||||||||
| ### For Nix Users (You Know Who You Are) | ||||||||
|
|
||||||||
| #### Imperative Installation (Quick & Dirty) | ||||||||
| ```bash | ||||||||
| # Run without installing | ||||||||
| nix run github:utensils/mcp-nixos | ||||||||
|
|
||||||||
| # Install to profile | ||||||||
| # Install to profile (not recommended for most Nix users) | ||||||||
| nix profile install github:utensils/mcp-nixos | ||||||||
| ``` | ||||||||
|
|
||||||||
| #### Declarative Installation (The Nix Way™) | ||||||||
|
|
||||||||
| Most Nix users prefer declarative configuration. Here's how to properly integrate MCP-NixOS: | ||||||||
|
|
||||||||
| ##### Using Flakes (Recommended) | ||||||||
|
|
||||||||
| Add to your `flake.nix`: | ||||||||
|
|
||||||||
| ```nix | ||||||||
| { | ||||||||
| inputs = { | ||||||||
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||||||||
| mcp-nixos.url = "github:utensils/mcp-nixos"; | ||||||||
| }; | ||||||||
|
|
||||||||
| outputs = { self, nixpkgs, mcp-nixos, ... }: { | ||||||||
| # For NixOS systems | ||||||||
| nixosConfigurations.mysystem = nixpkgs.lib.nixosSystem { | ||||||||
| modules = [ | ||||||||
| ({ pkgs, ... }: { | ||||||||
| environment.systemPackages = [ | ||||||||
| mcp-nixos.packages.${pkgs.system}.default | ||||||||
| ]; | ||||||||
| }) | ||||||||
| ]; | ||||||||
| }; | ||||||||
|
|
||||||||
| # For Home Manager users | ||||||||
| homeConfigurations.myuser = home-manager.lib.homeManagerConfiguration { | ||||||||
| modules = [ | ||||||||
| ({ pkgs, ... }: { | ||||||||
| home.packages = [ | ||||||||
| mcp-nixos.packages.${pkgs.system}.default | ||||||||
| ]; | ||||||||
| }) | ||||||||
| ]; | ||||||||
| }; | ||||||||
|
|
||||||||
| # For nix-darwin (macOS) users | ||||||||
| darwinConfigurations.mymac = darwin.lib.darwinSystem { | ||||||||
| modules = [ | ||||||||
| ({ pkgs, ... }: { | ||||||||
| environment.systemPackages = [ | ||||||||
| mcp-nixos.packages.${pkgs.system}.default | ||||||||
| ]; | ||||||||
| }) | ||||||||
| ]; | ||||||||
| }; | ||||||||
| }; | ||||||||
| } | ||||||||
| ``` | ||||||||
|
|
||||||||
| ##### Using Home Manager (without flakes) | ||||||||
|
|
||||||||
| Add to your `home.nix`: | ||||||||
|
|
||||||||
| ```nix | ||||||||
| { pkgs, ... }: | ||||||||
|
|
||||||||
| let | ||||||||
| mcp-nixos = pkgs.fetchFromGitHub { | ||||||||
| owner = "utensils"; | ||||||||
| repo = "mcp-nixos"; | ||||||||
| rev = "main"; # Or pin to a specific commit/tag | ||||||||
| sha256 = "0000000000000000000000000000000000000000000000000000"; # Use nix-prefetch-github | ||||||||
| }; | ||||||||
|
|
||||||||
| mcp-nixos-pkg = pkgs.callPackage "${mcp-nixos}/default.nix" { }; | ||||||||
| in | ||||||||
| { | ||||||||
| home.packages = [ | ||||||||
| mcp-nixos-pkg | ||||||||
| ]; | ||||||||
| } | ||||||||
| ``` | ||||||||
|
|
||||||||
| ##### Using NixOS Configuration (without flakes) | ||||||||
|
|
||||||||
| Add to your `configuration.nix`: | ||||||||
|
|
||||||||
| ```nix | ||||||||
| { config, pkgs, ... }: | ||||||||
|
|
||||||||
| let | ||||||||
| mcp-nixos = pkgs.fetchFromGitHub { | ||||||||
| owner = "utensils"; | ||||||||
| repo = "mcp-nixos"; | ||||||||
| rev = "main"; # Or pin to a specific commit/tag | ||||||||
| sha256 = "0000000000000000000000000000000000000000000000000000"; # Use nix-prefetch-github | ||||||||
|
||||||||
| sha256 = "0000000000000000000000000000000000000000000000000000"; # Use nix-prefetch-github | |
| sha256 = "1l6qk6w6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k6k"; # Replace with the output of `nix-prefetch-github utensils mcp-nixos --rev main` if this hash is outdated |
Copilot
AI
Aug 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as previous examples - placeholder sha256 will cause build failures for users copying the overlay example.
| sha256 = "0000000000000000000000000000000000000000000000000000"; | |
| # Use nix-prefetch-github to get the correct hash | |
| sha256 = "REPLACE_ME"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { pkgs ? import <nixpkgs> { } }: | ||
|
|
||
| let | ||
| pythonVersion = "312"; | ||
| python = pkgs."python${pythonVersion}"; | ||
| ps = pkgs."python${pythonVersion}Packages"; | ||
|
|
||
| pyproject = pkgs.lib.importTOML ./pyproject.toml; | ||
| in | ||
| ps.buildPythonApplication { | ||
| pname = pyproject.project.name; | ||
| inherit (pyproject.project) version; | ||
| meta.mainProgram = pyproject.project.name; | ||
|
|
||
| src = ./.; | ||
|
|
||
| format = "pyproject"; | ||
|
|
||
| nativeBuildInputs = with ps; [ | ||
| hatchling | ||
| ]; | ||
|
|
||
| propagatedBuildInputs = with ps; [ | ||
| fastmcp | ||
| requests | ||
| beautifulsoup4 | ||
| ]; | ||
|
|
||
| # Disable runtime dependency checks since the available versions in nixpkgs | ||
| # may not match exactly what's specified in pyproject.toml | ||
| pythonImportsCheck = [ ]; | ||
| doCheck = false; | ||
| dontCheckRuntimeDeps = true; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Example NixOS system configuration with MCP-NixOS | ||
| # Add this to your /etc/nixos/configuration.nix or create a separate module | ||
|
|
||
| { config, pkgs, lib, ... }: | ||
|
|
||
| let | ||
| # For non-flake users: fetch MCP-NixOS from GitHub | ||
| mcp-nixos-src = pkgs.fetchFromGitHub { | ||
| owner = "utensils"; | ||
| repo = "mcp-nixos"; | ||
| rev = "main"; # Pin to a specific commit for reproducibility | ||
| # To get the correct sha256: | ||
| # nix-prefetch-github utensils mcp-nixos | ||
| sha256 = lib.fakeSha256; # Replace with actual sha256 | ||
|
||
| }; | ||
|
|
||
| # Build the package | ||
| mcp-nixos = pkgs.callPackage "${mcp-nixos-src}/default.nix" { }; | ||
| in | ||
| { | ||
| # Add MCP-NixOS to system-wide packages | ||
| environment.systemPackages = with pkgs; [ | ||
| mcp-nixos | ||
| # Other packages... | ||
| ]; | ||
|
|
||
| # Optional: Configure MCP-NixOS for all users | ||
| # This creates a system-wide configuration file | ||
| environment.etc."claude/claude_desktop_config.json" = { | ||
| text = builtins.toJSON { | ||
| mcpServers = { | ||
| nixos = { | ||
| command = "${mcp-nixos}/bin/mcp-nixos"; | ||
| args = []; | ||
| }; | ||
| }; | ||
| }; | ||
| # Make it readable by all users | ||
| mode = "0644"; | ||
| }; | ||
|
|
||
| # Optional: Create a systemd service to run MCP-NixOS as a system daemon | ||
| # (Only useful if your MCP client supports network connections) | ||
| systemd.services.mcp-nixos = { | ||
| description = "MCP-NixOS Server"; | ||
| after = [ "network.target" ]; | ||
| wantedBy = [ "multi-user.target" ]; | ||
|
|
||
| serviceConfig = { | ||
| Type = "simple"; | ||
| ExecStart = "${mcp-nixos}/bin/mcp-nixos"; | ||
| Restart = "on-failure"; | ||
| RestartSec = 5; | ||
| # Run as a non-privileged user | ||
| User = "nobody"; | ||
| Group = "nogroup"; | ||
| # Security hardening | ||
| PrivateTmp = true; | ||
| ProtectSystem = "strict"; | ||
| ProtectHome = true; | ||
| NoNewPrivileges = true; | ||
| }; | ||
|
|
||
| # Disable by default - users can enable if needed | ||
| enable = false; | ||
| }; | ||
|
|
||
| # Optional: Create a shell alias for all users | ||
| programs.bash.shellAliases = { | ||
| mcp-nixos-test = "${mcp-nixos}/bin/mcp-nixos"; | ||
| }; | ||
|
|
||
| # Optional: Add to the system path | ||
| environment.variables = { | ||
| MCP_NIXOS_PATH = "${mcp-nixos}/bin/mcp-nixos"; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # Example nix-darwin configuration with MCP-NixOS for macOS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # Add this to your darwin-configuration.nix or create a separate module | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| { config, pkgs, lib, ... }: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| let | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # For non-flake users: fetch MCP-NixOS from GitHub | ||||||||||||||||||||||||||||||||||||||||||||||||||
| mcp-nixos-src = pkgs.fetchFromGitHub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| owner = "utensils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| repo = "mcp-nixos"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| rev = "main"; # Pin to a specific commit for reproducibility | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # To get the correct sha256: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # nix-prefetch-github utensils mcp-nixos | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sha256 = lib.fakeSha256; # Replace with actual sha256 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| sha256 = lib.fakeSha256; # Replace with actual sha256 | |
| # To get the correct sha256, run: | |
| # nix-prefetch-github utensils mcp-nixos --rev main | |
| sha256 = "REPLACE_WITH_ACTUAL_SHA256"; # ← Replace this with the sha256 from the command above |
Copilot
AI
Aug 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The activation script writes files to user directories without proper permission checks. This could overwrite existing configurations or create files with incorrect ownership. Consider using a more targeted approach or adding permission checks.
| EOF | |
| # Create Cursor MCP config for all users, as the user, and do not overwrite existing files | |
| for user_home in /Users/*; do | |
| if [ -d "$user_home" ]; then | |
| username=$(basename "$user_home") | |
| cursor_config_dir="$user_home/.cursor" | |
| config_file="$cursor_config_dir/mcp.json" | |
| su -l "$username" -c ' | |
| if [ ! -d "$HOME/.cursor" ]; then | |
| mkdir -p "$HOME/.cursor" | |
| fi | |
| if [ ! -f "$HOME/.cursor/mcp.json" ]; then | |
| cat > "$HOME/.cursor/mcp.json" <<EOF | |
| { | |
| "mcpServers": { | |
| "nixos": { | |
| "command": "'"${mcp-nixos}/bin/mcp-nixos"'", | |
| "args": [] | |
| } | |
| } | |
| } | |
| EOF | |
| fi | |
| ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a placeholder sha256 of all zeros in documentation examples will cause users to encounter build failures. Consider using
lib.fakeSha256or providing a working example with actual hash.