44 lines
1.6 KiB
Nix
44 lines
1.6 KiB
Nix
{
|
|
flakeInputs,
|
|
platform,
|
|
site,
|
|
}:
|
|
let
|
|
pkgs = flakeInputs.nixpkgs.legacyPackages.${platform};
|
|
lib = pkgs.lib;
|
|
mkDeploy = { site, targetPkg, profileName, extraCommands ? "" }: pkgs.substituteAll {
|
|
name = "deploy-${profileName}";
|
|
dir = "bin";
|
|
src = builtins.toFile "deploy-template" ''
|
|
#!@runtimeShell@
|
|
set -ex
|
|
nix-copy-closure --to @site@ @targetPkg@
|
|
ssh @site@ sudo nix-env --set -p /nix/var/nix/profiles/@profileName@ @targetPkg@
|
|
@extraCommands@
|
|
'';
|
|
env = {
|
|
inherit site targetPkg profileName extraCommands;
|
|
inherit (pkgs) runtimeShell;
|
|
};
|
|
isExecutable = true;
|
|
passthru.site = site;
|
|
};
|
|
deployments = builtins.map mkDeploy [
|
|
{
|
|
profileName = "blog-rhelmot-io";
|
|
site = "sunflower";
|
|
targetPkg = flakeInputs."blog-rhelmot-io".packages.${platform}.blog;
|
|
}
|
|
];
|
|
filteredDeployments = builtins.filter (deployment: deployment.site == site) deployments;
|
|
filteredDeploymentsAttrs = builtins.listToAttrs (builtins.map (value: { name = value.profileName; inherit value; }) filteredDeployments);
|
|
targetSystem = flakeInputs.self.packages.${platform}.${site}.system;
|
|
deployAll = pkgs.writeShellScriptBin "deploy-all-${site}" (''
|
|
set -ex
|
|
# TODO take advantage of the nixos-rebuild infrastructure
|
|
nix-copy-closure --to ${site} ${targetSystem}
|
|
ssh ${site} 'sudo nix-env --set -p /nix/var/nix/profiles/system ${targetSystem} && sudo ${targetSystem}/bin/switch-to-configuration switch'
|
|
set +e
|
|
'' + lib.concatStringsSep "\n" filteredDeployments);
|
|
in deployAll // filteredDeploymentsAttrs
|