diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 8182304..cd6b54e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -25,14 +25,14 @@ jobs: matrix: os: [ubuntu-latest] steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v5 - uses: wimpysworld/nothing-but-nix@main with: hatchet-protocol: 'carve' - uses: cachix/install-nix-action@v31 with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: cachix/cachix-action@v17 + - uses: cachix/cachix-action@v16 with: name: rde authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' @@ -118,14 +118,14 @@ jobs: test-with-python: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v5 - uses: wimpysworld/nothing-but-nix@main with: hatchet-protocol: 'carve' - uses: cachix/install-nix-action@v31 with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: cachix/cachix-action@v17 + - uses: cachix/cachix-action@v16 with: name: rde authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' @@ -174,14 +174,14 @@ jobs: test-with-julia: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v5 - uses: wimpysworld/nothing-but-nix@main with: hatchet-protocol: 'carve' - uses: cachix/install-nix-action@v31 with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: cachix/cachix-action@v17 + - uses: cachix/cachix-action@v16 with: name: rde authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' diff --git a/.github/workflows/check_ed.yml b/.github/workflows/check_ed.yml deleted file mode 100644 index 350c013..0000000 --- a/.github/workflows/check_ed.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: "Test ed template MacOS" -on: - workflow_dispatch: # allows manual triggering - push: - branches: - - 'update_rde' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true -jobs: - tests: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-latest, ubuntu-latest] - steps: - - uses: actions/checkout@v6 - - uses: cachix/install-nix-action@v31 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: cachix/cachix-action@v17 - with: - name: rde - authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - extraPullNames: rstats-on-nix, nix-community - - run: nix build ./templates/ed diff --git a/.github/workflows/check_macos.yml b/.github/workflows/check_macos.yml index 3b8e6f2..be76aa2 100644 --- a/.github/workflows/check_macos.yml +++ b/.github/workflows/check_macos.yml @@ -14,14 +14,13 @@ jobs: matrix: os: [macos-latest] steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v5 - uses: cachix/install-nix-action@v31 with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: cachix/cachix-action@v17 + - uses: cachix/cachix-action@v16 with: name: rde authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' extraPullNames: rstats-on-nix, nix-community - run: nix build ./templates/rde - - run: nix build ./templates/ed diff --git a/.github/workflows/flakehub-publish-rolling.yml b/.github/workflows/flakehub-publish-rolling.yml index 80ff807..8403bbe 100644 --- a/.github/workflows/flakehub-publish-rolling.yml +++ b/.github/workflows/flakehub-publish-rolling.yml @@ -10,7 +10,7 @@ jobs: id-token: "write" contents: "read" steps: - - uses: "actions/checkout@v6" + - uses: "actions/checkout@v5" with: persist-credentials: false - uses: "DeterminateSystems/determinate-nix-action@v3" diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 96cb868..44f16ec 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -10,24 +10,25 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v5 - uses: wimpysworld/nothing-but-nix@main with: hatchet-protocol: 'carve' - uses: cachix/install-nix-action@v31 with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: cachix/cachix-action@v17 + - uses: cachix/cachix-action@v16 with: name: rde authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' extraPullNames: rstats-on-nix, nix-community - - name: Update ed flake.lock - uses: DeterminateSystems/update-flake-lock@v28 + - run: cd templates/rde/ && nix develop -c p-updateDeps + - name: Update n flake.lock + uses: DeterminateSystems/update-flake-lock@v27 with: token: ${{ secrets.GH_TOKEN_FOR_UPDATES }} branch: update_rde - path-to-flake-dir: "templates/ed" + path-to-flake-dir: "templates/rde" pr-title: "Update RDE flake.lock" # Title of PR to be created pr-labels: | # Labels to be set on the PR dependencies diff --git a/flake.nix b/flake.nix index 7b723a7..e2cb7cc 100644 --- a/flake.nix +++ b/flake.nix @@ -6,11 +6,7 @@ path = ./templates/rde; description = "Research Development Environment"; }; - ed = { - path = ./templates/ed; - description = "Simple nvim Environment"; - }; }; - defaultTemplate = self.templates.ed; + defaultTemplate = self.templates.rde; }; } diff --git a/templates/ed/.envrc b/templates/ed/.envrc deleted file mode 100644 index 3550a30..0000000 --- a/templates/ed/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/templates/ed/.gitignore b/templates/ed/.gitignore deleted file mode 100644 index 52e8a70..0000000 --- a/templates/ed/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.nvimcom diff --git a/templates/ed/README.md b/templates/ed/README.md deleted file mode 100644 index 272d827..0000000 --- a/templates/ed/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# Project Editor - -A per-project Neovim wrapper built with [nix-wrapper-modules](https://birdeehub.github.io/nix-wrapper-modules/) and [nvimConfig](https://github.com/dwinkler1/nvimConfig). - -## Setup - -The flake provides two entry points: - -| Command | What you get | -|---|---| -| `direnv allow` / `nix develop` | **(Recommended)** A shell with `nv` and all enabled language toolchains (R, Python, Julia, Quarto) on `PATH`. | -| `nix run` | Launches only the `nv` editor. Language toolchains (R, Python, etc.) are **not** on `PATH`. | - -### With direnv (recommended) - -```bash -direnv allow # enter the devShell automatically -nv # launch the pre-configured Neovim -R # R REPL is available (if enabled in flake.nix) -``` - -### Without direnv - -```bash -nix develop # enter the devShell manually -nv # launch Neovim -R # R REPL is available (if enabled in flake.nix) -``` - -> **Why `nix run` only gives the editor:** The flake's `packages.default` is the wrapped Neovim binary. Language toolchains (R, radian, quarto, etc.) live in `devShells.default`. Use `nix develop` (or `direnv allow`) to get the full environment. - -## Configuration - -The `flake.nix` is the single source of truth. Key knobs: - -| Option | What it controls | -|---|---| -| `cats` | Toggle language support (nix, r, python, julia, etc.) | -| `settings.lang_packages.` | Language-specific packages installed in the wrapper | -| `settings.colorscheme` | Neovim colorscheme | -| `settings.background` | `"dark"` or `"light"` | -| `settings.wrapRc` | When `true`, init.lua is embedded (rebuild to change); when `false`, init.lua is external (reload without rebuild) | -| `binName` | The wrapper binary name (`nv` by default) | -| `env` | Environment variables set in the wrapper | -| `extraPackages` | Extra system packages available in the wrapper's PATH | -| `specs.extraLua` | Inject lazy.nvim plugin specs | - -### Adding packages without editing flake.nix - -Create any of these optional files in the project root to add dependencies without modifying `flake.nix`: - -- **`python-packages.nix`** — receives `python3Packages`, return a list of packages: - ```nix - p: with p; [ numpy scipy ] - ``` - -- **`r-packages.nix`** — receives `rpkgs` (includes `rPackages`), return a list: - ```nix - p: with p.rPackages; [ ggplot2 data.table ] - ``` - -- **`julia-packages.nix`** — no arguments, return a list of package name strings: - ```nix - [ "DataFrames" "Plots" ] - ``` - -## Formatting - -```bash -nix fmt -``` - -Uses `nixfmt-rfc-style` pinned via the flake's `formatter` output. diff --git a/templates/ed/flake.lock b/templates/ed/flake.lock deleted file mode 100644 index 19c77b2..0000000 --- a/templates/ed/flake.lock +++ /dev/null @@ -1,175 +0,0 @@ -{ - "nodes": { - "fran": { - "inputs": { - "nixpkgs": [ - "rixpkgs" - ] - }, - "locked": { - "lastModified": 1776413584, - "narHash": "sha256-xqqv46MTveuT4yJH2YihmbHGy5mdLnnLFDebVmUws/E=", - "owner": "dwinkler1", - "repo": "fran", - "rev": "da09626e4dd8f0f57078b3a04e0443a8c20defa1", - "type": "github" - }, - "original": { - "owner": "dwinkler1", - "repo": "fran", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1778869304, - "narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d233902339c02a9c334e7e593de68855ad26c4cb", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nvimConfig": { - "inputs": { - "fran": [ - "fran" - ], - "nixpkgs": [ - "nixpkgs" - ], - "plugins-cmp-pandoc-references": "plugins-cmp-pandoc-references", - "plugins-r": "plugins-r", - "r-nvim-nix": "r-nvim-nix", - "rixpkgs": [ - "rixpkgs" - ], - "wrappers": "wrappers" - }, - "locked": { - "lastModified": 1779362150, - "narHash": "sha256-y3JTpxmNgtEYG1m21Ymvdmrul/WvJzOCX45AlV21aak=", - "owner": "dwinkler1", - "repo": "nvimConfig", - "rev": "af6d975129768cce36ac4c46198ab2b3ebaafad3", - "type": "github" - }, - "original": { - "owner": "dwinkler1", - "repo": "nvimConfig", - "type": "github" - } - }, - "plugins-cmp-pandoc-references": { - "flake": false, - "locked": { - "lastModified": 1743491695, - "narHash": "sha256-XsdneGNJzmRBggk8lz9JNDQYk7wbYfUAF2oZLXzFb9c=", - "owner": "jmbuhr", - "repo": "cmp-pandoc-references", - "rev": "130eae4f75029d6495808e0ea4b769fa1ce4c9ac", - "type": "github" - }, - "original": { - "owner": "jmbuhr", - "repo": "cmp-pandoc-references", - "type": "github" - } - }, - "plugins-r": { - "flake": false, - "locked": { - "lastModified": 1776905071, - "narHash": "sha256-dXox6qEs1VDE7vPNDoN8bY4g06uj1IEs6uki72w8lpA=", - "owner": "R-nvim", - "repo": "R.nvim", - "rev": "582f2af11290ac067e49018db38e12a511325556", - "type": "github" - }, - "original": { - "owner": "R-nvim", - "ref": "v0.99.4", - "repo": "R.nvim", - "type": "github" - } - }, - "r-nvim-nix": { - "inputs": { - "nixpkgs": [ - "nvimConfig", - "rixpkgs" - ], - "rnvimsrc": [ - "nvimConfig", - "plugins-r" - ] - }, - "locked": { - "lastModified": 1778684156, - "narHash": "sha256-Z4y1tQfkIsPK4NRxGn668HMDfWxnxNxSJ0CAOOXiIfY=", - "owner": "dwinkler1", - "repo": "r_nvim_nix", - "rev": "2f49dfee27886068e2f49cbd54558ce4cc424c82", - "type": "github" - }, - "original": { - "owner": "dwinkler1", - "repo": "r_nvim_nix", - "type": "github" - } - }, - "rixpkgs": { - "locked": { - "lastModified": 1771303851, - "narHash": "sha256-tgveHozOJ2D/mi3LxVy/FcmLFDlM5XKZxsNB2XpvzaM=", - "owner": "dwinkler1", - "repo": "rixpkgs", - "rev": "af2dd3f7b4b172077747c0869d4e30702fb71b0e", - "type": "github" - }, - "original": { - "owner": "dwinkler1", - "repo": "rixpkgs", - "rev": "af2dd3f7b4b172077747c0869d4e30702fb71b0e", - "type": "github" - } - }, - "root": { - "inputs": { - "fran": "fran", - "nixpkgs": "nixpkgs", - "nvimConfig": "nvimConfig", - "rixpkgs": "rixpkgs" - } - }, - "wrappers": { - "inputs": { - "nixpkgs": [ - "nvimConfig", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1779297405, - "narHash": "sha256-VFoBwH7ZjVxCnvZTb5ODRXt70sLtWMxstive0N+RS50=", - "owner": "BirdeeHub", - "repo": "nix-wrapper-modules", - "rev": "e7ed7a1205945befdf2e0d73ba7df91d935e5af1", - "type": "github" - }, - "original": { - "owner": "BirdeeHub", - "repo": "nix-wrapper-modules", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/templates/ed/flake.nix b/templates/ed/flake.nix deleted file mode 100644 index b674c62..0000000 --- a/templates/ed/flake.nix +++ /dev/null @@ -1,203 +0,0 @@ -{ - description = "Project Editor"; - - outputs = { - self, - nixpkgs, - nvimConfig, - ... - } @ inputs: let - # ── Shared language support flags ────────────────────────────── - # Used by both the neovim wrapper module and the devShell - cats = { - clickhouse = false; - gitPlugins = false; - julia = false; - lua = false; - markdown = false; - nix = true; - optional = false; - python = false; - r = false; - }; - - # ── Language package lists ──────────────────────────────────── - # Shared between wrapper lang_packages and devShell toolchains. - # Accept pkgs so they work inside forAllSystems for each system. - - rPackages = pkgs: - (with pkgs.rpkgs.rPackages; [ - fixest - # pkgs.extraRPackages.musicMetadata - ]) - ++ ( - if builtins.pathExists ./r-packages.nix - # p: with p.rPackages; [ ... ] - then import ./r-packages.nix pkgs.rpkgs - else [] - ); - - pythonPackages = pkgs: - (with pkgs.python3Packages; [ - duckdb - polars - ]) - ++ ( - if builtins.pathExists ./python-packages.nix - # p: with p; [ ... ] - then import ./python-packages.nix pkgs.python3Packages - else [] - ); - - juliaPackages = - ["StatsBase"] - ++ ( - if builtins.pathExists ./julia-packages.nix - # [ ... ] - then import ./julia-packages.nix - else [] - ); - - systems = ["aarch64-darwin" "x86_64-linux" "aarch64-linux"]; - forAllSystems = nixpkgs.lib.genAttrs systems; - overlays = [inputs.nvimConfig.overlays.dependencies]; - in { - formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); - - packages = forAllSystems (system: let - pkgs = import nixpkgs { - inherit system overlays; - config = {allowUnfree = true;}; - }; - # Plain attrset — pkgs is captured from the surrounding scope, - # so the module system does not need lazy _module.args resolution. - projectSettings = { - inherit cats; - settings = let - # With `replace` packages are replaced otherwise they are merged with base packages - replace = pkgs.lib.mkForce; - in { - lang_packages = { - python = replace (pythonPackages pkgs); - r = replace (rPackages pkgs); - julia = replace juliaPackages; - }; - colorscheme = "kanagawa"; - background = "dark"; - wrapRc = true; - }; - binName = "nv"; - - env = { - IS_PROJECT_EDITOR = "1"; - }; - - runtimePkgs = with pkgs; [ - cowsay - ]; - - specs.extraLua = let - name = builtins.baseNameOf (builtins.toString ./.); - in { - data = pkgs.vimPlugins.mini-notify; - before = ["INIT_MAIN"]; - config = '' - require("mini.notify").setup() - vim.notify = MiniNotify.make_notify() - vim.notify("Welcome to ${name}!") - ''; - }; - }; - evalResult = nvimConfig.inputs.wrappers.lib.evalModules { - modules = [ - nvimConfig.wrapperModules.default - projectSettings - ]; - }; - in { - default = evalResult.config.wrap {inherit pkgs;}; - }); - - devShells = forAllSystems (system: let - pkgs = import nixpkgs { - inherit system overlays; - config = {allowUnfree = true;}; - }; - nv = self.packages.${system}.default; - in { - default = pkgs.mkShell { - shellHook = '' - exec nu - alias gst='git status' - alias glol='git log --oneline --graph --decorate' - alias gc='git commit' - alias gl='git pull' - alias gp='git push' - ''; - packages = - [ - nv - pkgs.git - pkgs.pre-commit - pkgs.nushell - ] - # ── R toolchain (R REPL, quarto, LSP, formatter) ───── - ++ pkgs.lib.optionals cats.r (let - r_packages = (pkgs.baseRPackages or []) ++ rPackages pkgs; - in [ - (pkgs.rWrapper.override {packages = r_packages;}) - pkgs.radianWrapper - pkgs.air-formatter - pkgs.yaml-language-server - pkgs.nvimcom - pkgs.rnvimserver - ]) - # ── Python toolchain (interpreter, LSP, formatter) ──── - ++ pkgs.lib.optionals cats.python [ - (pkgs.python3.withPackages (ps: pkgs.basePythonPackages ps ++ pythonPackages pkgs)) - pkgs.nodejs - pkgs.ruff - pkgs.basedpyright - pkgs.uv - ] - # ── Julia toolchain ─────────────────────────────────── - ++ pkgs.lib.optionals cats.julia [ - pkgs.julia-bin.withPackages - juliaPackages - ] - # ── Markdown toolchain (quarto, zk) ─────────────────── - ++ (let - r_packages = (pkgs.baseRPackages or []) ++ rPackages pkgs; - quarto = - if cats.r - then pkgs.quarto.override {extraRPackages = r_packages;} - else pkgs.quarto; - in - pkgs.lib.optionals cats.markdown [ - pkgs.python313Packages.pylatexenc - quarto - pkgs.zk - ]); - }; - }); - }; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - rixpkgs.url = "github:dwinkler1/rixpkgs/af2dd3f7b4b172077747c0869d4e30702fb71b0e"; - fran = { - url = "github:dwinkler1/fran"; - inputs = { - nixpkgs.follows = "rixpkgs"; - }; - }; - nvimConfig = { - url = "github:dwinkler1/nvimConfig"; - inputs = { - rixpkgs.follows = "rixpkgs"; - nixpkgs.follows = "nixpkgs"; - fran.follows = "fran"; - }; - }; - }; -} diff --git a/templates/rde/README.md b/templates/rde/README.md index d3a4cbf..c28ac3c 100644 --- a/templates/rde/README.md +++ b/templates/rde/README.md @@ -367,6 +367,11 @@ The CI runs on: This ensures that users can confidently use the template knowing that all advertised functionality has been verified. +## Related Documentation + +- [REFACTORING.md](REFACTORING.md) - Technical details about the modular structure +- [SUMMARY.md](SUMMARY.md) - Metrics and comparison with original template + ## Usage Use this template with: diff --git a/templates/rde/REFACTORING.md b/templates/rde/REFACTORING.md new file mode 100644 index 0000000..7098105 --- /dev/null +++ b/templates/rde/REFACTORING.md @@ -0,0 +1,150 @@ +# Template Refactoring Summary + +## Overview +This document summarizes the refactoring improvements made to the RDE (Research Development Environment) template flake. + +## Changes Made + +### 1. File Structure Reorganization +**Before**: Single 688-line `flake.nix` file +**After**: Modular structure with 17 files across 5 directories + +``` +templates/rde/ +├── flake.nix (261 lines) - Main configuration +├── README.md - User documentation +├── REFACTORING.md - This file +├── overlays/ (5 files) +│ ├── r.nix - R package configuration +│ ├── python.nix - Python package configuration +│ ├── rix.nix - rstats-on-nix integration +│ ├── theme.nix - Neovim theme setup +│ └── project-scripts.nix - Script wrapper definitions +├── hosts/ (5 files) +│ ├── default.nix - Merges all host configs +│ ├── python.nix - Python command definitions +│ ├── julia.nix - Julia command definitions +│ ├── r.nix - R command definitions +│ └── utils.nix - Utility command definitions +├── lib/ (2 files) +│ ├── shell-hook.nix - Dev shell welcome message +│ └── mini-notify-config.lua - Neovim notification config +└── scripts/ (4 files) + ├── initPython.sh - Python project initialization + ├── initProject.sh - Project structure setup + ├── updateDeps.sh - Dependency update script + └── activateDevenv.sh - Devenv activation +``` + +### 2. Key Improvements + +#### Separation of Concerns +- **Config**: Main configuration stays in flake.nix +- **Overlays**: Package modifications isolated in overlays/ +- **Hosts**: Command definitions organized by language in hosts/ +- **Scripts**: Shell scripts extracted to scripts/ directory +- **Helpers**: Utility functions in lib/ + +#### Readability +- Reduced main file from 688 to 261 lines (62% reduction) +- Added strategic comments explaining key sections +- Extracted long inline strings to separate files +- Grouped related functionality together + +#### Maintainability +- Language-specific changes isolated to dedicated files +- Easy to add new languages (create new host/overlay files) +- Easy to modify scripts without touching Nix code +- Clear separation between different concerns + +#### Reusability +- Individual overlays can be reused in other projects +- Host definitions can be copied/modified independently +- Scripts can be tested/modified separately +- Modular design allows selective adoption + +### 3. Specific Extractions + +#### Shell Scripts (200+ lines → 4 files) +- `initPython.sh`: Python project initialization logic +- `initProject.sh`: Directory structure and git setup +- `updateDeps.sh`: Dependency update automation +- `activateDevenv.sh`: Devenv shell activation + +#### Overlays (100+ lines → 5 files) +- `r.nix`: R package management with rix integration +- `python.nix`: Python package configuration +- `rix.nix`: rstats-on-nix package source +- `theme.nix`: Neovim colorscheme handling +- `project-scripts.nix`: Script wrapper generation + +#### Host Definitions (200+ lines → 5 files) +- `python.nix`: marimo, ipy, py, initPython commands +- `julia.nix`: jl, pluto, initJl commands +- `r.nix`: R console command +- `utils.nix`: initProject, updateDeps, devenv commands +- `default.nix`: Merges all host configurations + +#### Helper Functions (40+ lines → 2 files) +- `shell-hook.nix`: Dev shell welcome message generation +- `mini-notify-config.lua`: Neovim notification filtering + +### 4. Added Documentation + +#### README.md +- Overview of template purpose +- Directory structure explanation +- Benefits of modular design +- Configuration instructions +- Extension guidelines +- Usage examples + +#### Inline Comments +- Section headers in flake.nix +- Explanation of key configuration blocks +- Purpose of each import +- Documentation of categories and settings + +### 5. Benefits Achieved + +1. **Maintainability**: + - Changes to one language don't affect others + - Easy to locate and modify specific functionality + - Clear ownership of different components + +2. **Readability**: + - Main file is now scannable and understandable + - Related code grouped together + - Inline documentation guides users + +3. **Testability**: + - Scripts can be tested independently + - Overlays can be verified in isolation + - Smaller files are easier to debug + +4. **Extensibility**: + - Clear patterns for adding new languages + - Easy to add new commands + - Simple to customize per language + +5. **Learning**: + - New users can understand the template structure + - Examples in each file guide modifications + - Documentation explains purpose and usage + +## Migration Guide + +For users of the old template: +1. The functionality remains identical +2. Configuration in the main config section is the same +3. All commands work exactly as before +4. To customize, now edit the specific file in the appropriate directory + +## Future Improvements + +Possible future enhancements: +- Add validation scripts for configuration +- Create unit tests for individual modules +- Add more language examples (Go, Rust, etc.) +- Create a configuration wizard script +- Add CI/CD integration examples diff --git a/templates/rde/SUMMARY.md b/templates/rde/SUMMARY.md new file mode 100644 index 0000000..9b9947d --- /dev/null +++ b/templates/rde/SUMMARY.md @@ -0,0 +1,172 @@ +# Template Refactoring - Complete Summary + +## 🎯 Objective Achieved +Successfully refactored the RDE template from a single 688-line file into a modular, maintainable structure. + +## 📊 Key Metrics + +| Aspect | Before | After | Improvement | +|--------|--------|-------|-------------| +| **Main file (flake.nix)** | 688 lines | 261 lines | **62% reduction** | +| **File structure** | 1 monolithic file | 17 modular files | **Better organized** | +| **Documentation** | 0 lines | 218 lines | **Fully documented** | +| **Directories** | 0 | 5 organized dirs | **Clear structure** | + +## 📁 New Structure + +``` +templates/rde/ +├── 📄 flake.nix (261 lines) # Main config - clean & commented +├── 📖 README.md # User guide +├── 📖 REFACTORING.md # Technical details +│ +├── 📂 overlays/ # Package configurations +│ ├── r.nix # R packages +│ ├── python.nix # Python packages +│ ├── rix.nix # R nixpkgs source +│ ├── theme.nix # Neovim themes +│ └── project-scripts.nix # Script wrappers +│ +├── 📂 hosts/ # Command definitions +│ ├── default.nix # Merger +│ ├── python.nix # Python commands +│ ├── julia.nix # Julia commands +│ ├── r.nix # R commands +│ └── utils.nix # Utility commands +│ +├── 📂 lib/ # Helper functions +│ ├── shell-hook.nix # Welcome message +│ └── mini-notify-config.lua # Neovim config +│ +└── 📂 scripts/ # Shell scripts + ├── initPython.sh # Python init + ├── initProject.sh # Project setup + ├── updateDeps.sh # Update deps + └── activateDevenv.sh # Devenv activation +``` + +## ✨ Key Improvements + +### 1. **Separation of Concerns** +- Configuration stays in main flake.nix +- Language-specific code in dedicated files +- Scripts separated from Nix code +- Helpers isolated in lib/ + +### 2. **Enhanced Readability** +- Main file reduced from 688 → 261 lines +- Strategic comments explain sections +- Clear naming conventions +- Logical grouping of related code + +### 3. **Better Maintainability** +- Modify one language without affecting others +- Easy to locate specific functionality +- Clear patterns for adding features +- Reduced risk of breaking changes + +### 4. **Improved Extensibility** +- Add new languages: create host + overlay files +- Add new commands: edit relevant host file +- Modify scripts: edit .sh files directly +- Customize behavior: clear config section + +### 5. **Comprehensive Documentation** +- README.md: User-facing guide +- REFACTORING.md: Technical details +- Inline comments: Explain key sections +- Examples: Show how to extend + +## 🔄 Backwards Compatibility + +✅ **Zero Breaking Changes** +- All existing functionality preserved +- Same configuration interface +- All commands work identically +- Migration is seamless + +## 🎓 Learning Benefits + +### For Users +- Easier to understand template structure +- Clear examples for customization +- Self-documenting code organization +- Guided by inline comments + +### For Developers +- Easy to modify individual components +- Clear separation aids debugging +- Modular structure enables testing +- Well-documented refactoring process + +## 📈 Before & After Comparison + +### Before Refactoring +```nix +{ + description = "New Project"; + outputs = { ... }: let + config = { ... }; + # 200+ lines of inline bash scripts + initPython = '' + #!/usr/bin/env bash + # ... lots of bash code ... + ''; + # 100+ lines of overlay definitions + rOverlay = final: prev: let + # ... complex overlay code ... + # 300+ lines of host definitions + hosts = { + marimo = let marimoInit = '' + # ... more inline bash ... + # ... continues for 688 lines total +``` + +### After Refactoring +```nix +{ + description = "New Project"; + outputs = { ... }: let + # Clear config section + config = { ... }; + + # Import from organized modules + rOverlay = import ./overlays/r.nix; + pythonOverlay = import ./overlays/python.nix; + # ... clean imports ... + + # Main configuration + projectConfig = forSystems (system: + # ... focused on structure, not details +``` + +## 🚀 Next Steps + +The template is now: +1. ✅ Well-organized and modular +2. ✅ Fully documented +3. ✅ Easy to maintain +4. ✅ Simple to extend +5. ✅ Ready for production use + +## 💡 Usage + +No changes required for existing users! The template works exactly as before, but now with: +- Better code organization +- Comprehensive documentation +- Easier customization options +- Clearer structure for learning + +## 📝 Files Modified + +- `flake.nix` - Simplified and reorganized +- Created `overlays/` - Package configurations +- Created `hosts/` - Command definitions +- Created `lib/` - Helper functions +- Created `scripts/` - Shell scripts +- Added `README.md` - User documentation +- Added `REFACTORING.md` - Technical guide + +## 🎉 Success! + +The refactoring is complete. The template is now significantly more maintainable, readable, and extensible while preserving all original functionality. diff --git a/templates/rde/flake.lock b/templates/rde/flake.lock index 6e88194..d462a94 100644 --- a/templates/rde/flake.lock +++ b/templates/rde/flake.lock @@ -4,14 +4,17 @@ "inputs": { "nixpkgs": [ "rixpkgs" + ], + "nvimcom": [ + "plugins-r" ] }, "locked": { - "lastModified": 1776413584, - "narHash": "sha256-xqqv46MTveuT4yJH2YihmbHGy5mdLnnLFDebVmUws/E=", + "lastModified": 1761271358, + "narHash": "sha256-Yf1u/FvSKCD0sr0xmTE/Cwgy7H/YW2L/1R7tbxtLfDw=", "owner": "dwinkler1", "repo": "fran", - "rev": "da09626e4dd8f0f57078b3a04e0443a8c20defa1", + "rev": "3bcaf6aa8b74bb1f754e14d975d64bd970fdbe56", "type": "github" }, "original": { @@ -43,11 +46,11 @@ ] }, "locked": { - "lastModified": 1770172580, - "narHash": "sha256-l/fKPLdKxq7PLRbExDxsS4Esel4yos/NFJOFcDpsm2E=", + "lastModified": 1765425579, + "narHash": "sha256-XQLrlG8Uf1GOBy5EQlPP19foLfF3CY/ruQc9xonyGCQ=", "owner": "dwinkler1", "repo": "nixCatsConfig", - "rev": "98079a0844e53afd0c593c8f4d1ee5381baf36f0", + "rev": "7fc90930a9cb08aeccd575122f6fc1524ed2c71b", "type": "github" }, "original": { @@ -58,11 +61,11 @@ }, "nixCats_2": { "locked": { - "lastModified": 1769085828, - "narHash": "sha256-TjhFIAtS628+/r3IuYWPcNa++mUMMDDG8PbSfFHXBiA=", + "lastModified": 1763330129, + "narHash": "sha256-KbOeWIF52SV53BOeETGO2C5ewaV2Ex9iaXH7G72gOr8=", "owner": "BirdeeHub", "repo": "nixCats-nvim", - "rev": "43fbf4d12b0a613f1a792503da4bb2bf270173c7", + "rev": "c81551ed87db2aefab30a12cf7425ff94dc0ad64", "type": "github" }, "original": { @@ -73,11 +76,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1777077449, - "narHash": "sha256-AIiMJiqvGrN4HyLEbKAoCSRRYn0rnlW5VbKNIMIYqm4=", + "lastModified": 1765838191, + "narHash": "sha256-m5KWt1nOm76ILk/JSCxBM4MfK3rYY7Wq9/TZIIeGnT8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "a4bf06618f0b5ee50f14ed8f0da77d34ecc19160", + "rev": "c6f52ebd45e5925c188d1a20119978aa4ffd5ef6", "type": "github" }, "original": { @@ -138,16 +141,16 @@ }, "rixpkgs": { "locked": { - "lastModified": 1776958221, - "narHash": "sha256-cOHLrMWifj8HQMIG6gMhGowwPAkyX/kijDx38wK8kUM=", + "lastModified": 1765802109, + "narHash": "sha256-Aru0TG1mEhIJiaXElFopn5lrAE+pyxfF0JelHOIY4FQ=", "owner": "rstats-on-nix", "repo": "nixpkgs", - "rev": "db90c554b7172188324b84deea35ed5975e20e44", + "rev": "bdfc55ed37f7d1228a856be0f57876596b04477a", "type": "github" }, "original": { "owner": "rstats-on-nix", - "ref": "2026-04-22", + "ref": "2025-12-15", "repo": "nixpkgs", "type": "github" } diff --git a/templates/rde/flake.nix b/templates/rde/flake.nix index 12ae4f0..f83ec3f 100644 --- a/templates/rde/flake.nix +++ b/templates/rde/flake.nix @@ -219,7 +219,7 @@ }); }; inputs = { - rixpkgs.url = "github:rstats-on-nix/nixpkgs/2026-04-22"; + rixpkgs.url = "github:rstats-on-nix/nixpkgs/2025-12-15"; nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; nixCats = { url = "github:dwinkler1/nixCatsConfig"; @@ -237,6 +237,7 @@ url = "github:dwinkler1/fran"; inputs = { nixpkgs.follows = "rixpkgs"; + nvimcom.follows = "plugins-r"; }; }; ## Git Plugins