diff --git a/templates/rde/hosts/julia.nix b/templates/rde/hosts/julia.nix index aaf70ab..1ac861e 100644 --- a/templates/rde/hosts/julia.nix +++ b/templates/rde/hosts/julia.nix @@ -49,7 +49,9 @@ config: pkgs: { pluto = let runPluto = '' import Pkg; import TOML; Pkg.instantiate(); - if !isfile("Project.toml") || !haskey(TOML.parsefile(Base.active_project())["deps"], "Pluto") + proj = isfile("Project.toml") ? TOML.parsefile(Base.active_project()) : Dict(); + deps = get(proj, "deps", Dict()); + if !haskey(deps, "Pluto") Pkg.add("Pluto"); end import Pluto; Pluto.run(); diff --git a/templates/rde/hosts/python.nix b/templates/rde/hosts/python.nix index 45aa1f2..d1c7b16 100644 --- a/templates/rde/hosts/python.nix +++ b/templates/rde/hosts/python.nix @@ -37,17 +37,12 @@ config: pkgs: { echo "🐍 Launching Marimo..." echo "--------------------------------------------------------------------------" fi + uv run marimo edit "$@" ''; in { enable = config.enabledLanguages.python; path = { - value = "${pkgs.uv}/bin/uv"; - args = [ - "--run" - "${marimoInit}" - "--add-flags" - "run marimo edit \"$@\"" - ]; + value = "${pkgs.writeShellScriptBin "marimo-wrapper" marimoInit}/bin/marimo-wrapper"; }; }; @@ -78,23 +73,16 @@ config: pkgs: { else echo "--------------------------------------------------------------------------" echo "🔄 Syncing existing project..." - echo "đŸ“Ļ Ensuring IPython is installed..." - uv add ipython uv sync echo "🐍 Launching IPython..." echo "--------------------------------------------------------------------------" fi + uv run ipython "$@" ''; in { enable = config.enabledLanguages.python; path = { - value = "${pkgs.uv}/bin/uv"; - args = [ - "--run" - "${ipythonInit}" - "--add-flags" - "run ipython \"$@\"" - ]; + value = "${pkgs.writeShellScriptBin "ipy-wrapper" ipythonInit}/bin/ipy-wrapper"; }; }; diff --git a/templates/rde/overlays/project-scripts.nix b/templates/rde/overlays/project-scripts.nix index dbb5ade..15786da 100644 --- a/templates/rde/overlays/project-scripts.nix +++ b/templates/rde/overlays/project-scripts.nix @@ -26,14 +26,14 @@ config: final: prev: let (builtins.readFile scriptPath); in { # Python project initialization (creates pyproject.toml, adds packages) - initPython = prev.writeShellScriptBin "initPython" (substituteScript ./scripts/initPython.sh); + initPython = prev.writeShellScriptBin "initPython" (substituteScript ../scripts/initPython.sh); # Project structure setup (creates directories, git repo, .gitignore) - initProject = prev.writeShellScriptBin "initProject" (substituteScript ./scripts/initProject.sh); + initProject = prev.writeShellScriptBin "initProject" (substituteScript ../scripts/initProject.sh); # Update all dependencies (R packages, Python packages, flake inputs) - updateDeps = prev.writeShellScriptBin "updateDeps" (substituteScript ./scripts/updateDeps.sh); + updateDeps = prev.writeShellScriptBin "updateDeps" (substituteScript ../scripts/updateDeps.sh); # Activate devenv environment if devenv.nix exists - activateDevenv = prev.writeShellScriptBin "activateDevenv" (substituteScript ./scripts/activateDevenv.sh); + activateDevenv = prev.writeShellScriptBin "activateDevenv" (substituteScript ../scripts/activateDevenv.sh); } diff --git a/templates/rde/scripts/initProject.sh b/templates/rde/scripts/initProject.sh index c616268..09a92d4 100644 --- a/templates/rde/scripts/initProject.sh +++ b/templates/rde/scripts/initProject.sh @@ -44,15 +44,24 @@ fi # Initialize git if [[ ! -d ".git" ]]; then git init - echo "✓ Initialized Git repository and added: flake.nix, flake.lock" + echo "✓ Initialized Git repository" fi -# Check if files are already staged/tracked before adding -if ! git diff --cached --name-only | grep -q "flake.nix\|flake.lock" && - ! git ls-files --error-unmatch flake.nix flake.lock >/dev/null 2>&1; then - echo "✓ Adding flake.nix, flake.lock to Git repository" - git add flake.nix flake.lock -else - echo "✓ flake.nix, flake.lock already tracked/staged in Git" + +# Check if files exist and are not already staged/tracked before adding +if [[ -f "flake.nix" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.nix" && + ! git ls-files --error-unmatch flake.nix >/dev/null 2>&1; then + echo "✓ Adding flake.nix to Git repository" + git add flake.nix +elif [[ -f "flake.nix" ]]; then + echo "✓ flake.nix already tracked/staged in Git" +fi + +if [[ -f "flake.lock" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.lock" && + ! git ls-files --error-unmatch flake.lock >/dev/null 2>&1; then + echo "✓ Adding flake.lock to Git repository" + git add flake.lock +elif [[ -f "flake.lock" ]]; then + echo "✓ flake.lock already tracked/staged in Git" fi # Create .gitignore if [[ ! -f ".gitignore" ]]; then diff --git a/templates/rde/scripts/updateDeps.sh b/templates/rde/scripts/updateDeps.sh index 61310a4..57be44f 100644 --- a/templates/rde/scripts/updateDeps.sh +++ b/templates/rde/scripts/updateDeps.sh @@ -3,30 +3,77 @@ set -euo pipefail echo "🔄 Updating project dependencies..." +# Ensure we're in the repository root +if [[ ! -f "flake.nix" ]]; then + # Try to find git root + if git rev-parse --show-toplevel >/dev/null 2>&1; then + cd "$(git rev-parse --show-toplevel)" + if [[ ! -f "flake.nix" ]]; then + echo "❌ Error: flake.nix not found in repository root" + exit 1 + fi + else + echo "❌ Error: Not in a git repository and flake.nix not found" + exit 1 + fi +fi + # Fetch latest R version from rstats-on-nix # This command chain: downloads CSV, extracts last line, gets 4th field (date), removes quotes -RVER=$( wget -qO- 'https://raw.githubusercontent.com/ropensci/rix/refs/heads/main/inst/extdata/available_df.csv' | tail -n 1 | head -n 1 | cut -d',' -f4 | tr -d '"' ) &&\ +echo "📡 Fetching latest R version from rstats-on-nix..." +RVER=$( wget -qO- 'https://raw.githubusercontent.com/ropensci/rix/refs/heads/main/inst/extdata/available_df.csv' | tail -n 1 | head -n 1 | cut -d',' -f4 | tr -d '"' ) + +# Validate RVER matches YYYY-MM-DD format +if [[ ! "$RVER" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then + echo "❌ Error: Failed to fetch valid R version date. Got: '$RVER'" + exit 1 +fi + +echo "✅ R date is $RVER" + +# Create backup of flake.nix before modifying +cp flake.nix flake.nix.backup # Update rixpkgs date in flake.nix -sed -i "s|rixpkgs.url = \"github:rstats-on-nix/nixpkgs/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\";|rixpkgs.url = \"github:rstats-on-nix/nixpkgs/$RVER\";|" flake.nix -echo "✅ R date is $RVER" +if sed -i "s|rixpkgs.url = \"github:rstats-on-nix/nixpkgs/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\";|rixpkgs.url = \"github:rstats-on-nix/nixpkgs/$RVER\";|" flake.nix; then + echo "✅ Updated rixpkgs date in flake.nix" + rm flake.nix.backup +else + echo "âš ī¸ Warning: Failed to update flake.nix, restoring backup" + mv flake.nix.backup flake.nix +fi nix flake update echo "✅ Flake inputs updated" +# Update Python dependencies if pyproject.toml exists and uv is available if [[ -f "pyproject.toml" ]]; then - uv sync --upgrade - echo "✅ Python dependencies updated" + if command -v uv >/dev/null 2>&1; then + uv sync --upgrade + echo "✅ Python dependencies updated" + else + echo "â„šī¸ pyproject.toml found but uv command not available, skipping Python update" + fi fi +# Update Julia dependencies if Project.toml exists and julia is available if [[ -f "Project.toml" ]]; then - @defaultPackageName@-jl -e "using Pkg; Pkg.update()" - echo "✅ Julia dependencies updated" + if command -v @defaultPackageName@-jl >/dev/null 2>&1; then + @defaultPackageName@-jl -e "using Pkg; Pkg.update()" + echo "✅ Julia dependencies updated" + else + echo "â„šī¸ Project.toml found but @defaultPackageName@-jl command not available, skipping Julia update" + fi fi +# Update devenv dependencies if devenv.nix exists and devenv is available if [[ -f "devenv.nix" ]]; then - devenv update - echo "✅ Devenv dependencies updated" + if command -v devenv >/dev/null 2>&1; then + devenv update + echo "✅ Devenv dependencies updated" + else + echo "â„šī¸ devenv.nix found but devenv command not available, skipping devenv update" + fi fi echo "🎉 All dependencies updated!"