FROM archlinux:latest

RUN pacman -Sy --noconfirm archlinux-keyring && \
    pacman -Su --noconfirm && \
    pacman -S --noconfirm --needed \
        bash \
        ca-certificates \
        curl \
        dart-sass \
        fastfetch \
        fzf \
        git \
        lazygit \
        less \
        mariadb-clients \
        nodejs \
        npm \
        openssh \
        php \
        pwgen \
        python \
        redis \
        sqlite \
        tmux \
        tree \
        unzip \
        uv \
        vim \
        zoxide && \
    pacman -Scc --noconfirm

RUN printf '%s\n' \
        'export PATH="/root/.local/bin:$PATH"' \
        'eval "$(zoxide init bash)"' \
        > /etc/profile.d/nix_path.sh && \
    chmod 755 /etc/profile.d/nix_path.sh && \
    echo '[ -f /etc/profile.d/nix_path.sh ] && . /etc/profile.d/nix_path.sh' >> /etc/bash.bashrc

RUN git config --system user.name "code" && \
    git config --system user.email "code@4lt.ca" && \
    git config --system --add safe.directory '*'

# Dotfiles
COPY files/bash_aliases /opt/dotfiles/bash_aliases
COPY files/bashrc /root/.bashrc

# Install Claude Code straight into /root, so a rebuild always picks up the
# latest release. Only the two files needed to stay logged in (not the CLI
# itself) are persisted across rebuilds, via individual bind mounts set up
# by `claudaris start` — see claudaris and AGENTS.md.
WORKDIR /tmp

RUN curl -fsSL https://claude.ai/install.sh | bash

# Claude Code usage statusline plugin
RUN PATH="/root/.local/bin:$PATH" bash -c \
    'curl -fsSL https://raw.githubusercontent.com/leeguooooo/claude-code-usage-bar/main/web-install.sh | bash'

# MCP servers for Claude Code. Only installed here — they're registered at
# user scope by entrypoint.sh on container start, because user-scope MCP
# config lives in ~/.claude.json, which is bind-mounted from the host and
# would shadow anything written to it at build time. Each server picks up
# its instance URL/token from the environment (see files/bash_aliases).

# n8n — https://github.com/czlonkowski/n8n-mcp
RUN npm install -g --prefix /usr/local n8n-mcp

# Gitea — official server, latest release binary
# https://gitea.com/gitea/gitea-mcp
RUN tag="$(curl -fsSL https://gitea.com/api/v1/repos/gitea/gitea-mcp/releases/latest \
        | python -c 'import json,sys; print(json.load(sys.stdin)["tag_name"])')" && \
    curl -fsSL "https://gitea.com/gitea/gitea-mcp/releases/download/${tag}/gitea-mcp_Linux_x86_64.tar.gz" \
        | tar -xz -C /usr/local/bin gitea-mcp && \
    chmod 755 /usr/local/bin/gitea-mcp

# InvokeAI — https://github.com/coinstax/invokeai-mcp-server. Upstream
# hardcodes the InvokeAI URL, so patch it to honor $INVOKEAI_BASE_URL; the
# grep fails the build if upstream changes shape and the patch stops landing.
RUN uv tool install invokeai-mcp-server && \
    sed -i 's|^INVOKEAI_BASE_URL = .*|import os\nINVOKEAI_BASE_URL = os.environ.get("INVOKEAI_BASE_URL", "http://127.0.0.1:9090")|' \
        /root/.local/share/uv/tools/invokeai-mcp-server/lib/python*/site-packages/invokeai_mcp_server.py && \
    grep -q 'INVOKEAI_BASE_URL = os.environ.get' \
        /root/.local/share/uv/tools/invokeai-mcp-server/lib/python*/site-packages/invokeai_mcp_server.py

# tmux wrapper
COPY files/tmux /usr/local/bin/tmux
COPY files/tmux.conf /etc/tmux.conf
RUN chmod 755 /usr/local/bin/tmux

# Container entrypoint
COPY files/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod 755 /usr/local/bin/entrypoint.sh

WORKDIR /projects

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]