Skip to content

Commit

Permalink
33 papercuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Enzime committed Dec 7, 2024
1 parent 16996ba commit b7f95dd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Added `deploy-<hostname>` 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`
Expand Down
49 changes: 49 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,55 @@
in lib.mapAttrs' (hostname: configuration:
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; };
Expand Down

0 comments on commit b7f95dd

Please sign in to comment.