# SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0

{ depot, lib, pkgs, ... }@args:
let
  cfg = configName: configPath: { ... }: {
    _module.args = args // {
      inherit configName;
    };
    imports = [ configPath ];
  };

  configs = {
    base = nixos/lib/home-manager/common.nix;
    client = nixos/lib/home-manager/client.nix;
    porcorosso-wsl = nixos/lib/home-manager/porcorosso-wsl.nix;
  };

  configModules = lib.mapAttrs cfg configs;

  builtModules = lib.mapAttrs (name: value: (import ../third_party/home-manager/modules {
    inherit pkgs;

    configuration = {
      imports = [ value ];
      config._module.args.pkgs = lib.mkForce pkgs;
      config.nixpkgs.config = pkgs.config;
      config.home.sessionVariablesExtra = ''
        export PATH="$HOME/.nix-profile/bin''${PATH:+:}$PATH"
      '';
    };
    check = true;
  }).activationPackage) configModules;
in
configModules // {
  built = builtModules;
}