diff --git a/.gitignore b/.gitignore index bea7366..bc15009 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,10 @@ lnbits-extensions # Copy example-krops.nix to krops.nix and customize krops.nix +# User-specific build configuration +# Copy example-build-local.nix to build-local.nix and customize +build-local.nix + # Machine-specific configurations (user creates these) # Keep example-machine as a template config/machines/* diff --git a/DEPLOYMENT-GUIDE.md b/DEPLOYMENT-GUIDE.md index 94aab0e..a290300 100644 --- a/DEPLOYMENT-GUIDE.md +++ b/DEPLOYMENT-GUIDE.md @@ -11,11 +11,12 @@ This setup builds the web-app **locally** with machine-specific configuration, t When you first clone this repository, you need to set up your local configuration: -### 1. Create your krops.nix +### 1. Create your configuration files ```bash -# Copy the example template +# Copy the example templates cp example-krops.nix krops.nix +cp example-build-local.nix build-local.nix ``` ### 2. Create your first machine configuration @@ -29,20 +30,38 @@ cp -r config/machines/example-machine config/machines/my-machine # - Add your hardware-configuration.nix (from nixos-generate-config) ``` -### 3. Update krops.nix +### 3. Create machine-specific web-app assets (if deploying web-app) -Edit `krops.nix` and: +```bash +mkdir -p machine-specific/my-machine/env +mkdir -p machine-specific/my-machine/images + +# Add your .env file and images +# See machine-specific/example-machine/ for reference +``` + +### 4. Update krops.nix and build-local.nix + +**In `krops.nix`:** - Replace `example-machine` with your machine name - Update the SSH target (`root@your-host`) - Add to the `inherit` list and `all` script -### 4. Deploy! +**In `build-local.nix`:** +- Replace `example-machine` with your machine name +- Add to the `all` build script + +### 5. Build and deploy! ```bash +# Build web-app locally (if using web-app) +nix-build ./build-local.nix -A my-machine && ./result/bin/build-my-machine + +# Deploy to target machine nix-build ./krops.nix -A my-machine && ./result ``` -**Note:** Your `krops.nix` and machine configs in `config/machines/*` are gitignored. You can safely pull updates without overwriting your local configuration. +**Note:** Your `krops.nix`, `build-local.nix`, and machine configs in `config/machines/*` are gitignored. You can safely pull updates without overwriting your local configuration. ## Structure diff --git a/example-build-local.nix b/example-build-local.nix new file mode 100644 index 0000000..c268808 --- /dev/null +++ b/example-build-local.nix @@ -0,0 +1,59 @@ +let + pkgs = import {}; + + # Build script for a specific machine + buildForMachine = name: pkgs.writeShellScriptBin "build-${name}" '' + set -e + + BUILD_DIR="./build/${name}" + + echo "Building web-app for ${name}..." + + # Clean and create build directory + rm -rf "$BUILD_DIR" + mkdir -p "$BUILD_DIR" + + # Copy web-app source + cp -r ./web-app/* "$BUILD_DIR/" + + # Copy machine-specific .env + echo "Copying machine-specific .env..." + cp ./machine-specific/${name}/env/.env "$BUILD_DIR/.env" + + # Copy machine-specific images to public folder + echo "Copying machine-specific images to public..." + cp -r ./machine-specific/${name}/images/* "$BUILD_DIR/public/" + + # Copy machine-specific logo to assets + echo "Copying machine-specific logo to assets..." + mkdir -p "$BUILD_DIR/src/assets" + cp ./machine-specific/${name}/images/logo.png "$BUILD_DIR/src/assets/logo.png" + + # Build the web-app + echo "Running build..." + cd "$BUILD_DIR" + ${pkgs.nodejs}/bin/npm run build + + echo "Build complete for ${name}! Output in $BUILD_DIR/dist" + ''; + +in { + # Example machine build (copy this line for each machine) + # Replace "example-machine" with your machine name + example-machine = buildForMachine "example-machine"; + + # Add more machines here: + # machine1 = buildForMachine "machine1"; + # machine2 = buildForMachine "machine2"; + + # Build all machines (update this list with your machines) + all = pkgs.writeShellScriptBin "build-all" '' + set -e + echo "Building for all machines..." + ${(buildForMachine "example-machine")}/bin/build-example-machine + # Add your machines here: + # ${(buildForMachine "machine1")}/bin/build-machine1 + # ${(buildForMachine "machine2")}/bin/build-machine2 + echo "All builds complete!" + ''; +}