# Gather up the grid library functionality and present it in a (somewhat)
# coherent public interface.  Application code should prefer these names over
# directly importing the source files in this directory.
{
  base = import ./base.nix;

  hardware-aws = import ./issuer-aws.nix;
  hardware-vagrant = import ./hardware-vagrant.nix;

  issuer = import ./issuer.nix;
  storage = import ./storage.nix;
  monitoring = import ./monitoring.nix;

  modules = builtins.toString ../../nixos/modules;

  # The nixpkgs version used in our deployments. This affects both the packages
  # installed, as well as the NixOS module set that is used.
  # This is intended to be used in a grid definition like:
  #     network = { ... ; inherit (gridlib) pkgs; ... }
  pkgs = import ../../nixpkgs.nix {
    # Ensure that configuration of the system where this runs
    # doesn't leak into what we build.
    # See https://github.com/NixOS/nixpkgs/issues/62513
    config = { pkgs }: let lib = pkgs.lib; in {
      allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
        "megacli"
      ];
    };
    # Expose `nixos/pkgs` as an attribute of our package set.
    # This is is primarly consumed by `nixos/modules/packages.nix`, which
    # then exposes it as a module argument. We do this here, so that
    # the package set only needs to be evaluted once for the grid, rather
    # than once for each host.
    overlays = [
      (self: super: { ourpkgs = self.callPackage ../../nixos/pkgs {}; })
    ];
  };
}