### Install Charmbracelet tools using traditional Nix Source: https://context7.com/charmbracelet/nur/llms.txt Commands to install Charmbracelet packages using traditional Nix package management. Requires NUR configuration in nixpkgs. Supports installing individual packages, multiple packages, and running packages without installation. ```bash # Add to ~/.config/nixpkgs/config.nix or /etc/nixos/configuration.nix # packageOverrides = pkgs: { # nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") { # inherit pkgs; # }; # }; # Install via nix-env nix-env -iA nur.repos.charmbracelet.glow nix-env -iA nur.repos.charmbracelet.crush # Build directly nix-build '' -A nur.repos.charmbracelet.glow # Install multiple packages nix-env -iA nur.repos.charmbracelet.glow \ nur.repos.charmbracelet.gum \ nur.repos.charmbracelet.vhs # Run without installing nix-shell -p nur.repos.charmbracelet.mods ``` -------------------------------- ### Define repository entry point with package exports Source: https://context7.com/charmbracelet/nur/llms.txt The default.nix file serves as the main entry point for the NUR repository. It imports and exposes custom library functions, NixOS/Home Manager modules, and overlays. Uses callPackage to instantiate all charmbracelet tool packages including charm, glow, vhs, gum, and others. Provides usage examples for building individual packages. ```nix { pkgs ? import { }, }: { # Special attributes lib = import ./lib { inherit pkgs; }; # Custom library functions modules = import ./modules; # NixOS/Home Manager modules overlays = import ./overlays; # Nixpkgs overlays # Package definitions using callPackage charm = pkgs.callPackage ./pkgs/charm { }; confettysh = pkgs.callPackage ./pkgs/confettysh { }; crush = pkgs.callPackage ./pkgs/crush { }; freeze = pkgs.callPackage ./pkgs/freeze { }; glow = pkgs.callPackage ./pkgs/glow { }; gum = pkgs.callPackage ./pkgs/gum { }; markscribe = pkgs.callPackage ./pkgs/markscribe { }; melt = pkgs.callPackage ./pkgs/melt { }; mods = pkgs.callPackage ./pkgs/mods { }; pop = pkgs.callPackage ./pkgs/pop { }; sequin = pkgs.callPackage ./pkgs/sequin { }; skate = pkgs.callPackage ./pkgs/skate { }; soft-serve = pkgs.callPackage ./pkgs/soft-serve { }; vhs = pkgs.callPackage ./pkgs/vhs { }; wishlist = pkgs.callPackage ./pkgs/wishlist { }; } # Usage example # nix-build -A glow # nix-build -A vhs # nix-env -iA nur.repos.charmbracelet.crush ``` -------------------------------- ### Create glow CLI markdown renderer package Source: https://context7.com/charmbracelet/nur/llms.txt Defines a Nix package for glow, a CLI tool that renders markdown with style. The package handles architecture-specific downloads and checksums. Uses fetchurl for source retrieval and installShellFiles for shell completion installation. Supports multiple Linux and Darwin platforms. ```nix { system ? builtins.currentSystem, lib, fetchurl, installShellFiles, stdenvNoCC }: let # SHA256 checksums for each architecture shaMap = { i686-linux = "1598hvs3z4wdma6njd8xi4phlwiq9cn80ksk986gd5k4q3pc8j62"; x86_64-linux = "0zy27bzlhvpgyp9a6fqigi75ikdcnyxjg0qpl6ys1ck9pq46n42r"; armv7l-linux = "1s7lbplgksdfa5qwv2k7bsd8cza25prapmgfkvd4js8xh084226g"; aarch64-linux = "0ggg2xww8qdpivwqdngxan053hlb5r538q28yb50dzbfrh1sf4mb"; x86_64-darwin = "06qnx62hd1w3r40bw0z0n59jjv2fmacd3qm64wriji4vcny4wcwi"; aarch64-darwin = "03c65cqz3bf9pbc54aqj98v7k56s50nxdv3pvif7gg6fs2kj0ji3"; }; # Download URLs for each architecture urlMap = { x86_64-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Linux_x86_64.tar.gz"; aarch64-darwin = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Darwin_arm64.tar.gz"; # ... other architectures }; in stdenvNoCC.mkDerivation { pname = "glow"; version = "2.1.1"; src = fetchurl { url = urlMap.${system}; sha256 = shaMap.${system}; }; nativeBuildInputs = [ installShellFiles ]; installPhase = '' mkdir -p $out/bin cp -vr ./glow $out/bin/glow installManPage ./manpages/glow.1.gz installShellCompletion ./completions/* ''; meta = { description = "Render markdown on the CLI, with pizzazz!"; homepage = "https://charm.sh/"; license = lib.licenses.mit; sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; platforms = [ "aarch64-darwin" "aarch64-linux" "armv7l-linux" "i686-linux" "x86_64-darwin" "x86_64-linux" ]; }; } ``` -------------------------------- ### Create Nixpkgs Overlay for NUR Packages (Nix) Source: https://context7.com/charmbracelet/nur/llms.txt This Nix overlay integrates NUR packages into the nixpkgs namespace, filtering out reserved attributes. It takes self and super as arguments, producing an overlay that can be added to nixpkgs.overlays for seamless package access. Dependencies include nixpkgs and the project's default.nix. Limitation: Must be applied correctly in configuration to avoid namespace conflicts. ```nix self: super: let isReserved = n: n == "lib" || n == "overlays" || n == "modules"; nameValuePair = n: v: { name = n; value = v; }; nurAttrs = import ./default.nix { pkgs = super; }; in builtins.listToAttrs (map (n: nameValuePair n nurAttrs.${n}) (builtins.filter (n: !isReserved n) (builtins.attrNames nurAttrs))) ``` -------------------------------- ### Configure Crush AI Assistant with Home Manager Source: https://context7.com/charmbracelet/nur/llms.txt This snippet demonstrates configuring the Crush AI assistant at the user level using Home Manager. It allows for customizing settings for various AI providers, including Local Ollama and Google Gemini. The configuration file is generated at ~/.config/crush/crush.json. ```Nix { config, pkgs, ... }: { imports = [ inputs.charmbracelet-nur.homeManagerModules.crush ]; programs.crush = { enable = true; settings = { providers = { local-ollama = { id = "ollama"; name = "Local Ollama"; type = "openai"; # Ollama uses OpenAI-compatible API base_url = "http://localhost:11434/v1"; api_key = "dummy-key-not-required"; models = [{ id = "llama2:latest"; name = "Llama 2 Local"; context_window = 4096; default_max_tokens = 2048; }]; }; gemini = { id = "gemini"; name = "Google Gemini"; type = "gemini"; api_key = builtins.readFile ~/.secrets/gemini-key; models = [{ id = "gemini-pro"; name = "Gemini Pro"; context_window = 32000; cost_per_1m_in = 0.5; cost_per_1m_out = 1.5; }]; }; }; options = { tui.compact_mode = false; debug = true; }; }; }; # Configuration file will be generated at: ~/.config/crush/crush.json } ``` -------------------------------- ### Create VHS terminal GIF recorder package with dependencies Source: https://context7.com/charmbracelet/nur/llms.txt Defines a Nix package for VHS, a terminal GIF recording tool. This package demonstrates wrapping binaries with runtime dependencies (ffmpeg, ttyd, chromium) using makeWrapper. The wrapProgram function ensures required dependencies are available in PATH at runtime. Only includes chromium as Linux-specific dependency. ```nix { system ? builtins.currentSystem, lib, fetchurl, installShellFiles, stdenvNoCC, ffmpeg, # Runtime dependency ttyd, # Runtime dependency chromium, # Runtime dependency (Linux only) makeWrapper }: let shaMap = { x86_64-linux = "01sl2agmqxr8wx12dlqa821vgdyf5przwg2kzv51s46a1a3w6lmm"; aarch64-darwin = "04l0c7dfj8ymg5gp0z5j6m7h4f0s4krhwgan4fk8pb056d06q9fw"; # ... other architectures }; urlMap = { x86_64-linux = "https://github.com/charmbracelet/vhs/releases/download/v0.10.0/vhs_0.10.0_Linux_x86_64.tar.gz"; # ... other architectures }; in stdenvNoCC.mkDerivation { pname = "vhs"; version = "0.10.0"; src = fetchurl { url = urlMap.${system}; sha256 = shaMap.${system}; }; nativeBuildInputs = [ installShellFiles makeWrapper ]; installPhase = '' mkdir -p $out/bin cp -vr ./vhs $out/bin/vhs # Wrap binary with runtime dependencies in PATH wrapProgram $out/bin/vhs --prefix PATH : ${ lib.makeBinPath ( lib.optionals stdenvNoCC.isLinux [ chromium ] ++ [ ffmpeg ttyd ] ) } installManPage ./manpages/vhs.1.gz installShellCompletion ./completions/* ''; meta = { description = "A tool for recording terminal GIFs"; homepage = "https://charm.sh/"; license = lib.licenses.mit; platforms = [ "aarch64-darwin" "aarch64-linux" "armv7l-linux" "i686-linux" "x86_64-darwin" "x86_64-linux" ]; }; } ``` -------------------------------- ### Configure Crush AI Assistant with NixOS Source: https://context7.com/charmbracelet/nur/llms.txt This snippet demonstrates configuring the Crush AI assistant at the system level using a NixOS module. It specifies settings for various AI providers like OpenAI and Anthropic, along with configuration for Model Context Protocol servers and Language Server Protocol. The configuration file is generated at /etc/crush/crush.json. ```Nix { config, pkgs, ... }: { imports = [ inputs.charmbracelet-nur.nixosModules.crush ]; programs.crush = { enable = true; settings = { providers = { openai = { id = "openai"; name = "OpenAI"; type = "openai"; api_key = builtins.readFile /run/secrets/openai-key; base_url = "https://api.openai.com/v1"; models = [{ id = "gpt-4-turbo-preview"; name = "GPT-4 Turbo"; context_window = 128000; default_max_tokens = 4096; cost_per_1m_in = 10.0; cost_per_1m_out = 30.0; can_reason = true; }]; }; anthropic = { id = "anthropic"; name = "Anthropic"; type = "anthropic"; api_key = builtins.readFile /run/secrets/anthropic-key; models = [{ id = "claude-3-opus-20240229"; name = "Claude 3 Opus"; context_window = 200000; default_max_tokens = 4096; cost_per_1m_in = 15.0; cost_per_1m_out = 75.0; }]; }; }; mcp = { filesystem = { command = "npx"; args = ["-y" "@modelcontextprotocol/server-filesystem" "/home/user/projects"]; type = "stdio"; env = { NODE_ENV = "production"; }; }; github = { command = "npx"; args = ["-y" "@modelcontextprotocol/server-github"]; type = "stdio"; env = { GITHUB_TOKEN = builtins.readFile /run/secrets/github-token; }; }; }; lsp = { typescript = { command = "typescript-language-server"; args = ["--stdio"]; options = {}; enabled = true; }; }; options = { context_paths = ["/home/user/.context" "/home/user/docs"]; tui = { compact_mode = true; }; debug = false; auto_summarize = true; data_dir = "/home/user/.local/share/crush"; }; permissions = { allowed_tools = ["read_file" "write_file" "execute_command"]; }; models = { "gpt-4-turbo-preview" = { id = "gpt-4-turbo-preview"; provider = "openai"; reasoning_effort = "high"; max_tokens = 4096; thinking_mode = true; }; }; }; }; # Configuration file will be generated at: /etc/crush/crush.json } ``` -------------------------------- ### Configure Nix Flakes for Charmbracelet packages Source: https://context7.com/charmbracelet/nur/llms.txt Sets up Nix Flakes to access Charmbracelet packages. Supports multiple architectures and integrates with NixOS and Home Manager configurations. Requires Nix with flakes support and internet access to GitHub. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; charmbracelet-nur.url = "github:charmbracelet/nur"; }; outputs = { self, nixpkgs, charmbracelet-nur }: { # Access individual packages packages.x86_64-linux.default = charmbracelet-nur.packages.x86_64-linux.glow; # Use in NixOS configuration nixosConfigurations.myhost = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ { environment.systemPackages = with charmbracelet-nur.packages.x86_64-linux; [ glow # Markdown renderer gum # Shell script UI toolkit vhs # Terminal GIF recorder mods # AI assistant crush # Developer AI tool ]; } ]; }; # Use in home-manager configuration homeConfigurations.myuser = home-manager.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; modules = [ { home.packages = with charmbracelet-nur.packages.x86_64-linux; [ glow freeze # Code screenshot generator pop # Email sender skate # Key-value store ]; } ];n }; }; } ``` -------------------------------- ### Generate Nix Module Options from JSON Schema (Bash) Source: https://context7.com/charmbracelet/nur/llms.txt This Bash script fetches a JSON schema from a URL, extracts enums, and generates a type-safe Nix module options file for Crush configuration. It outputs a modules/crush/options.nix file with generated options. Dependencies include curl, jq, and alejandra for formatting. Limitation: Requires internet access to fetch the schema and assumes the schema structure remains compatible. ```bash #!/usr/bin/env bash # scripts/generate-options.sh set -euo pipefail # Fetch the official Crush JSON schema SCHEMA_URL="https://charm.land/crush.json" SCHEMA=$(curl -sL "$SCHEMA_URL") # Extract enum values for type definitions PROVIDER_TYPES=$(echo "$SCHEMA" | jq -r '.definitions.Provider.properties.type.enum[]') MCP_TYPES=$(echo "$SCHEMA" | jq -r '.definitions.MCP.properties.type.enum[]') REASONING_EFFORTS=$(echo "$SCHEMA" | jq -r '.definitions.Model.properties.reasoning_effort.enum[]') # Generate Nix options from schema cat > modules/crush/options.nix < {} }: let charmbracelet = import /path/to/charmbracelet-nur { inherit pkgs; }; in { # Use individual packages myDevShell = pkgs.mkShell { buildInputs = [ charmbracelet.glow charmbracelet.gum charmbracelet.vhs ]; shellHook = '' echo "Welcome to development environment!" ${charmbracelet.glow}/bin/glow --version ''; }; # Create derived packages myDocsTool = pkgs.writeShellApplication { name = "docs-tool"; runtimeInputs = [ charmbracelet.glow ]; text = '' glow "$@" ''; }; } ``` -------------------------------- ### Filter NUR Packages for CI Builds (Nix) Source: https://context7.com/charmbracelet/nur/llms.txt This Nix function filters the NUR attributes to include only buildable and cacheable derivations, excluding reserved attributes like 'lib', 'overlays', and 'modules', as well as broken or locally-built packages. It takes nixpkgs as an argument and outputs a set of filtered packages. Dependencies include nixpkgs and the project's default.nix. Limitation: Assumes 'nurAttrs' contains valid derivations. ```nix { pkgs ? import { } }: let isReserved = n: n == "lib" || n == "overlays" || n == "modules"; isDerivation = p: pkgs.lib.isDerivation p; isBuildable = p: !(p.meta.broken or false); isCacheable = p: !(p.preferLocalBuild or false); shouldRecurseForDerivations = p: p.recurseForDerivations or false; nurAttrs = import ./default.nix { inherit pkgs; }; filterSet = pkgs.lib.filterAttrs (_: v: isDerivation v && isBuildable v && isCacheable v ); in filterSet nurAttrs ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.