diff --git a/.gitignore b/.gitignore index 06d79aa..182b988 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ result result-* **/.direnv/ -.data/ \ No newline at end of file +.data/ +.cache/ +.nixos-test-history diff --git a/catalog/part.nix b/catalog/part.nix new file mode 100644 index 0000000..cb6bcad --- /dev/null +++ b/catalog/part.nix @@ -0,0 +1,10 @@ +{ lib, ... }: + +{ + perSystem = { + options.catalog = lib.mkOption { + type = with lib.types; lazyAttrsOf (lazyAttrsOf (lazyAttrsOf (submodule ./target.nix))); + default = {}; + }; + }; +} diff --git a/catalog/target.nix b/catalog/target.nix new file mode 100644 index 0000000..e3f9d29 --- /dev/null +++ b/catalog/target.nix @@ -0,0 +1,31 @@ +{ lib, name, ... }: + +{ + options = { + description = lib.mkOption { + type = lib.types.str; + default = name; + }; + + actions = lib.mkOption { + type = with lib.types; lazyAttrsOf (submodule { + options = { + description = lib.mkOption { + type = lib.types.str; + default = name; + }; + + command = lib.mkOption { + type = lib.types.str; + }; + + packages = lib.mkOption { + type = with lib.types; listOf package; + default = []; + }; + }; + }); + default = {}; + }; + }; +} diff --git a/cluster/catalog/default.nix b/cluster/catalog/default.nix new file mode 100644 index 0000000..82114b7 --- /dev/null +++ b/cluster/catalog/default.nix @@ -0,0 +1,52 @@ +{ config, lib, ... }: + +let + inherit (config) cluster flake; +in + +{ + perSystem = { config, pkgs, ... }: { + catalog.cluster = { + services = lib.mapAttrs (name: svc: { + description = "Cluster service: ${name}"; + actions = let + mkDeployAction = { description, agents }: { + inherit description; + packages = [ + config.packages.cachix + pkgs.tmux + ]; + command = let + cachixDeployJson = pkgs.writeText "cachix-deploy.json" (builtins.toJSON { + agents = lib.genAttrs agents (name: builtins.unsafeDiscardStringContext flake.nixosConfigurations.${name}.config.system.build.toplevel); + }); + in '' + set -e + echo building ${toString (lib.length agents)} configurations in parallel + tmux new-session ${lib.concatStringsSep " split-window " ( + map (host: let + drvPath = builtins.unsafeDiscardStringContext flake.nixosConfigurations.${host}.config.system.build.toplevel.drvPath; + in '' 'echo building configuration for ${host}; nix build -L --no-link --store "ssh-ng://${host}" --eval-store auto "${drvPath}^*"'\; '') agents + )} select-layout even-vertical + + source ~/.config/cachix/deploy + cachix deploy activate ${cachixDeployJson} + echo + ''; + }; + in { + deployAll = mkDeployAction { + description = "Deploy ALL groups of this service."; + agents = lib.unique (lib.concatLists (lib.attrValues svc.nodes)); + }; + } // lib.mapAttrs' (group: agents: { + name = "deployGroup-${group}"; + value = mkDeployAction { + description = "Deploy the '${group}' group of this service."; + inherit agents; + }; + }) svc.nodes; + }) cluster.config.services; + }; + }; +} diff --git a/cluster/part.nix b/cluster/part.nix index 99452ac..eae3222 100644 --- a/cluster/part.nix +++ b/cluster/part.nix @@ -1,6 +1,10 @@ { depot, lib, ... }: { + imports = [ + ./catalog + ]; + options.cluster = lib.mkOption { type = lib.types.raw; }; diff --git a/flake.nix b/flake.nix index 581b5ae..cb2f64b 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,7 @@ ./jobs/part.nix ./lib/part.nix ./cluster/part.nix + ./catalog/part.nix ]; }; diff --git a/lib/catalog.nix b/lib/catalog.nix new file mode 100644 index 0000000..b523fd4 --- /dev/null +++ b/lib/catalog.nix @@ -0,0 +1,42 @@ +{ config, lib, withSystem, ... }: + +{ + lib = { + catalog = { + init = lib.genAttrs config.systems (system: withSystem system ({ config, ... }: lib.mapAttrsToList (name: cell: { + cell = name; + cellBlocks = lib.mapAttrsToList (name: block: { + blockType = "catalogBlock"; + cellBlock = name; + targets = lib.mapAttrsToList (name: target: { + inherit name; + inherit (target) description; + actions = lib.mapAttrsToList (name: action: { + inherit name; + inherit (action) description; + }) target.actions; + }) block; + }) cell; + }) config.catalog)); + + actions = lib.genAttrs config.systems (system: withSystem system ({ config, pkgs, ... }: + lib.mapAttrs (name: cell: + lib.mapAttrs (name: block: + lib.mapAttrs (name: target: + lib.mapAttrs (name: action: + let + binPath = lib.makeBinPath action.packages; + in pkgs.writeShellScript name '' + # Void CLI Action + # --- + ${lib.optionalString (action.packages != []) ''export PATH="${binPath}:$PATH"''} + # --- + ${action.command} + '') target.actions + ) block + ) cell + ) + config.catalog)); + }; + }; +} diff --git a/lib/part.nix b/lib/part.nix index e152399..9d259ad 100644 --- a/lib/part.nix +++ b/lib/part.nix @@ -7,6 +7,7 @@ ./meta.nix ./nginx.nix ./identity.nix + ./catalog.nix ]; options.lib = lib.mkOption { @@ -23,5 +24,8 @@ }); }; - config._module.args.depot = config; + config = { + _module.args.depot = config; + flake = { inherit (config) lib; }; + }; } diff --git a/packages/catalog/checks.nix b/packages/catalog/checks.nix new file mode 100644 index 0000000..1dab997 --- /dev/null +++ b/packages/catalog/checks.nix @@ -0,0 +1,21 @@ +{ lib, ... }: + +{ + perSystem = { config, ... }: { + catalog.depot = { + checks = lib.mapAttrs (name: check: { + description = "NixOS Test: ${name}"; + actions = { + build = { + description = "Build this check."; + command = "nix build -L --no-link '${builtins.unsafeDiscardStringContext check.drvPath}^*'"; + }; + runInteractive = { + description = "Run interactive driver."; + command = lib.getExe check.driverInteractive; + }; + }; + }) config.checks; + }; + }; +} diff --git a/packages/catalog/default.nix b/packages/catalog/default.nix new file mode 100644 index 0000000..4a42cfa --- /dev/null +++ b/packages/catalog/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./checks.nix + ]; +} diff --git a/packages/part.nix b/packages/part.nix index 946dbb2..7823eae 100644 --- a/packages/part.nix +++ b/packages/part.nix @@ -8,6 +8,7 @@ in { imports = [ ./projects.nix ./patched-inputs.nix + ./catalog ]; perSystem = { pkgs, self', system, ... }: let patched-derivations = import ./patched-derivations.nix (pkgs // { flakePackages = self'.packages; }); diff --git a/packages/projects.nix b/packages/projects.nix index a5a7fd7..edc0767 100644 --- a/packages/projects.nix +++ b/packages/projects.nix @@ -46,6 +46,8 @@ searxng = pkgs.callPackage ./web-apps/searxng { inherit pins; }; stevenblack-hosts = pkgs.callPackage ./data/stevenblack { inherit pins; }; + + void = pkgs.callPackage ./tools/void { }; }; projectShells = { @@ -58,6 +60,7 @@ hci npins pin + void pkgs.deadnix pkgs.statix ]; diff --git a/packages/tools/void/default.nix b/packages/tools/void/default.nix new file mode 100644 index 0000000..fc9b85c --- /dev/null +++ b/packages/tools/void/default.nix @@ -0,0 +1,53 @@ +{ lib, buildGoModule, fetchFromGitHub, installShellFiles }: + +let + version = "0.15.0+dev"; + rev = "6461b31e4458dbce655fa1db6d266f666dbdfc4e"; +in +buildGoModule rec { + + inherit version; + pname = "void"; + + meta = { + description = "Paisano CLI/TUI, customized for Private Void"; + license = lib.licenses.unlicense; + homepage = "https://github.com/paisano-nix/tui"; + }; + + src = fetchFromGitHub { + owner = "paisano-nix"; + repo = "tui"; + inherit rev; + hash = "sha256-EFDb8jfv2SH57a6CfDo0WU4XjDihhgvVnKKw20yqksc="; + }; + + postPatch = '' + substituteInPlace flake/flake.go --replace-fail __std lib.catalog + substituteInPlace env/env.go --replace-fail '"metadata"' '"void-cli-metadata"' + ''; + + sourceRoot = "source/src"; + + vendorHash = "sha256-S1oPselqHRIPcqDSsvdIkCwu1siQGRDHOkxWtYwa+g4="; + + nativeBuildInputs = [ installShellFiles ]; + + postInstall = '' + mv $out/bin/paisano $out/bin/void + + installShellCompletion --cmd void \ + --bash <($out/bin/void _carapace bash) \ + --fish <($out/bin/void _carapace fish) \ + --zsh <($out/bin/void _carapace zsh) + ''; + + ldflags = [ + "-s" + "-w" + "-X main.buildVersion=${version}" + "-X main.buildCommit=${rev}" + "-X main.argv0=void" + "-X main.project=Depot" + ]; +}