From 6c32412fa35e506cb0445805756f233a327a39df Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Fri, 20 Dec 2024 10:00:01 +0000 Subject: [PATCH] Fix utility script bugs Signed-off-by: Nikolaos Karaolidis --- README.md | 8 ++++---- hosts/common/user/configs/gui/openlens/default.nix | 8 ++++---- hosts/installer/README.md | 12 ++++++++++++ lib/scripts/add-host.sh | 2 +- lib/scripts/install.sh | 11 ++++++----- lib/scripts/remove-host.sh | 2 +- lib/scripts/update-keys.sh | 12 +++++++----- 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5551187..096c122 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ Any `options.nix` files create custom option definitions when present. Below is a table of all hosts, with links to their respective README files, which may provide further details and/or post-installation checklists. -| Host | README | -|-------------|------------------------------------------------------| +| Host | README | +|-------------|----------------------------------------------------------| | `installer` | [hosts/installer/README.md](./hosts/installer/README.md) | -| `eirene` | [hosts/eirene/README.md](./hosts/eirene/README.md) | -| `elara` | [hosts/elara/README.md](./hosts/elara/README.md) | +| `eirene` | [hosts/eirene/README.md](./hosts/eirene/README.md) | +| `elara` | [hosts/elara/README.md](./hosts/elara/README.md) | diff --git a/hosts/common/user/configs/gui/openlens/default.nix b/hosts/common/user/configs/gui/openlens/default.nix index bc096bd..180d5f0 100644 --- a/hosts/common/user/configs/gui/openlens/default.nix +++ b/hosts/common/user/configs/gui/openlens/default.nix @@ -14,10 +14,10 @@ in (pkgs.formats.json { }).generate "lens-user-store.json" { __internal__ = { - migrations = { - version = "6.5.0"; - }; - }; + migrations = { + version = "6.5.0"; + }; + }; preferences = { colorTheme = "system"; diff --git a/hosts/installer/README.md b/hosts/installer/README.md index a24c902..bc7bb8f 100644 --- a/hosts/installer/README.md +++ b/hosts/installer/README.md @@ -1 +1,13 @@ # installer + +I have automated myself out of a job. How to use: + +1. Boot into installer +2. Unlock luks partition +3. Run the following commands: + + ``` + cd /etc/nixos + direnv allow + sudo ./lib/scripts/install.sh + ``` diff --git a/lib/scripts/add-host.sh b/lib/scripts/add-host.sh index 96c0b72..0181fca 100755 --- a/lib/scripts/add-host.sh +++ b/lib/scripts/add-host.sh @@ -17,7 +17,7 @@ ssh-keygen -t ed25519 -f "./hosts/${HOST}/secrets/ssh_host_ed25519_key" -N "" AGE_KEY=$(nix shell nixpkgs#ssh-to-age --command bash -c "cat './hosts/${HOST}/secrets/ssh_host_ed25519_key.pub' | ssh-to-age") -for SOPS_FILE in $(find . -type f -name "sops.yaml"); do +find . -type f -name "sops.yaml" | while IFS= read -r SOPS_FILE; do sed -i "/- hosts:/a\ - &${HOST} ${AGE_KEY}" "${SOPS_FILE}" sed -i "/- age:/a\ - *${HOST}" "${SOPS_FILE}" done diff --git a/lib/scripts/install.sh b/lib/scripts/install.sh index 6b4fe6c..215d6e7 100755 --- a/lib/scripts/install.sh +++ b/lib/scripts/install.sh @@ -59,7 +59,7 @@ setup_wifi() { fi echo "Waiting for a network connection..." - for i in {1..10}; do + for _ in {1..10}; do if ping -c 1 google.com &>/dev/null; then echo "Connected to the network successfully." return @@ -73,8 +73,9 @@ setup_wifi() { select_host() { echo "Available hosts:" - echo $(nix --experimental-features "nix-command flakes" flake show --json | - nix --experimental-features "nix-command flakes" shell nixpkgs#jq --command jq -r '.nixosConfigurations | keys[]') + hosts=$(nix --experimental-features "nix-command flakes" flake show --json \ + | nix --experimental-features "nix-command flakes" shell nixpkgs#jq --command jq -r '.nixosConfigurations | keys[]') + echo "${hosts}" echo "Enter host:" read -r host @@ -120,8 +121,8 @@ copy_config() { read -r copy_config if [[ "${copy_config}" =~ ^([yY][eE][sS]|[yY])$ ]]; then - rm -rf /mnt/etc/nixos - cp -r . /mnt/etc/nixos + rm -rf /mnt/persist/etc/nixos + cp -r . /mnt/persist/etc/nixos echo "Configuration copied successfully." fi } diff --git a/lib/scripts/remove-host.sh b/lib/scripts/remove-host.sh index 7e6d080..2284b71 100755 --- a/lib/scripts/remove-host.sh +++ b/lib/scripts/remove-host.sh @@ -13,7 +13,7 @@ HOST="$1" AGE_KEY=$(nix shell nixpkgs#ssh-to-age --command bash -c "cat './hosts/${HOST}/secrets/ssh_host_ed25519_key.pub' | ssh-to-age") -for SOPS_FILE in $(find . -type f -name "sops.yaml"); do +find . -type f -name "sops.yaml" | while IFS= read -r SOPS_FILE; do sed -i "/ - &${HOST} ${AGE_KEY}/d" "${SOPS_FILE}" sed -i "/ - \*${HOST}/d" "${SOPS_FILE}" done diff --git a/lib/scripts/update-keys.sh b/lib/scripts/update-keys.sh index 24e432a..d9a0c6e 100755 --- a/lib/scripts/update-keys.sh +++ b/lib/scripts/update-keys.sh @@ -11,11 +11,13 @@ fi export SOPS_AGE_KEY_FILE="$1" -for SOPS_FILE in $(find . -type f -name 'sops.yaml'); do +find . -type f -name 'sops.yaml' | while IFS= read -r SOPS_FILE; do dir=$(dirname "${SOPS_FILE}") echo "${dir}" - find "${dir}" -maxdepth 1 -type f -regextype posix-extended -regex '.+\.(yaml|yml|json|env|ini|bin)' | while read -r file; do - echo "${file}" - nix shell nixpkgs#sops --command sops --config "${SOPS_FILE}" updatekeys "${file}" -y - done + find "${dir}" -maxdepth 1 -type f -regextype posix-extended \ + -regex '.+\.(yaml|yml|json|env|ini|bin)' \ + ! -name 'sops.yaml' | while IFS= read -r file; do + echo "${file}" + nix shell nixpkgs#sops --command sops --config "${SOPS_FILE}" updatekeys "${file}" -y + done done