From 6301de617d2fe5876ca007dcc9cee4c371fc5dc9 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 23 Oct 2026 18:31:26 +0200 Subject: added create flake script --- home-manager/scripts/create-flake.sh | 115 +++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100755 home-manager/scripts/create-flake.sh (limited to 'home-manager/scripts/create-flake.sh') diff --git a/home-manager/scripts/create-flake.sh b/home-manager/scripts/create-flake.sh new file mode 100755 index 0000000..1c00701 --- /dev/null +++ b/home-manager/scripts/create-flake.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Print styled messages +info() { echo -e "\033[1;34m[INFO]\033[0m $1"; } +success() { echo -e "\033[1;32m[SUCCESS]\033[0m $1"; } +error() { echo -e "\033[1;31m[ERROR]\033[0m $1"; exit 1; } + +# Check if flake.nix already exists +if [[ -f "flake.nix" ]]; then + error "A flake.nix file already exists in this directory!" +fi + +# Prompt user for template type +echo "Select a flake template to generate:" +echo "1) Generic / Minimal" +echo "2) Go" +echo "3) Node.js / TypeScript" +echo "4) Python" +echo "5) Rust" +read -rp "Enter choice [1-5]: " CHOICE + +case "$CHOICE" in + 1) + TEMPLATE_TYPE="generic" + PACKAGES="ripgrep jq curl" + EXTRA_VARS="" + ;; + 2) + TEMPLATE_TYPE="go" + PACKAGES="go gopls golangci-lint delve" + EXTRA_VARS="GOPATH = \"\$(pwd)/.go\";" + ;; + 3) + TEMPLATE_TYPE="node" + PACKAGES="nodejs_20 corepack nodePackages.typescript-language-server" + EXTRA_VARS="" + ;; + 4) + TEMPLATE_TYPE="python" + PACKAGES="(python3.withPackages (ps: with ps; [ numpy requests ])) ruff pyright" + EXTRA_VARS="" + ;; + 5) + TEMPLATE_TYPE="rust" + PACKAGES="cargo rustc clippy rustfmt rust-analyzer" + EXTRA_VARS="" + ;; + *) + error "Invalid selection." + ;; +esac + +info "Generating flake.nix for [$TEMPLATE_TYPE] environment..." + +# Generate flake.nix +cat < flake.nix +{ + description = "Development environment for $TEMPLATE_TYPE"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.\${system}; + in + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + $PACKAGES + ]; + + env = { + $EXTRA_VARS + }; + + shellHook = '' + echo "🚀 Entering $TEMPLATE_TYPE dev environment" + ''; + }; + } + ); +} +EOF + +# Optional: Create .envrc for direnv integration +if [[ ! -f ".envrc" ]]; then + read -rp "Do you want to create a .envrc file for direnv integration? [y/N]: " ENABLE_DIRENV + if [[ "$ENABLE_DIRENV" =~ ^[Yy]$ ]]; then + echo "use flake" > .envrc + info "Created .envrc" + if command -v direnv &> /dev/null; then + direnv allow + fi + fi +fi + +# Git integration requirement +if [[ -d ".git" ]]; then + info "Staging flake.nix in Git..." + git add flake.nix + if [[ -f ".envrc" ]]; then + git add .envrc 2>/dev/null || true + fi +else + info "Note: Git repository not detected. If you initialize Git, remember to run 'git add flake.nix'." +fi + +success "flake.nix successfully generated!" +echo -e "\nRun \033[1mnix develop\033[0m to enter your new shell." -- cgit v1.2.3