shell: HISTFILE, CI, runners

This commit is contained in:
kat witch 2021-05-15 00:50:24 +01:00
parent ea449f61f9
commit 4e775b6691
No known key found for this signature in database
GPG key ID: 1B477797DCA5EC72
5 changed files with 68 additions and 16 deletions

View file

@ -15,7 +15,9 @@ rec {
}) })
hosts targets; hosts targets;
inherit (pkgs) lib; inherit (pkgs) lib;
runners = import ./runners.nix { inherit lib; inherit (deploy) target; };
deploy = import ./lib/deploy.nix { deploy = import ./lib/deploy.nix {
inherit pkgs sources; inherit pkgs sources;

View file

@ -5,24 +5,30 @@ with pkgs.lib;
let let
pkgsModule = { ... }: { config._module.args = { pkgs = mkDefault pkgs; }; }; pkgsModule = { ... }: { config._module.args = { pkgs = mkDefault pkgs; }; };
configExtension = { ... }: {
options.terraform.baseDir = mkOption {
type = types.path;
};
};
tfEval = config: tfEval = config:
(evalModules { (evalModules {
modules = [ pkgsModule (sources.tf-nix + "/modules") ] ++ toList config; modules = [ pkgsModule (sources.tf-nix + "/modules") configExtension ] ++ toList config;
specialArgs = { inherit hosts; }; specialArgs = { inherit hosts; };
}).config; }).config;
tf = { targetName, target }: tf = { targetName ? null, target ? [] }:
tfEval ({ config, ... }: { tfEval ({ config, ... }: {
imports = optional (builtins.pathExists ../trusted/tf) (import ../trusted/tf/meta.nix) 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 config = mkMerge (map
(hostName: (hostName:
mapAttrs (_: mkMerge) hosts.${hostName}.config.deploy.tf.out.set) mapAttrs (_: mkMerge) hosts.${hostName}.config.deploy.tf.out.set)
target); target);
}] ++ optional }] ++ optional
(builtins.pathExists (../trusted/targets + "/${targetName}")) (targetName != null && builtins.pathExists (../trusted/targets + "/${targetName}"))
(../trusted/targets + "/${targetName}") (../trusted/targets + "/${targetName}")
++ optional (builtins.pathExists (../targets + "/${targetName}")) ++ optional (targetName != null && builtins.pathExists (../targets + "/${targetName}"))
(../targets + "/${targetName}") ++ concatMap (../targets + "/${targetName}") ++ concatMap
(hostName: (hostName:
filter builtins.pathExists filter builtins.pathExists
@ -35,12 +41,17 @@ let
enable = true; enable = true;
}; };
runners.lazy = { runners = {
file = ../.; lazy = {
args = [ "--show-trace" ]; file = ../.;
attrPrefix = args = [ "--show-trace" ];
let attr = if target != null then "target.${targetName}" else "tf"; attrPrefix =
in "deploy.${attr}.runners.run."; 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 = { variables.hcloud_token = {

View file

@ -38,7 +38,7 @@ rec {
})) }))
hostNames); 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; }) (hostName: host: { ${host.config.deploy.target} = hostName; })
hosts); hosts));
} }

16
runners.nix Normal file
View 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

View file

@ -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 = '' shellHook = ''
export HOME_HOSTNAME=$(hostname -s) 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
}
''; '';
} }