#  My first run with nix. The config is based on Matthias Benaets config and youtube tutorial
#  https://github.com/MatthiasBenaets/nixos-config
#  https://www.youtube.com/watch?v=AGVXJ-TIv3Y
#
#  flake.nix *             
#   ├─ ./hosts
#   │   └─ default.nix

{
  description = "Kabbone's peronal NixOS Flake config";

  inputs =                                                                  # All flake references used to build my NixOS setup. These are dependencies.
    {
      nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";                  # Nix Packages
      nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
      nixos-hardware.url = "github:NixOS/nixos-hardware/master";

      microvm = {
        url = "github:astro/microvm.nix";
        inputs.nixpkgs.follows = "nixpkgs";
      };

      impermanence.url = "github:nix-community/impermanence";

      home-manager = {                                                      # User Package Management
        url = "github:nix-community/home-manager/release-24.11";
        inputs.nixpkgs.follows = "nixpkgs";
      };

      home-manager-unstable = {                                                      # User Package Management
        url = "github:nix-community/home-manager";
        inputs.nixpkgs.follows = "nixpkgs-unstable";
      };

      agenix = {
        url = "github:ryantm/agenix";
        inputs.nixpkgs.follows = "nixpkgs";
      };

      jovian-nixos = {
        url = "github:Jovian-Experiments/Jovian-NixOS";
        inputs.nixpkgs.follows = "nixpkgs-unstable";
      };

      lanzaboote = {
        url = "github:nix-community/lanzaboote/master";
        inputs.nixpkgs.follows = "nixpkgs";
      };

    };

  outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, nixos-hardware, home-manager, home-manager-unstable, agenix, jovian-nixos, microvm, impermanence, lanzaboote, ... }:   # Function that tells my flake which to use and what do what to do with the dependencies.
    rec {
        nixosConfigurations = (                                               # NixOS configurations
          import ./hosts {                                                    # Imports ./hosts/default.nix
            inherit (nixpkgs) lib;
            inherit inputs nixpkgs nixpkgs-unstable nixos-hardware home-manager home-manager-unstable agenix jovian-nixos microvm impermanence lanzaboote;   # Also inherit home-manager so it does not need to be defined here.
            nix.allowedUsers = [ "@wheel" ];
            security.sudo.execWheelOnly = true;
          }
        );
        hydraJobs = {
          "steamdeck" = nixosConfigurations.steamdeck.config.system.build.toplevel;
          "hades" = nixosConfigurations.hades.config.system.build.toplevel;
          "nasbak" = nixosConfigurations.nasbak.config.system.build.toplevel;
          "jupiter" = nixosConfigurations.jupiter.config.system.build.toplevel;
          "lifebook" = nixosConfigurations.lifebook.config.system.build.toplevel;
          "kabtop" = nixosConfigurations.kabtop.config.system.build.toplevel;
          "dmz" = nixosConfigurations.dmz.config.system.build.toplevel;
        };
    };


}