Flatten apps (nixinate-name instead nixinate.name) (#50)

- Solves #12

Reviewed-on: #50
Co-authored-by: Tristan Druyen <tristan@vault81.de>
Co-committed-by: Tristan Druyen <tristan@vault81.de>
This commit is contained in:
Tristan D. 2023-12-11 21:03:59 +01:00
parent a53e5eb676
commit 1efac43f15
Signed by: tristan
SSH key fingerprint: SHA256:U7y6eMb7CQDaTHv9XoX6/BaQnPqyxxKc+Xnfcefi6rY
3 changed files with 28 additions and 29 deletions

View file

@ -8,6 +8,7 @@
> Changes so far: > Changes so far:
> - Merged a helpful PR for ssh config hostnames https://git.vlt81.de/tristan/nixinate/pulls/49 > - Merged a helpful PR for ssh config hostnames https://git.vlt81.de/tristan/nixinate/pulls/49
> - Fixed nix run on non-posix compliant shells like fish by explicitly adding a bash shim to the script > - Fixed nix run on non-posix compliant shells like fish by explicitly adding a bash shim to the script
> - Solved https://git.vlt81.de/tristan/nixinate/issues/12 by renaming apps from `nixinate.{$machine_name}` to `nixinate-${machine_name]}`
> >
> PR's welcome :) > PR's welcome :)
@ -75,12 +76,12 @@ git+file:///etc/nixos
└───myMachine: NixOS configuration └───myMachine: NixOS configuration
``` ```
To finally execute the deployment script, use `nix run .#apps.nixinate.myMachine` To finally execute the deployment script, use `nix run .#apps.nixinate-myMachine`
#### Example Run #### Example Run
``` ```
[root@myMachine:/etc/nixos]# nix run .#apps.nixinate.myMachine [root@myMachine:/etc/nixos]# nix run .#apps.nixinate-myMachine
🚀 Deploying nixosConfigurations.myMachine from /nix/store/279p8aaclmng8kc3mdmrmi6q3n76r1i7-source 🚀 Deploying nixosConfigurations.myMachine from /nix/store/279p8aaclmng8kc3mdmrmi6q3n76r1i7-source
👤 SSH User: matthew 👤 SSH User: matthew
🌐 SSH Host: itchy.scratchy.com 🌐 SSH Host: itchy.scratchy.com

View file

@ -118,33 +118,31 @@
in in
final.writeScript "deploy-${machine}.sh" script; final.writeScript "deploy-${machine}.sh" script;
in in
{ (
nixinate = (
nixpkgs.lib.genAttrs nixpkgs.lib.genAttrs
validMachines (map (a: "nixinate-" + a) validMachines)
( (
x: { x: {
type = "app"; type = "app";
program = toString (mkDeployScript { program = toString (mkDeployScript {
machine = x; machine = nixpkgs.lib.removePrefix "nixinate-" x;
dryRun = false; dryRun = false;
}); });
} }
) )
// nixpkgs.lib.genAttrs // nixpkgs.lib.genAttrs
(map (a: a + "-dry-run") validMachines) (map (a: "nixinate-" + a + "-dry-run") validMachines)
( (
x: { x: {
type = "app"; type = "app";
program = toString (mkDeployScript { program = toString (mkDeployScript {
machine = nixpkgs.lib.removeSuffix "-dry-run" x; machine = nixpkgs.lib.removeSuffix "-dry-run" (nixpkgs.lib.removePrefix "nixinate-" x);
dryRun = true; dryRun = true;
}); });
} }
) )
); );
}; };
};
nixinate = forAllSystems (system: pkgs: nixpkgsFor.${system}.generateApps); nixinate = forAllSystems (system: pkgs: nixpkgsFor.${system}.generateApps);
checks = forAllSystems ( checks = forAllSystems (
system: pkgs: system: pkgs:

View file

@ -106,7 +106,7 @@ let
nixinator.wait_for_unit("multi-user.target") nixinator.wait_for_unit("multi-user.target")
nixinator.succeed("mkdir ~/.ssh/") nixinator.succeed("mkdir ~/.ssh/")
nixinator.succeed("ssh-keyscan -H nixinatee >> ~/.ssh/known_hosts") nixinator.succeed("ssh-keyscan -H nixinatee >> ~/.ssh/known_hosts")
nixinator.succeed("exec ${deployScript.nixinate.nixinatee.program} >&2") nixinator.succeed("exec ${deployScript.nixinate-nixinatee.program} >&2")
nixinatee.wait_for_unit("nginx.service") nixinatee.wait_for_unit("nginx.service")
nixinatee.wait_for_open_port("80") nixinatee.wait_for_open_port("80")
with subtest("Check that Nginx webserver can be reached by deployer after deployment"): with subtest("Check that Nginx webserver can be reached by deployer after deployment"):