krops: udpate shell to make it more powerful
This commit is contained in:
parent
95da0e6bb2
commit
79524242dc
1 changed files with 61 additions and 41 deletions
74
shell.nix
74
shell.nix
|
@ -124,33 +124,48 @@ let
|
||||||
hostPattern = name:
|
hostPattern = name:
|
||||||
if name == "porani" then "${name}.insecure" else "${name}.private";
|
if name == "porani" then "${name}.insecure" else "${name}.private";
|
||||||
|
|
||||||
deployment = populateCommands: name:
|
deployment = { secrets, content }:
|
||||||
|
name:
|
||||||
{ host ? (hostPattern name), target ? "/var/src/", user ? "root"
|
{ host ? (hostPattern name), target ? "/var/src/", user ? "root"
|
||||||
, commandPrefix ? "deploy", enableSwitch ? true }:
|
, commandPrefix ? "deploy", enableSwitch ? true, enableSecrets ? true }:
|
||||||
with ops;
|
with ops;
|
||||||
jobs "${commandPrefix}-${name}" "${user}@${host}${target}"
|
let
|
||||||
(populateCommands ++ (if enableSwitch then [ switch ] else [ ]));
|
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:
|
serverDeployment = name:
|
||||||
with ops;
|
with ops;
|
||||||
deployment [
|
deployment {
|
||||||
|
content = [
|
||||||
(populate source.nixPkgs)
|
(populate source.nixPkgs)
|
||||||
(populate source.modules)
|
(populate source.modules)
|
||||||
(populate (source.secrets name))
|
|
||||||
(populate (source.system name))
|
(populate (source.system name))
|
||||||
] name;
|
];
|
||||||
|
secrets = [ (populate (source.secrets name)) ];
|
||||||
|
} name;
|
||||||
|
|
||||||
desktopDeployment = name:
|
desktopDeployment = name:
|
||||||
with ops;
|
with ops;
|
||||||
deployment [
|
deployment {
|
||||||
|
content = [
|
||||||
(populate source.nixPkgs)
|
(populate source.nixPkgs)
|
||||||
(populate source.modules)
|
(populate source.modules)
|
||||||
(populate (source.secrets name))
|
|
||||||
(populate (source.system name))
|
(populate (source.system name))
|
||||||
(populate source.desktopSecrets)
|
];
|
||||||
] name;
|
secrets =
|
||||||
|
[ (populate (source.secrets name)) (populate source.desktopSecrets) ];
|
||||||
|
} name;
|
||||||
|
|
||||||
cleanupNix = name:
|
cleanupNix = name:
|
||||||
|
{ ... }:
|
||||||
let
|
let
|
||||||
target = {
|
target = {
|
||||||
host = hostPattern name;
|
host = hostPattern name;
|
||||||
|
@ -165,40 +180,45 @@ let
|
||||||
nix-collect-garbage -d
|
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
|
let
|
||||||
serverList = [ "workhorse" "sputnik" "porani" ];
|
doForAll = runForAll serverList;
|
||||||
deployments = flip map serverList (name: serverDeployment name { });
|
deployments = doForAll serverDeployment { };
|
||||||
cleanup = flip map serverList (name: cleanupNix name);
|
cleanup = doForAll cleanupNix { };
|
||||||
install = flip map serverList (name:
|
install = doForAll serverDeployment {
|
||||||
serverDeployment name {
|
|
||||||
commandPrefix = "install";
|
commandPrefix = "install";
|
||||||
host = installHost;
|
host = installHost;
|
||||||
target = "/mnt/var/src";
|
target = "/mnt/var/src";
|
||||||
enableSwitch = false;
|
enableSwitch = false;
|
||||||
});
|
};
|
||||||
in deployments ++ cleanup ++ install;
|
in deployments ++ cleanup ++ install;
|
||||||
|
|
||||||
desktops = with lib;
|
desktops = desktopList:
|
||||||
|
with lib;
|
||||||
let
|
let
|
||||||
desktopList = [ "pepe" "workout" "sterni" "mobi" ];
|
doForAll = runForAll desktopList;
|
||||||
deployments = flip map desktopList (name: desktopDeployment name { });
|
deployments = doForAll desktopDeployment { };
|
||||||
cleanup = flip map desktopList (name: cleanupNix name);
|
cleanup = doForAll cleanupNix { };
|
||||||
install = flip map desktopList (name:
|
install = doForAll desktopDeployment {
|
||||||
desktopDeployment name {
|
|
||||||
commandPrefix = "install";
|
commandPrefix = "install";
|
||||||
host = installHost;
|
host = installHost;
|
||||||
target = "/mnt/var/src";
|
target = "/mnt/var/src";
|
||||||
enableSwitch = false;
|
enableSwitch = false;
|
||||||
});
|
};
|
||||||
in deployments ++ cleanup ++ install;
|
in deployments ++ cleanup ++ install;
|
||||||
|
|
||||||
in pkgs.mkShell {
|
in pkgs.mkShell {
|
||||||
|
|
||||||
buildInputs = with pkgs;
|
buildInputs = with pkgs;
|
||||||
servers ++ desktops ++ [
|
(servers [ "workhorse" "sputnik" "porani" ])
|
||||||
|
++ (desktops [ "pepe" "workout" "sterni" "mobi" ]) ++ [
|
||||||
(pkgs.writers.writeBashBin "reformat" ''
|
(pkgs.writers.writeBashBin "reformat" ''
|
||||||
find ${
|
find ${
|
||||||
toString ./.
|
toString ./.
|
||||||
|
|
Loading…
Reference in a new issue