Create for me a script that does the following. The script should run on any nixos machine. For git use REPO_URL="https://gitea.data-pro.nu/henrov/nixos.git" For html use https://gitea.data-pro.nu/henrov/nixos/archive/main.zip This script is really important, my job depends on it # DroidNix Installation — Step Specification ## Step 1 — Collect system identity Store the current Unix username in a variable: `USER=$(whoami)` Store the current hostname in a variable: `HOSTNAME=$(hostname)` ## Step 2 — Create target directory Create the directory `~/Droidnix` if it does not already exist. ## Step 3 — Download the repository Download the contents of `https://gitea.data-pro.nu/henrov/nixos/src/branch/main/Droidnix` into `~/Droidnix` using the following priority: - If `git` is available: `git clone ~/Droidnix` - Otherwise if `wget` is available: download the zip archive and extract it into `~/Droidnix` - Otherwise: use `curl` to download the zip archive and extract it into `~/Droidnix` ## Step 4 — Rename files and folders Perform the following renames recursively under `~/Droidnix`, processing deepest paths first to avoid conflicts: - **4.1** Rename any file or folder whose name contains `traveldroid`, replacing it with `$HOSTNAME` - **4.2** Rename any file or folder whose name contains `henrov`, replacing it with `$USER` ## Step 5 — Replace strings in file contents Perform the following text substitutions: - **5.1** In all files under `~/Droidnix/generated/`, replace every occurrence of `henrov` with `$USER` - **5.2** In `~/Droidnix/[README.org](http://README.org)`, replace every occurrence of `henrov` with `$USER`, but **only within blocks** that begin with the string `** =` and end with a line matching `#+END_SRC`. Leave all text outside these blocks unchanged. - **5.3** In all files under `~/Droidnix/` (recursively, excluding binary files), replace every occurrence of `~/Repos/nixos/Droidnix` with `~/Droidnix` - **5.4.** In all files under `~/Droidnix`, replace every occurrence of `traveldroid` with `$HOSTNAME` - **5.6** In `~/Droidnix/[README.org](http://README.org)`, replace every occurrence of `traveldroid` with `$HOSTNAME`, but **only within blocks** that begin with a line matching `** =` and end with a line matching `#+END_SRC` ## Step 6 — Generate hardware configuration Create the directory `~/Droidnix/generated/hosts/$HOSTNAME/` if it does not already exist. Run the following command and write its output to `~/Droidnix/generated/hosts/$HOSTNAME/hardware-configuration.nix`: ```bash sudo nixos-generate-config --show-hardware-config ``` ## Step 7 — Update [README.org](http://README.org) with generated hardware configuration In `~/Droidnix/[README.org](http://README.org)`, locate the block that begins with exactly this line: ``` #+BEGIN_SRC nix :tangle generated/hosts/$HOSTNAME/hardware-configuration.nix :noweb yes :mkdirp yes :eval never ``` and ends with the next line containing exactly `#+END_SRC`. Replace everything between (but not including) those two boundary lines with the full contents of `~/Droidnix/generated/hosts/$HOSTNAME/hardware-configuration.nix`. ## Step 8 — Build and activate the NixOS configuration Change directory to `~/Droidnix` and run: ```bash sudo nixos-rebuild switch --flake .#$HOSTNAME ``` ## Step 9 — Inform the user Print the following message: ``` Installation complete. Please reboot your system. After rebooting, any changes to your NixOS configuration must be made in ~/Droidnix/[README.org](http://README.org). Before rebuilding, first tangle the org file using: emacs --batch --no-init-file ~/Droidnix/[README.org](http://README.org) \ --eval "(require 'org)" \ --eval "(require 'ob-tangle)" \ --eval "(find-file \"[README.org](http://README.org)\")" \ --eval "(with-temp-message \"\" (org-babel-tangle))" \ --eval "(with-temp-message \"\" (org-html-export-to-html))" Then rebuild with: cd ~/Droidnix && sudo nixos-rebuild switch --flake .#$(hostname) ```