krops: udpate shell to make it more powerful

This commit is contained in:
Ingolf Wagner 2020-03-06 14:10:55 +08:00
parent 95da0e6bb2
commit 79524242dc
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B

View file

@ -124,33 +124,48 @@ let
hostPattern = name:
if name == "porani" then "${name}.insecure" else "${name}.private";
deployment = populateCommands: name:
deployment = { secrets, content }:
name:
{ host ? (hostPattern name), target ? "/var/src/", user ? "root"
, commandPrefix ? "deploy", enableSwitch ? true }:
, commandPrefix ? "deploy", enableSwitch ? true, enableSecrets ? true }:
with ops;
jobs "${commandPrefix}-${name}" "${user}@${host}${target}"
(populateCommands ++ (if enableSwitch then [ switch ] else [ ]));
let
commandName = if enableSecrets then
"${commandPrefix}-${name}-with-secrets"
else
"${commandPrefix}-${name}-without-secrets";
populateCommands = with lib; flatten [
content
(optionals enableSecrets secrets)
(optionals enableSwitch [ switch ])
];
in jobs commandName "${user}@${host}${target}" populateCommands;
serverDeployment = name:
with ops;
deployment [
deployment {
content = [
(populate source.nixPkgs)
(populate source.modules)
(populate (source.secrets name))
(populate (source.system name))
] name;
];
secrets = [ (populate (source.secrets name)) ];
} name;
desktopDeployment = name:
with ops;
deployment [
deployment {
content = [
(populate source.nixPkgs)
(populate source.modules)
(populate (source.secrets name))
(populate (source.system name))
(populate source.desktopSecrets)
] name;
];
secrets =
[ (populate (source.secrets name)) (populate source.desktopSecrets) ];
} name;
cleanupNix = name:
{ ... }:
let
target = {
host = hostPattern name;
@ -165,40 +180,45 @@ let
nix-collect-garbage -d
'';
# generate tasks
# helper function to make stuff more readable
runForAll = serverList: command: arguments:
let f = args: (map (name: command name (arguments // args)) serverList);
in (f { enableSecrets = false; }) ++ (f { enableSecrets = true; });
servers = with lib;
# generate tasks
servers = serverList:
with lib;
let
serverList = [ "workhorse" "sputnik" "porani" ];
deployments = flip map serverList (name: serverDeployment name { });
cleanup = flip map serverList (name: cleanupNix name);
install = flip map serverList (name:
serverDeployment name {
doForAll = runForAll serverList;
deployments = doForAll serverDeployment { };
cleanup = doForAll cleanupNix { };
install = doForAll serverDeployment {
commandPrefix = "install";
host = installHost;
target = "/mnt/var/src";
enableSwitch = false;
});
};
in deployments ++ cleanup ++ install;
desktops = with lib;
desktops = desktopList:
with lib;
let
desktopList = [ "pepe" "workout" "sterni" "mobi" ];
deployments = flip map desktopList (name: desktopDeployment name { });
cleanup = flip map desktopList (name: cleanupNix name);
install = flip map desktopList (name:
desktopDeployment name {
doForAll = runForAll desktopList;
deployments = doForAll desktopDeployment { };
cleanup = doForAll cleanupNix { };
install = doForAll desktopDeployment {
commandPrefix = "install";
host = installHost;
target = "/mnt/var/src";
enableSwitch = false;
});
};
in deployments ++ cleanup ++ install;
in pkgs.mkShell {
buildInputs = with pkgs;
servers ++ desktops ++ [
(servers [ "workhorse" "sputnik" "porani" ])
++ (desktops [ "pepe" "workout" "sterni" "mobi" ]) ++ [
(pkgs.writers.writeBashBin "reformat" ''
find ${
toString ./.