#
#  These are the different profiles that can be used when building NixOS.
#
#  flake.nix 
#   └─ ./hosts  
#       ├─ default.nix *
#       ├─ configuration.nix
#       ├─ home.nix
#       └─ ./desktop OR ./laptop OR ./vm
#            ├─ ./default.nix
#            └─ ./home.nix 
#

{ lib, inputs, nixpkgs, nixpkgs-unstable, nixos-hardware, home-manager, home-manager-unstable, agenix, jovian-nixos, microvm, impermanence, lanzaboote, ... }:

let
  user = "kabbone";
  userdmz = "diablo";
  userserver = "mephisto";
  location = "$HOME/.setup";

  system = "x86_64-linux";                                  # System architecture

  pkgs = import nixpkgs {
    inherit system;
    config.allowUnfree = true;                              # Allow proprietary software
  };

  lib = nixpkgs.lib;
  users.defaultShell = "pkgs.zsh";

in
{
  hades = lib.nixosSystem {                                # Desktop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix microvm nixpkgs lanzaboote; };
    modules = [
      agenix.nixosModules.default
      microvm.nixosModules.host
      lanzaboote.nixosModules.lanzaboote
      ./desktop
      ./configuration_desktop.nix
      ../modules/hardware/hydraCache.nix
      ../modules/hardware/remoteBuilder.nix
      nixos-hardware.nixosModules.common-cpu-amd
      nixos-hardware.nixosModules.common-gpu-amd
      nixos-hardware.nixosModules.common-pc-ssd
      

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home.nix)] ++ [(import ./desktop/home.nix)];
        };
      }
    ];
  };

  lifebook = lib.nixosSystem {                                # Laptop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix lanzaboote; };
    modules = [
      agenix.nixosModules.default
      lanzaboote.nixosModules.lanzaboote
      ./lifebook
      ./configuration_desktop.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-cpu-intel
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home.nix)] ++ [(import ./lifebook/home.nix)];
        };
      }
    ];
  };

  nbf5 = lib.nixosSystem {                                # Laptop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix; };
    modules = [
      agenix.nixosModules.default
      ./nbf5
      ./configuration_desktop.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-cpu-intel
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home.nix)] ++ [(import ./nbf5/home.nix)];
        };
      }
    ];
  };

  steamdeck = nixpkgs-unstable.lib.nixosSystem {            # steamdeck profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix jovian-nixos lanzaboote; };
    modules = [
      agenix.nixosModules.default
      jovian-nixos.nixosModules.default
      lanzaboote.nixosModules.lanzaboote
      ./steamdeck
      ./configuration_desktop.nix
      ../modules/hardware/hydraCache.nix

      home-manager-unstable.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home.nix)] ++ [(import ./steamdeck/home.nix)];
        };
      }
    ];
  };

  server = lib.nixosSystem {                                # Desktop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix nixpkgs impermanence; };
    modules = [
      agenix.nixosModules.default
      microvm.nixosModules.host
      ./server
      ./configuration_server.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-cpu-amd
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home_server.nix)] ++ [(import ./server/home.nix)];
        };
      }
    ];
  };

  kabtop = lib.nixosSystem {                                # Desktop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix nixpkgs impermanence; };
    modules = [
      agenix.nixosModules.default
      microvm.nixosModules.host
      ./kabtop
      ./configuration_server.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-cpu-amd
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home_server.nix)] ++ [(import ./server/home.nix)];
        };
      }
    ];
  };

  nasbak = lib.nixosSystem {                                # Desktop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix; };
    modules = [
      agenix.nixosModules.default
      ./nasbackup
      ./configuration_server.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-cpu-intel
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home_server.nix)] ++ [(import ./nasbackup/home.nix)];
        };
      }
    ];
  };

  jupiter = lib.nixosSystem {                                # Desktop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix; };
    modules = [
      agenix.nixosModules.default
      ./jupiter
      ./configuration_server.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-cpu-intel
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home_server.nix)] ++ [(import ./jupiter/home.nix)];
        };
      }
    ];
  };

  kabtopci = lib.nixosSystem {                                # Desktop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix nixpkgs impermanence; };
    modules = [
      agenix.nixosModules.default
      microvm.nixosModules.host
      ./kabtopci
      ./configuration_server.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home_server.nix)] ++ [(import ./kabtopci/home.nix)];
        };
      }
    ];
  };

  dmz = lib.nixosSystem {                                # Desktop profile
    inherit system;
    specialArgs = { inherit inputs user location nixos-hardware agenix nixpkgs impermanence; };
    modules = [
      agenix.nixosModules.default
      microvm.nixosModules.host
      ./dmz
      ./configuration_server.nix
      ../modules/hardware/hydraCache.nix
      nixos-hardware.nixosModules.common-pc-ssd

      home-manager.nixosModules.home-manager {
        home-manager.useGlobalPkgs = true;
        home-manager.useUserPackages = true;
        home-manager.extraSpecialArgs = { inherit user; };
        home-manager.users.${user} = {
        imports = [(import ./home_server.nix)] ++ [(import ./dmz/home.nix)];
        };
      }
    ];
  };

#  vm = lib.nixosSystem {                                    # VM profile
#    inherit system;
#    specialArgs = { inherit inputs user location; };
#    modules = [
#      ./vm
#      ./configuration.nix
#
#      home-manager.nixosModules.home-manager {
#        home-manager.useGlobalPkgs = true;
#        home-manager.useUserPackages = true;
#        home-manager.extraSpecialArgs = { inherit user; }; 
#        home-manager.users.${user} = {
#          imports = [(import ./home.nix)] ++ [(import ./vm/home.nix)];
#        };
#      }
#    ];
#  };
}