From dc206b13e256941298868d559fff9be31d7e0e34 Mon Sep 17 00:00:00 2001
From: m3tm3re
Date: Tue, 17 Feb 2026 20:16:11 +0100
Subject: [PATCH] feat(shells): add opencode dev shell with mkOpencodeRules
demo
---
flake.nix | 4 +-
shells/default.nix | 10 ++-
shells/devops.nix | 5 +-
shells/opencode.nix | 155 ++++++++++++++++++++++++++++++++++++++++++++
shells/python.nix | 5 +-
5 files changed, 172 insertions(+), 7 deletions(-)
create mode 100644 shells/opencode.nix
diff --git a/flake.nix b/flake.nix
index c00683d..234c514 100644
--- a/flake.nix
+++ b/flake.nix
@@ -78,11 +78,11 @@
# Development shells for various programming environments
# Usage: nix develop .#
- # Available shells: default, python, devops
+ # Available shells: default, python, devops, opencode
devShells = forAllSystems (system: let
pkgs = pkgsFor system;
in
- import ./shells {inherit pkgs;});
+ import ./shells {inherit pkgs inputs;});
# Formatter for 'nix fmt'
formatter = forAllSystems (system: (pkgsFor system).alejandra);
diff --git a/shells/default.nix b/shells/default.nix
index 40336e7..b1dfdb5 100644
--- a/shells/default.nix
+++ b/shells/default.nix
@@ -1,7 +1,10 @@
# Development shells for various programming environments
# Each shell can be accessed via: nix develop .#
# Or used in home-manager/system configs
-{pkgs}: {
+{
+ pkgs,
+ inputs,
+}: {
# Default shell for working on this repository
default = pkgs.mkShell {
name = "m3ta-nixpkgs-dev";
@@ -27,6 +30,7 @@
};
# Import all individual shell environments
- python = import ./python.nix {inherit pkgs;};
- devops = import ./devops.nix {inherit pkgs;};
+ python = import ./python.nix {inherit pkgs inputs;};
+ devops = import ./devops.nix {inherit pkgs inputs;};
+ opencode = import ./opencode.nix {inherit pkgs inputs;};
}
diff --git a/shells/devops.nix b/shells/devops.nix
index 052bb15..707411a 100644
--- a/shells/devops.nix
+++ b/shells/devops.nix
@@ -1,6 +1,9 @@
# DevOps development environment
# Usage: nix develop .#devops
-{pkgs}:
+{
+ pkgs,
+ inputs ? null,
+}:
pkgs.mkShell {
name = "devops-dev";
diff --git a/shells/opencode.nix b/shells/opencode.nix
new file mode 100644
index 0000000..0b9b769
--- /dev/null
+++ b/shells/opencode.nix
@@ -0,0 +1,155 @@
+# OpenCode development environment with AI coding rules
+# This shell demonstrates the mkOpencodeRules library provided by this repository
+# Usage: nix develop .#opencode
+#
+# To enable OpenCode rules, add the agents input to your flake:
+# agents = {
+# url = "git+https://code.m3ta.dev/m3tam3re/AGENTS";
+# flake = false;
+# };
+{
+ pkgs,
+ lib ? pkgs.lib,
+ inputs ? null,
+ agents ? null,
+}: let
+ # Import the opencode-rules library
+ m3taLib = import ../lib {lib = pkgs.lib;};
+
+ # Import custom packages
+ customPackages = import ../pkgs {inherit pkgs inputs;};
+
+ # Create rules configuration only if agents input is provided
+ # This demonstrates how to use mkOpencodeRules in a real project
+ rulesConfig = lib.optionalAttrs (agents != null) {
+ rules = m3taLib.opencode-rules.mkOpencodeRules {
+ # Pass the AGENTS repository path
+ inherit agents;
+
+ # Languages relevant to this repository
+ languages = ["python" "typescript" "nix"];
+
+ # Frameworks used in this repo
+ frameworks = ["n8n"];
+
+ # Standard concerns for development
+ concerns = [
+ "coding-style"
+ "naming"
+ "documentation"
+ "testing"
+ "git-workflow"
+ "project-structure"
+ ];
+ };
+ };
+in
+ pkgs.mkShell {
+ name = "opencode-dev";
+
+ # Development tools
+ buildInputs = with pkgs;
+ [
+ # OpenCode AI coding agent (if inputs are available)
+ ]
+ ++ lib.optionals (inputs != null)
+ [inputs.opencode.packages.${pkgs.system}.opencode]
+ ++ [
+ # Task management for AI coding sessions
+ customPackages.td
+
+ # Companion tool for CLI agents (diffs, file trees, task management)
+ customPackages.sidecar
+
+ # Code analysis tools
+ customPackages.code2prompt
+
+ # Nix development tools (for this repo)
+ nil
+ alejandra
+ statix
+ deadnix
+ ];
+
+ # Shell hook that sets up OpenCode rules
+ shellHook = ''
+ echo "🤖 OpenCode Development Environment"
+ echo ""
+ echo "This environment demonstrates the mkOpencodeRules library"
+ echo "provided by the m3ta-nixpkgs repository."
+ echo ""
+
+ ${
+ if (agents != null)
+ then ''
+ # Execute the OpenCode rules shellHook
+ ${rulesConfig.rules.shellHook}
+
+ echo "✅ OpenCode rules configured!"
+ ''
+ else ''
+ echo "⚠️ OpenCode rules not configured"
+ echo ""
+ echo "To enable OpenCode rules, add the agents input to your flake.nix:"
+ echo ""
+ echo " inputs = {"
+ echo " m3ta-nixpkgs.url = \"git+https://code.m3ta.dev/m3tam3re/nixpkgs\";"
+ echo " agents = {"
+ echo " url = \"git+https://code.m3ta.dev/m3tam3re/AGENTS\";"
+ echo " flake = false;"
+ echo " };"
+ echo " };"
+ echo ""
+ echo "Then pass agents to the shell:"
+ echo " opencode = import ./opencode.nix { inherit pkgs inputs agents; };"
+ ''
+ }
+
+ echo ""
+ echo "Available tools:"
+ echo " opencode - AI coding agent"
+ echo " td usage --new-session - View current tasks"
+ echo " sidecar - Companion tool (diffs, file trees, tasks)"
+ echo " code2prompt - Convert code to prompts"
+ echo ""
+ echo "Nix development tools:"
+ echo " nix flake check - Check flake validity"
+ echo " nix fmt . - Format Nix files"
+ echo " statix check . - Lint Nix files"
+ echo " deadnix . - Find dead code"
+ echo ""
+ ${
+ if (agents == null)
+ then ''
+ echo "💡 Using mkOpencodeRules in your project:"
+ echo ""
+ echo "Add to your flake.nix:"
+ echo " inputs = {"
+ echo " m3ta-nixpkgs.url = \"git+https://code.m3ta.dev/m3tam3re/nixpkgs\";"
+ echo " agents = {"
+ echo " url = \"git+https://code.m3ta.dev/m3tam3re/AGENTS\";"
+ echo " flake = false;"
+ echo " };"
+ echo " };"
+ echo ""
+ echo " outputs = {self, nixpkgs, m3ta-nixpkgs, agents, ...}:"
+ echo " let"
+ echo " system = \"x86_64-linux\";"
+ echo " pkgs = nixpkgs.legacyPackages.''${system};"
+ echo " m3taLib = m3ta-nixpkgs.lib.''${system};"
+ echo " rules = m3taLib.opencode-rules.mkOpencodeRules {"
+ echo " inherit agents;"
+ echo " languages = [\"python\" \"typescript\"];"
+ echo " frameworks = [\"n8n\"];"
+ echo " };"
+ echo " in {"
+ echo " devShells.''${system}.default = pkgs.mkShell {"
+ echo " shellHook = rules.shellHook;"
+ echo " };"
+ echo " };"
+ ''
+ else ""
+ }
+ echo ""
+ '';
+ }
diff --git a/shells/python.nix b/shells/python.nix
index d9da096..4e429c7 100644
--- a/shells/python.nix
+++ b/shells/python.nix
@@ -1,6 +1,9 @@
# Modern Python development environment with marimo and uv — Nushell version
# Usage: nix develop .#python (drops into Nushell)
-{pkgs}: let
+{
+ pkgs,
+ inputs ? null,
+}: let
# Use the latest Python available in nixpkgs
python = pkgs.python313;
in