From 0a5b2ab646244c7fec1f54296ad11774461eca05 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sat, 7 Dec 2024 14:48:14 +1100 Subject: [PATCH] 33 papercuts --- CHANGELOG.md | 1 + flake.nix | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b500852..4e4d695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- Added `deploy-` packages for remotely deploying macOS machines - Use Microsoft's Python VSCode extension for Python IDE functionality - Use `gitlens.remotes` to support `git.clan.lol` - Added signing key for `hermes-macos` and `hermes-linux-builder` diff --git a/flake.nix b/flake.nix index fb8df68..7e15b8e 100644 --- a/flake.nix +++ b/flake.nix @@ -465,6 +465,61 @@ lib.nameValuePair "${hostname}-vm" (vmWithNewHostPlatform hostname)) self.nixosConfigurations; } + { + packages = let + deploy = hostname: configuration: + pkgs.writeShellApplication { + name = "deploy-${hostname}-from-${system}"; + runtimeInputs = builtins.attrValues { inherit (pkgs) jq; }; + text = let + cfg = configuration.config; + + user = configuration._module.specialArgs.user; + dest = configuration._module.specialArgs.hostname; + darwin-rebuild = cfg.system.build.darwin-rebuild; + in '' + flags=() + overriddenInputs=() + + while [ $# -gt 0 ]; do + flag=$1; shift 1 + if [[ $flag == "--override-input" ]]; then + arg1=$1; shift 1 + arg2=$1; shift 1 + resolved=$(nix flake metadata "$arg2" --json | jq -r '.path') + flags+=("--override-input" "$arg1" "$resolved") + overriddenInputs+=("$resolved") + fi + done + + if [[ $(hostname) != "${hostname}" || $USER != "${user}" ]]; then + nix copy --to ssh-ng://root@${dest} ${ + ./. + } "''${overriddenInputs[@]}" + ssh -t ${user}@${dest} nix run \ + ${ + ./. + }#darwinConfigurations.${hostname}.config.system.build.darwin-rebuild \ + "''${flags[@]}" \ + switch \ + -- \ + --flake ${./.} \ + "''${flags[@]}" + + ${lib.optionalString + (system == configuration.pkgs.hostPlatform.system) '' + else + ${lib.getExe darwin-rebuild} switch --flake ${ + ./. + } "''${flags[@]}" + ''} + fi + ''; + }; + in lib.mapAttrs' (hostname: configuration: + lib.nameValuePair "deploy-${hostname}" + (deploy hostname configuration)) self.darwinConfigurations; + } ]; flake = { keys = import ./keys.nix; }; });