mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
Massive rework to rebase on hexchen's new nixfiles deploy stuffs.
This commit is contained in:
parent
6eac632061
commit
f2eb255ba5
62 changed files with 990 additions and 846 deletions
|
|
@ -1,74 +1,18 @@
|
|||
let
|
||||
pkgs = import <nixpkgs> { };
|
||||
lib = pkgs.lib;
|
||||
{ pkgs, hosts, profiles }:
|
||||
|
||||
hosts = import ../configuration/hosts;
|
||||
nixosHosts = lib.filterAttrs (name: host: host ? ssh) hosts;
|
||||
with pkgs.lib;
|
||||
|
||||
allGroups = lib.unique
|
||||
(lib.flatten (lib.mapAttrsToList (name: host: host.groups) hosts));
|
||||
|
||||
hostsInGroup = group:
|
||||
lib.filterAttrs (k: v: builtins.elem group v.groups) hosts;
|
||||
|
||||
hostsInAllGroups = lib.listToAttrs
|
||||
(map (group: lib.nameValuePair group (lib.attrNames (hostsInGroup group)))
|
||||
allGroups);
|
||||
|
||||
mkDeploy = hostnames:
|
||||
pkgs.writeScript "deploy-${lib.concatStringsSep "-" hostnames}" ''
|
||||
#!${pkgs.stdenv.shell}
|
||||
set -e -o pipefail
|
||||
export PATH=/run/wrappers/bin/:${
|
||||
with pkgs;
|
||||
lib.makeBinPath [
|
||||
coreutils
|
||||
openssh
|
||||
nix
|
||||
gnutar
|
||||
findutils
|
||||
nettools
|
||||
gzip
|
||||
git
|
||||
]
|
||||
}
|
||||
|
||||
MODE=$1
|
||||
shift || true
|
||||
ARGS=$@
|
||||
|
||||
[ "$MODE" == "" ] && MODE="switch"
|
||||
|
||||
${lib.concatMapStrings (hostname:
|
||||
let
|
||||
hostAttrs = nixosHosts.${hostname};
|
||||
nixosSystem = (import <nixpkgs/nixos/lib/eval-config.nix> {
|
||||
modules = [
|
||||
"${toString ../configuration}/hosts/${hostname}/configuration.nix"
|
||||
];
|
||||
system =
|
||||
if hostAttrs ? system then hostAttrs.system else "x86_64-linux";
|
||||
}).config.system.build.toplevel;
|
||||
in ''
|
||||
(
|
||||
echo "deploying ${hostname}..."
|
||||
nix copy --no-check-sigs --to ssh://${hostAttrs.ssh.host} ${nixosSystem}
|
||||
ssh $NIX_SSHOPTS ${hostAttrs.ssh.host} "sudo nix-env -p /nix/var/nix/profiles/system -i ${nixosSystem}"
|
||||
ssh $NIX_SSHOPTS ${hostAttrs.ssh.host} "sudo /nix/var/nix/profiles/system/bin/switch-to-configuration $MODE"
|
||||
) &
|
||||
PID_LIST+=" $!"
|
||||
'') hostnames}
|
||||
|
||||
echo "deploys started, waiting for them to finish..."
|
||||
|
||||
trap "kill $PID_LIST" SIGINT
|
||||
wait $PID_LIST
|
||||
'';
|
||||
|
||||
in {
|
||||
deploy =
|
||||
(lib.mapAttrs (hostname: hostAttrs: mkDeploy [ hostname ]) nixosHosts)
|
||||
// (lib.mapAttrs (group: hosts: mkDeploy hosts) hostsInAllGroups) // {
|
||||
all = mkDeploy (lib.attrNames nixosHosts);
|
||||
};
|
||||
}
|
||||
(mapAttrs (name: hosts:
|
||||
pkgs.writeScript "deploy-profile-${name}" ''
|
||||
#!${pkgs.runtimeShell}
|
||||
export PATH=
|
||||
${concatMapStrings (host: ''
|
||||
echo "deploying ${host.config.networking.hostName}..."
|
||||
${host.config.system.build.deployScript} $1 &
|
||||
PID_LIST+=" $!"
|
||||
'') hosts}
|
||||
# FIXME: remove jobs from PIDLIST once they finish
|
||||
trap "kill $PID_LIST" SIGINT
|
||||
wait $PID_LIST
|
||||
'') profiles)
|
||||
// (mapAttrs (name: host: host.config.system.build.deployScript) hosts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue