6.5 KiB
GitHub Copilot Instructions for np Repository
Repository Overview
This repository provides Nix flake templates for setting up Research Development Environments (RDE). The primary template is located in templates/rde/ and is designed for data science and research projects supporting R, Python, and Julia.
Project Structure
flake.nix- Root flake defining available templatestemplates/rde/- Main RDE template with Neovim-based development environmentflake.nix- Template flake configuration with language support and toolingflake.lock- Locked dependencies for reproducibility.envrc- direnv configuration for automatic environment loading
.github/workflows/- CI/CD workflows for testing and updatescheck.yml- Tests RDE template on Ubuntucheck_macos.yml- Tests RDE template on macOSupdate.yml- Automated daily dependency updates
Key Technologies
- Nix Flakes: Reproducible development environments
- nixCats: Custom Neovim configuration framework
- direnv: Automatic environment loading
- Cachix: Binary cache for faster builds (using
rde,rstats-on-nix, andnix-communitycaches)
Language Support
The RDE template supports multiple languages, controlled via config.enabledLanguages in templates/rde/flake.nix:
- R: R wrapper, Quarto, air-formatter, language server, and custom R packages via overlays
- Python: Python 3, basedpyright LSP, UV package manager
- Julia: Julia REPL with Pluto.jl support
Development Commands
The template provides project-specific commands (prefix with package name, default is p):
p- Launch Neovimp-g- Launch Neovide GUIp-initProject- Initialize project structure (data/, src/, docs/)p-updateDeps- Update all dependencies (flake inputs, R packages, Python packages)p-r- Launch R consolep-py/p-ipy- Launch Python/IPython REPLp-marimo- Launch Marimo notebookp-jl- Launch Julia REPLp-pluto- Launch Pluto.jl notebookp-devenv- Devenv integration (when enabled)
Nix Flake Conventions
Configuration Structure
The RDE template uses a centralized config object at the top of flake.nix:
config = rec {
defaultPackageName = "p";
enabledLanguages = { julia = false; python = false; r = true; };
enabledPackages = { gitPlugins = enabledLanguages.r; devenv = false; };
theme = { colorscheme = "kanagawa"; background = "dark"; };
};
Overlays Pattern
The template uses multiple overlays to extend nixpkgs:
rOverlay- Adds R packages via rix/rstats-on-nixpythonOverlay- Configures Python packagesrixOverlay- Integrates R package snapshots from rstats-on-nixprojectScriptsOverlay- Custom shell scripts for project managementextraPkgOverlay- Additional theme and plugin configuration
Package Categories
nixCats uses categories to organize functionality:
lspsAndRuntimeDeps- Language servers and runtime dependenciesstartupPlugins- Neovim plugins loaded at startupoptionalPlugins- Plugins loaded on demandenvironmentVariables- Language-specific environment setupextraWrapperArgs- Additional wrapper arguments (e.g., unset PYTHONPATH for Python)
Testing & CI/CD
Local Testing
# Build the RDE template
nix build ./templates/rde
# Check the RDE template
nix flake check ./templates/rde
# Enter development shell
nix develop ./templates/rde
CI Workflows
- check.yml: Runs on pushes to
templates/rde/flake.lock, builds and checks the template on Ubuntu - check_macos.yml: Tests on macOS when
update_rdebranch is pushed - update.yml: Daily cron job that updates dependencies via
p-updateDepsand creates PRs
Dependency Management
R Packages
R packages are managed through rstats-on-nix pinned snapshots. The date is specified in the rixpkgs.url input:
rixpkgs.url = "github:rstats-on-nix/nixpkgs/2025-12-15";
Custom R packages can be added in rOverlay or via r-packages.nix file.
Python Packages
Python packages use UV for management with nixpkgs Python as the interpreter:
- Environment variables force UV to use nix Python:
UV_PYTHON_DOWNLOADS = "never"andUV_PYTHON = pkgs.python.interpreter - PYTHONPATH is explicitly unset via
extraWrapperArgs
Flake Inputs
Dependencies are tracked in flake.lock. Key inputs include:
nixpkgs- NixOS 25.11rixpkgs- R package snapshots from rstats-on-nixnixCats- Custom Neovim configuration frameworkfran- Extra R packages overlay- Plugin inputs for R.nvim ecosystem
Coding Style & Conventions
-
Nix Code:
- Use
recfor recursive attribute sets when needed - Prefer
let...infor local bindings - Use
lib.optionalandlib.optionalStringfor conditional inclusion - Keep configuration at the top of the file for easy customization
- Use
-
Shell Scripts (in overlays):
- Always use
set -euo pipefailfor safety - Provide user-friendly output with emojis and clear messages
- Check for existing files/directories before creating
- Always use
-
Workflows:
- Use
workflow_dispatchfor manual triggering - Configure concurrency to cancel in-progress runs
- Use Cachix for binary caching with multiple caches
- Use
Common Patterns
Adding a New Language
- Add to
config.enabledLanguages - Create overlay for language-specific packages
- Add to
categoryDefinitions.lspsAndRuntimeDeps - Add command aliases in
packageDefinitions.hosts - Update
shellHookwith available commands
Adding Custom Scripts
Add to projectScriptsOverlay:
myScript = prev.writeShellScriptBin "myScript" ''
#!/usr/bin/env bash
set -euo pipefail
# script content
'';
Plugin Integration
For git-based plugins:
- Add flake input with
flake = false - Reference in nixCats inputs
- Add to
startupPluginsoroptionalPluginscategories
Important Notes
- The template creates a
.gitignorethat excludes data files by default - R packages are installed to project-local
.Rlibs/directory - Python UV is configured to never download Python, always using nixpkgs version
- The template supports multiple platforms: x86_64-linux, aarch64-linux, aarch64-darwin
- Neovim is wrapped with language-specific environment variables and PATH additions
File Generation
When asked to initialize projects or generate common files, follow the patterns in:
initProjectScriptfor project structure.gitignoretemplate for what to excludeREADME.mdtemplate for documentation structure