mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 04:19:19 -08:00
shell: HISTFILE, CI, runners
This commit is contained in:
parent
ea449f61f9
commit
4e775b6691
5 changed files with 68 additions and 16 deletions
|
|
@ -15,7 +15,9 @@ rec {
|
|||
})
|
||||
hosts targets;
|
||||
|
||||
inherit (pkgs) lib;
|
||||
inherit (pkgs) lib;
|
||||
|
||||
runners = import ./runners.nix { inherit lib; inherit (deploy) target; };
|
||||
|
||||
deploy = import ./lib/deploy.nix {
|
||||
inherit pkgs sources;
|
||||
|
|
|
|||
|
|
@ -5,24 +5,30 @@ with pkgs.lib;
|
|||
let
|
||||
pkgsModule = { ... }: { config._module.args = { pkgs = mkDefault pkgs; }; };
|
||||
|
||||
configExtension = { ... }: {
|
||||
options.terraform.baseDir = mkOption {
|
||||
type = types.path;
|
||||
};
|
||||
};
|
||||
|
||||
tfEval = config:
|
||||
(evalModules {
|
||||
modules = [ pkgsModule (sources.tf-nix + "/modules") ] ++ toList config;
|
||||
modules = [ pkgsModule (sources.tf-nix + "/modules") configExtension ] ++ toList config;
|
||||
specialArgs = { inherit hosts; };
|
||||
}).config;
|
||||
|
||||
tf = { targetName, target }:
|
||||
tf = { targetName ? null, target ? [] }:
|
||||
tfEval ({ config, ... }: {
|
||||
imports = optional (builtins.pathExists ../trusted/tf) (import ../trusted/tf/meta.nix)
|
||||
++ map (hostName: ../hosts + "/${hostName}/meta.nix") target ++ [{
|
||||
++ flatten (map (hostName: optional (builtins.pathExists (../hosts + "/${hostName}/meta.nix")) (../hosts + "/${hostName}/meta.nix")) target) ++ [{
|
||||
config = mkMerge (map
|
||||
(hostName:
|
||||
mapAttrs (_: mkMerge) hosts.${hostName}.config.deploy.tf.out.set)
|
||||
target);
|
||||
}] ++ optional
|
||||
(builtins.pathExists (../trusted/targets + "/${targetName}"))
|
||||
(targetName != null && builtins.pathExists (../trusted/targets + "/${targetName}"))
|
||||
(../trusted/targets + "/${targetName}")
|
||||
++ optional (builtins.pathExists (../targets + "/${targetName}"))
|
||||
++ optional (targetName != null && builtins.pathExists (../targets + "/${targetName}"))
|
||||
(../targets + "/${targetName}") ++ concatMap
|
||||
(hostName:
|
||||
filter builtins.pathExists
|
||||
|
|
@ -35,12 +41,17 @@ let
|
|||
enable = true;
|
||||
};
|
||||
|
||||
runners.lazy = {
|
||||
file = ../.;
|
||||
args = [ "--show-trace" ];
|
||||
attrPrefix =
|
||||
let attr = if target != null then "target.${targetName}" else "tf";
|
||||
in "deploy.${attr}.runners.run.";
|
||||
runners = {
|
||||
lazy = {
|
||||
file = ../.;
|
||||
args = [ "--show-trace" ];
|
||||
attrPrefix =
|
||||
let attr = if targetName != null then "target.${targetName}" else "tf";
|
||||
in "deploy.${attr}.runners.run.";
|
||||
};
|
||||
run = {
|
||||
apply.name = if targetName != null then "${targetName}-apply" else "tf-apply";
|
||||
};
|
||||
};
|
||||
|
||||
variables.hcloud_token = {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ rec {
|
|||
}))
|
||||
hostNames);
|
||||
|
||||
targets = foldAttrs (host: hosts: [ host ] ++ hosts) [ ] (mapAttrsToList
|
||||
targets = filterAttrs (targetName: _: targetName != "") (foldAttrs (host: hosts: [ host ] ++ hosts) [ ] (mapAttrsToList
|
||||
(hostName: host: { ${host.config.deploy.target} = hostName; })
|
||||
hosts);
|
||||
hosts));
|
||||
}
|
||||
|
|
|
|||
16
runners.nix
Normal file
16
runners.nix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{ lib, target }:
|
||||
|
||||
with lib;
|
||||
|
||||
# targets -> targetName list of hosts
|
||||
|
||||
let
|
||||
runners = {
|
||||
run = foldAttrList (mapAttrsToList (targetName: targetx: mapAttrs' (k: run:
|
||||
nameValuePair run.name run.set
|
||||
) targetx.runners.run) target);
|
||||
lazy.run = foldAttrList (mapAttrsToList (targetName: targetx: mapAttrs' (k: run:
|
||||
nameValuePair run.name run.set
|
||||
) targetx.runners.lazy.run) target);
|
||||
lazy.nativeBuildInputs = concatLists (mapAttrsToList (targetName: target: target.runners.lazy.nativeBuildInputs) target);
|
||||
}; in runners
|
||||
27
shell.nix
27
shell.nix
|
|
@ -1,7 +1,30 @@
|
|||
with (import <nixpkgs> { });
|
||||
{ }: let
|
||||
config = import ./default.nix;
|
||||
tf = config.deploy.tf {};
|
||||
inherit (config) pkgs;
|
||||
in pkgs.mkShell {
|
||||
nativeBuildInputs = config.runners.lazy.nativeBuildInputs;
|
||||
HISTFILE = toString (tf.terraform.baseDir + "/.history");
|
||||
|
||||
CI_ROOT = toString ./.;
|
||||
CI_CONFIG_ROOT = toString ./ci;
|
||||
#CI_CONFIG = toString ./example/ci.nix
|
||||
CI_PLATFORM = "impure"; # use host's nixpkgs for more convenient testing
|
||||
|
||||
mkShell {
|
||||
shellHook = ''
|
||||
export HOME_HOSTNAME=$(hostname -s)
|
||||
export NIX_PATH="$NIX_PATH:nixfiles=${toString ./.}"
|
||||
|
||||
CI_CONFIG_FILES=($CI_CONFIG_ROOT/hosts.nix)
|
||||
gh-actions-generate() {
|
||||
for f in "''${CI_CONFIG_FILES[@]}"; do
|
||||
nix run --arg config $f ci.run.gh-actions-generate
|
||||
done
|
||||
}
|
||||
test-all() {
|
||||
for f in "''${CI_CONFIG_FILES[@]}"; do
|
||||
nix run --arg config $f ci.test || break
|
||||
done
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue