upgrading fwminex too
This commit is contained in:
parent
9cd5d406cf
commit
5a5ffd6f00
2
data.nix
2
data.nix
@ -69,7 +69,7 @@ rec {
|
||||
jakstIP = "100.89.176.5";
|
||||
};
|
||||
"fwminex.motiejus.jakst" = rec {
|
||||
extraHostNames = [jakstIP];
|
||||
extraHostNames = [jakstIP vno1IP];
|
||||
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHlWSZ/H6DR5i5aCrlrEQLVF9MXNvls/pjlLPLaav3f+";
|
||||
jakstIP = "100.89.176.6";
|
||||
vno1IP = "192.168.189.10";
|
||||
|
@ -186,6 +186,12 @@
|
||||
".#vno3-rp3b"
|
||||
".#fra1-a"
|
||||
];
|
||||
deployIfPresent = [
|
||||
{
|
||||
derivationTarget = ".#fwminex";
|
||||
altHostname = myData.hosts."fwminex.motiejus.jakst".vno1IP;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
follower = {
|
||||
|
@ -4,10 +4,37 @@
|
||||
pkgs,
|
||||
myData,
|
||||
...
|
||||
}: {
|
||||
}: let
|
||||
cfg = config.mj.services.deployerbot;
|
||||
mkOptional = {
|
||||
derivationTarget,
|
||||
altHostname,
|
||||
}: ''
|
||||
if ping -c 1 ${altHostname}; then
|
||||
${pkgs.deploy-rs}/bin/deploy \
|
||||
--ssh-opts="-i ''${CREDENTIALS_DIRECTORY}/ssh-key" \
|
||||
--ssh-user=deployerbot-follower \
|
||||
--confirm-timeout 60 \
|
||||
--hostname ${altHostname} \
|
||||
--targets ${derivationTarget} -- \
|
||||
--accept-flake-config
|
||||
fi
|
||||
'';
|
||||
in {
|
||||
options.mj.services.deployerbot.main = with lib.types; {
|
||||
enable = lib.mkEnableOption "Enable system updater orchestrator";
|
||||
deployDerivations = lib.mkOption {type = listOf str;};
|
||||
deployIfPresent = lib.mkOption {
|
||||
type = listOf (submodule (
|
||||
{...}: {
|
||||
options = {
|
||||
derivationTarget = lib.mkOption {type = str;};
|
||||
altHostname = lib.mkOption {type = str;};
|
||||
};
|
||||
}
|
||||
));
|
||||
default = [];
|
||||
};
|
||||
uidgid = lib.mkOption {type = int;};
|
||||
repo = lib.mkOption {type = str;};
|
||||
};
|
||||
@ -19,8 +46,7 @@
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
(with config.mj.services.deployerbot.main;
|
||||
lib.mkIf enable {
|
||||
(lib.mkIf cfg.main.enable {
|
||||
# TODO: git config --global user.email bot@jakstys.lt
|
||||
users.users.deployerbot-main = {
|
||||
description = "Deployerbot Main";
|
||||
@ -29,9 +55,9 @@
|
||||
group = "deployerbot-main";
|
||||
isSystemUser = true;
|
||||
createHome = true;
|
||||
uid = uidgid;
|
||||
uid = cfg.main.uidgid;
|
||||
};
|
||||
users.groups.deployerbot-main.gid = uidgid;
|
||||
users.groups.deployerbot-main.gid = cfg.main.uidgid;
|
||||
|
||||
systemd.services.deployerbot = {
|
||||
description = "Update all known systems";
|
||||
@ -45,12 +71,12 @@
|
||||
LoadCredential = ["ssh-key:/etc/ssh/ssh_host_ed25519_key"];
|
||||
};
|
||||
script = let
|
||||
deployDerivationsStr = builtins.concatStringsSep " " deployDerivations;
|
||||
deployDerivationsStr = builtins.concatStringsSep " " cfg.main.deployDerivations;
|
||||
in ''
|
||||
set -x
|
||||
export GIT_SSH_COMMAND="ssh -i ''${CREDENTIALS_DIRECTORY}/ssh-key"
|
||||
if [[ ! -d config ]]; then
|
||||
git clone ${repo} config
|
||||
git clone ${cfg.main.repo} config
|
||||
cd config
|
||||
else
|
||||
cd config
|
||||
@ -67,6 +93,10 @@
|
||||
--targets ${deployDerivationsStr} -- \
|
||||
--accept-flake-config
|
||||
|
||||
# Optional deployments
|
||||
${lib.concatLines (map mkOptional cfg.main.deployIfPresent)}
|
||||
|
||||
# done
|
||||
git push origin main
|
||||
'';
|
||||
};
|
||||
@ -84,8 +114,7 @@
|
||||
|
||||
nix.settings.trusted-users = ["deployerbot-main"];
|
||||
})
|
||||
(with config.mj.services.deployerbot.follower;
|
||||
lib.mkIf enable {
|
||||
(lib.mkIf cfg.follower.enable {
|
||||
users.users = {
|
||||
deployerbot-follower = {
|
||||
description = "Deployerbot Follower";
|
||||
@ -95,13 +124,13 @@
|
||||
extraGroups = ["wheel"];
|
||||
isSystemUser = true;
|
||||
createHome = true;
|
||||
uid = uidgid;
|
||||
uid = cfg.follower.uidgid;
|
||||
openssh.authorizedKeys.keys = let
|
||||
restrictedPubKey = "from=\"${myData.subnets.tailscale.sshPattern}\" " + publicKey;
|
||||
restrictedPubKey = "from=\"${myData.subnets.tailscale.sshPattern}\" " + cfg.follower.publicKey;
|
||||
in [restrictedPubKey];
|
||||
};
|
||||
};
|
||||
users.groups.deployerbot-follower.gid = uidgid;
|
||||
users.groups.deployerbot-follower.gid = cfg.follower.uidgid;
|
||||
nix.settings.trusted-users = ["deployerbot-follower"];
|
||||
})
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user