diff --git a/justfiles/main.just b/justfiles/main.just index ac0720b..51b965a 100644 --- a/justfiles/main.just +++ b/justfiles/main.just @@ -10,7 +10,7 @@ import? "/etc/self-host-playbook/tiers/premium.just" gum style \ --foreground 212 --border double --border-foreground 212 \ --align center --width 50 --margin "1 2" --padding "1 2" \ - "šŸš€ DevOps Control Center šŸš€" + "šŸš€ Self-Hosting Playbook Command Center šŸš€" } # Function to create menu items with icons and descriptions @@ -20,6 +20,7 @@ import? "/etc/self-host-playbook/tiers/premium.just" echo "šŸ’¾ Disk Usage - Show docker disk usage" echo "šŸ”„ Restart - Restart a specific container" echo "🐳 Update Docker - Update Docker containers" + echo "🌐 Add custom service" echo "āŒ Exit" } @@ -58,7 +59,9 @@ import? "/etc/self-host-playbook/tiers/premium.just" "🐳 Update Docker"*) just update-containers ;; - "āŒ Exit") + "🌐 Add custom"*) + just add-custom-service + ;; "āŒ Exit") echo "Goodbye! šŸ‘‹" | gum style --foreground 212 exit 0 ;; diff --git a/justfiles/tiers/core.just b/justfiles/tiers/core.just index 1aa042c..c85b056 100644 --- a/justfiles/tiers/core.just +++ b/justfiles/tiers/core.just @@ -1,101 +1,14 @@ status: - #!/usr/bin/env bash - gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "šŸ“Š Running Containers" - docker ps --format "table {{"{{.Names}}\t{{.Status}}"}}" | gum table + @/etc/self-host-playbook/scripts/status.sh -# Interactive logs viewer with gum logs: - #!/usr/bin/env bash - gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "šŸ“ Docker Logs Viewer" - - # Get running container names - containers=($(docker ps --format "{{"{{.Names}}"}}")) - - if [ ${#containers[@]} -eq 0 ]; then - gum style --foreground 1 "āš ļø No running containers found" - exit 1 - fi - - # Select container using gum choose - container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container:" --cursor.foreground 212) - - if [ -z "$container" ]; then - exit 0 - fi - - # Select number of lines using gum choose - lines=$(gum choose --header "Select number of log lines:" --cursor.foreground 212 \ - "5 lines" "10 lines" "25 lines" "50 lines" "100 lines" "200 lines") - - if [ -z "$lines" ]; then - exit 0 - fi - - # Extract number from selection - lines=${lines%% *} - - # Show spinner while fetching logs - gum spin --spinner dot --title "Fetching logs..." -- sleep 1 - - # Show logs - docker logs "$container" 2>&1 | tail -n "$lines" | gum pager + @/etc/self-host-playbook/scripts/logs.sh docker-disk: - #!/usr/bin/env bash - gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "šŸ’¾ Docker Disk Usage" - docker system df | gum table + @/etc/self-host-playbook/scripts/docker-disk.sh docker-restart: - #!/usr/bin/env bash - containers=($(docker ps --format "{{"{{.Names}}"}}")) - if [ ${#containers[@]} -eq 0 ]; then - gum style --foreground 1 "āš ļø No running containers found" - exit 1 - fi - container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container to restart:" --cursor.foreground 212) - if [ -n "$container" ]; then - gum spin --spinner dot --title "Restarting $container..." -- docker restart "$container" - gum style --foreground 212 "āœ… Container $container restarted successfully!" - fi + @/etc/self-host-playbook/scripts/docker-restart.sh update-containers: - #!/usr/bin/env bash - set -e # Exit on error - CONTAINERS=($(docker ps --format "{{"{{.Names}}"}}")) - - echo "Will update these containers:" - printf '%s\n' "${CONTAINERS[@]}" | gum table && \ - gum confirm "Continue?" || exit 0 - - # First collect all image information - declare -A CONTAINER_IMAGES - echo "Collecting image information..." - for container in "${CONTAINERS[@]}"; do - FULL_IMAGE=$(docker inspect "$container" --format '{{"{{.Config.Image}}"}}') - CONTAINER_IMAGES[$container]=$(echo "$FULL_IMAGE" | sed 's/@sha256.*$//') - echo "$container -> ${CONTAINER_IMAGES[$container]}" - done - - echo "Stopping containers..." && \ - for container in "${CONTAINERS[@]}"; do - echo "Stopping $container..." - sudo systemctl stop "docker-$container.service" - done - - echo "Pulling new images..." && \ - for container in "${CONTAINERS[@]}"; do - IMAGE="${CONTAINER_IMAGES[$container]}" - echo -e "\nšŸ“„ Pulling $IMAGE for $container..." | gum style --foreground 99 - if ! docker pull "$IMAGE" --quiet=false; then - echo "āŒ Failed to pull $IMAGE" | gum style --foreground 196 - exit 1 - fi - echo "------------------------" - done - - echo "Starting containers..." && \ - for container in "${CONTAINERS[@]}"; do - echo "Starting $container..." - sudo systemctl start "docker-$container.service" - done && \ - gum style --foreground 212 "āœ… Containers updated successfully!" + @/etc/self-host-playbook/scripts/update-containers.sh diff --git a/justfiles/tiers/starter.just b/justfiles/tiers/starter.just index e69de29..e286897 100644 --- a/justfiles/tiers/starter.just +++ b/justfiles/tiers/starter.just @@ -0,0 +1,2 @@ +add-custom-service: + @/etc/self-host-playbook/scripts/add-custom-service.sh diff --git a/modules/core.nix b/modules/core.nix index f0fed84..0305d28 100644 --- a/modules/core.nix +++ b/modules/core.nix @@ -82,13 +82,33 @@ }; }; + programs.bash = { + loginShellInit = '' + # Only show the message for interactive login shells + if [[ -t 0 && -t 1 && "$BASH_EXECUTION_STRING" == "" ]]; then + gum style \ + --foreground 212 \ + --border double \ + --margin "1 2" \ + --padding "1 2" \ + --align center \ + --width 70 \ + "🌟 Welcome to Your Self-Host Playbook Server! 🌟" \ + "" \ + "šŸ”§ To manage your server: Run 'shp' (requires sudo)" \ + "" \ + "šŸ’¬ Join our community: https://www.m3tam3re.com" + fi + ''; + }; + environment.etc = { # Main justfile "self-host-playbook/justfile".source = ../justfiles/main.just; # Tier justfiles - "self-host-playbook/tiers/core.just".source = ../justfiles/tiers/core.just; - "self-host-playbook/tiers/starter.just".source = ../justfiles/tiers/starter.just; + "self-host-playbook/tiers".source = ../justfiles/tiers; + "self-host-playbook/scripts".source = ../justfiles/scripts; }; # System state version (do not change) system.stateVersion = "24.11"; diff --git a/services/caddy/default.nix b/services/caddy/default.nix index fca9df7..3598c46 100644 --- a/services/caddy/default.nix +++ b/services/caddy/default.nix @@ -1,41 +1,14 @@ -{jsonConfig, ...}: { +{jsonConfig, ...}: let + # Get all .nix files from the hosts directory + hostFiles = builtins.attrNames (builtins.readDir ./hosts); + # Filter out non-.nix files + hostModules = builtins.filter (n: builtins.match ".*\\.nix" n != null) hostFiles; + # Import each host file and merge them + importHost = file: import ./hosts/${file} {inherit jsonConfig;}; + virtualHosts = builtins.foldl' (acc: file: acc // (importHost file)) {} hostModules; +in { services.caddy = { enable = true; - virtualHosts = { - ${jsonConfig.domains.portainer} = { - extraConfig = '' - reverse_proxy localhost:9000 - header { - # Security headers - Strict-Transport-Security "max-age=31536000; includeSubDomains" - X-Content-Type-Options "nosniff" - X-Frame-Options "DENY" - Referrer-Policy "strict-origin-when-cross-origin" - } - ''; - }; - ${jsonConfig.domains.n8n} = { - extraConfig = '' - reverse_proxy localhost:5678 - header { - Strict-Transport-Security "max-age=31536000; includeSubDomains" - X-Content-Type-Options "nosniff" - X-Frame-Options "DENY" - Referrer-Policy "strict-origin-when-cross-origin" - } - ''; - }; - ${jsonConfig.domains.baserow} = { - extraConfig = '' - reverse_proxy localhost:3000 - header { - Strict-Transport-Security "max-age=31536000; includeSubDomains" - X-Content-Type-Options "nosniff" - X-Frame-Options "DENY" - Referrer-Policy "strict-origin-when-cross-origin" - } - ''; - }; - }; + inherit virtualHosts; }; }