From e2addeab1a11e6589f56bacec4b045d17f322c19 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sat, 6 Sep 2025 16:08:07 -0700 Subject: move things around --- flake/devshells.nix | 2 +- flake/scripts/common.nix | 29 ++++++++++++++++++++++++ flake/scripts/darwin.nix | 29 ++++++++++++++++++++++++ flake/scripts/default.nix | 15 +++++++++++++ scripts/common.nix | 29 ------------------------ scripts/darwin.nix | 57 ----------------------------------------------- scripts/default.nix | 20 ----------------- scripts/linux.nix | 19 ---------------- 8 files changed, 74 insertions(+), 126 deletions(-) create mode 100644 flake/scripts/common.nix create mode 100644 flake/scripts/darwin.nix create mode 100644 flake/scripts/default.nix delete mode 100644 scripts/common.nix delete mode 100644 scripts/darwin.nix delete mode 100644 scripts/default.nix delete mode 100644 scripts/linux.nix diff --git a/flake/devshells.nix b/flake/devshells.nix index a97dc2b..19f9497 100644 --- a/flake/devshells.nix +++ b/flake/devshells.nix @@ -36,7 +36,7 @@ }; pre-commit-check = mkPreCommitHooks ./.; - scripts = import "${self}/scripts" { + scripts = import "${self}/flake/scripts" { inherit pkgs system diff --git a/flake/scripts/common.nix b/flake/scripts/common.nix new file mode 100644 index 0000000..b8ab82e --- /dev/null +++ b/flake/scripts/common.nix @@ -0,0 +1,29 @@ +{ pkgs }: +[ + (pkgs.writeScriptBin "update-deps" "nix flake update --commit-lock-file") + + (pkgs.writeShellScriptBin "gcloud-auth" '' + set -xeuo pipefail + ${pkgs.google-cloud-sdk}/bin/gcloud auth print-identity-token > /dev/null 2>&1 || \ + ${pkgs.google-cloud-sdk}/bin/gcloud auth login --quiet + ${pkgs.google-cloud-sdk}/bin/gcloud auth application-default print-access-token > /dev/null 2>&1 || \ + ${pkgs.google-cloud-sdk}/bin/gcloud auth application-default login --quiet + '') + + (pkgs.writeShellScriptBin "tf-state-setup" '' + set -xeuo pipefail + ${pkgs.google-cloud-sdk}/bin/gcloud storage buckets describe \ + gs://fcuny-infra-tofu-state \ + --project=fcuny-infra \ + --quiet || \ + + ${pkgs.google-cloud-sdk}/bin/gcloud storage buckets create \ + gs://fcuny-infra-tofu-state \ + --project=fcuny-infra \ + --uniform-bucket-level-access \ + --public-access-prevention \ + --location=us-west1 \ + --default-storage-class=STANDARD \ + --quiet + '') +] diff --git a/flake/scripts/darwin.nix b/flake/scripts/darwin.nix new file mode 100644 index 0000000..abf6eac --- /dev/null +++ b/flake/scripts/darwin.nix @@ -0,0 +1,29 @@ +{ + pkgs, + system, + inputs, +}: +[ + (pkgs.writeScriptBin "nbuild" '' + set -e + echo "> Running darwin-rebuild build..." + ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild build --flake . + echo "> darwin-rebuild build was successful ✅" + '') + + (pkgs.writeScriptBin "nswitch" '' + set -e + echo "> Running darwin-rebuild switch..." + ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild switch --flake . + echo "> macOS config was successfully applied 🚀" + '') + + (pkgs.writeScriptBin "sync-agenix-key" '' + set -e + echo "> Copying agenix SSH key from 1password ..." + mkdir -p ~/.ssh + ${pkgs._1password-cli}/bin/op --account my.1password.com read "op://Private/agenix/private key?ssh-format=openssh" > ~/.ssh/agenix + ${pkgs._1password-cli}/bin/op --account my.1password.com read "op://Private/agenix/public key" > ~/.ssh/agenix.pub + echo "> agenix SSH key copied successfully 🔐" + '') +] diff --git a/flake/scripts/default.nix b/flake/scripts/default.nix new file mode 100644 index 0000000..db6febe --- /dev/null +++ b/flake/scripts/default.nix @@ -0,0 +1,15 @@ +{ + pkgs, + system, + inputs, +}: +let + common = import ./common.nix { inherit pkgs; }; + darwin = import ./darwin.nix { inherit pkgs system inputs; }; +in +{ + common = common; + darwin = if pkgs.lib.hasSuffix "darwin" system then darwin else [ ]; + + all = common ++ (if pkgs.lib.hasSuffix "darwin" system then darwin else [ ]); +} diff --git a/scripts/common.nix b/scripts/common.nix deleted file mode 100644 index b8ab82e..0000000 --- a/scripts/common.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ pkgs }: -[ - (pkgs.writeScriptBin "update-deps" "nix flake update --commit-lock-file") - - (pkgs.writeShellScriptBin "gcloud-auth" '' - set -xeuo pipefail - ${pkgs.google-cloud-sdk}/bin/gcloud auth print-identity-token > /dev/null 2>&1 || \ - ${pkgs.google-cloud-sdk}/bin/gcloud auth login --quiet - ${pkgs.google-cloud-sdk}/bin/gcloud auth application-default print-access-token > /dev/null 2>&1 || \ - ${pkgs.google-cloud-sdk}/bin/gcloud auth application-default login --quiet - '') - - (pkgs.writeShellScriptBin "tf-state-setup" '' - set -xeuo pipefail - ${pkgs.google-cloud-sdk}/bin/gcloud storage buckets describe \ - gs://fcuny-infra-tofu-state \ - --project=fcuny-infra \ - --quiet || \ - - ${pkgs.google-cloud-sdk}/bin/gcloud storage buckets create \ - gs://fcuny-infra-tofu-state \ - --project=fcuny-infra \ - --uniform-bucket-level-access \ - --public-access-prevention \ - --location=us-west1 \ - --default-storage-class=STANDARD \ - --quiet - '') -] diff --git a/scripts/darwin.nix b/scripts/darwin.nix deleted file mode 100644 index c23feb3..0000000 --- a/scripts/darwin.nix +++ /dev/null @@ -1,57 +0,0 @@ -{ - pkgs, - system, - inputs, -}: -[ - (pkgs.writeScriptBin "nbuild" '' - set -e - echo "> Running darwin-rebuild build..." - ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild build --flake . - echo "> darwin-rebuild build was successful ✅" - '') - - (pkgs.writeScriptBin "nswitch" '' - set -e - echo "> Running darwin-rebuild switch..." - ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild switch --flake . - echo "> macOS config was successfully applied 🚀" - '') - - (pkgs.writeScriptBin "build-synology-vm" '' - set -e - echo "> Running nixos-rebuild build ..." - ${pkgs.nixos-rebuild}/bin/nixos-rebuild build --keep-going --flake .#synology-vm --target-host 192.168.1.151 --build-host 192.168.1.151 --fast --use-remote-sudo --use-substitutes - echo "> nixos-rebuild build was successful ✅" - '') - - (pkgs.writeScriptBin "switch-synology-vm" '' - set -e - echo "> Running nixos-rebuild switch ..." - ${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --keep-going --flake .#synology-vm --target-host 192.168.1.151 --build-host 192.168.1.151 --fast --use-remote-sudo --use-substitutes - echo "> nixos config successfully applied 🚀" - '') - - (pkgs.writeScriptBin "build-do-rproxy" '' - set -e - echo "> Running nixos-rebuild build ..." - ${pkgs.nixos-rebuild}/bin/nixos-rebuild build --keep-going --flake .#do-rproxy --target-host 165.232.158.110 --build-host 165.232.158.110 --fast --use-remote-sudo --use-substitutes - echo "> nixos-rebuild build was successful ✅" - '') - - (pkgs.writeScriptBin "switch-do-rproxy" '' - set -e - echo "> Running nixos-rebuild switch ..." - ${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --keep-going --flake .#do-rproxy --target-host 165.232.158.110 --build-host 165.232.158.110 --fast --use-remote-sudo --use-substitutes - echo "> nixos config successfully applied 🚀" - '') - - (pkgs.writeScriptBin "sync-agenix-key" '' - set -e - echo "> Copying agenix SSH key from 1password ..." - mkdir -p ~/.ssh - ${pkgs._1password-cli}/bin/op --account my.1password.com read "op://Private/agenix/private key?ssh-format=openssh" > ~/.ssh/agenix - ${pkgs._1password-cli}/bin/op --account my.1password.com read "op://Private/agenix/public key" > ~/.ssh/agenix.pub - echo "> agenix SSH key copied successfully 🔐" - '') -] diff --git a/scripts/default.nix b/scripts/default.nix deleted file mode 100644 index 90851df..0000000 --- a/scripts/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ - pkgs, - system, - inputs, -}: -let - common = import ./common.nix { inherit pkgs; }; - darwin = import ./darwin.nix { inherit pkgs system inputs; }; - linux = import ./linux.nix { inherit pkgs system inputs; }; -in -{ - common = common; - darwin = if pkgs.lib.hasSuffix "darwin" system then darwin else [ ]; - linux = if pkgs.lib.hasSuffix "linux" system then linux else [ ]; - - all = - common - ++ (if pkgs.lib.hasSuffix "darwin" system then darwin else [ ]) - ++ (if pkgs.lib.hasSuffix "linux" system then linux else [ ]); -} diff --git a/scripts/linux.nix b/scripts/linux.nix deleted file mode 100644 index b44c86f..0000000 --- a/scripts/linux.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ - pkgs, -}: -[ - (pkgs.writeScriptBin "nbuild" '' - set -e - echo "> Running nixos-rebuild build..." - sudo nixos-rebuild build --flake . - echo "> nixos-rebuild build was successful ✅" - '') - - (pkgs.writeScriptBin "nswitch" '' - set -e - echo "> Running nixos-rebuild switch..." - sudo nixos-rebuild switch --flake . - echo "> nixos-rebuild switch was successful ✅" - echo "> NixOS config was successfully applied 🚀" - '') -] -- cgit v1.2.3