{
  description = "flake for matt-nixos";

  inputs = {

    #####################################################
    #                   Desktop                         #
    #####################################################

    # nixpgs
    desktop-nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };

    # Chaotic-nix
    desktop-chaotic = {
      url = "github:chaotic-cx/nyx/nyxpkgs-unstable";
    };

    # Home Manager
    desktop-home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "desktop-nixpkgs";
    };

    # Impermenance
    desktop-impermanence = {
      url = "github:nix-community/impermanence";
    };

    # Lanzaboote
    desktop-lanzaboote = {
      url = "github:nix-community/lanzaboote/v0.4.2";
      inputs.nixpkgs.follows = "desktop-nixpkgs";
    };

    # Nix hardware
    desktop-nixos-hardware = {
      url = "github:NixOS/nixos-hardware/master";
    };

    # Sops-nix
    desktop-sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "desktop-nixpkgs";
    };

    # steam rom manager
    desktop-steam-rom-manager = {
      url = "github:mjallen18/nix-steam-rom-manager";
      inputs.nixpkgs.follows = "desktop-nixpkgs";
      inputs.home-manager.follows = "desktop-home-manager";
    };

    # cosmic launcher
    desktop-cosmic = {
      url = "github:lilyinstarlight/nixos-cosmic";
      inputs.nixpkgs.follows = "desktop-nixpkgs";
    };

    #####################################################
    #                     NAS                           #
    #####################################################

    # nixpgs
    nas-nixpkgs = {
      # url = "github:NixOS/nixpkgs/nixos-24.11";
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };

    nas-nixpkgs-stable = {
      url = "github:NixOS/nixpkgs/nixos-24.11";
    };

    # Authentik
    nas-authentik-nix = {
      url = "github:nix-community/authentik-nix";
      inputs.nixpkgs.follows = "nas-nixpkgs";
    };

    # cosmic launcher
    nas-cosmic = {
      url = "github:lilyinstarlight/nixos-cosmic";
      inputs.nixpkgs.follows = "nas-nixpkgs-stable";
    };

    # crowdsec
    nas-crowdsec = {
      url = "git+https://codeberg.org/kampka/nix-flake-crowdsec.git";
      inputs.nixpkgs.follows = "nas-nixpkgs";
    };

    # Home Manager
    nas-home-manager = {
      # url = "github:nix-community/home-manager/release-24.11";
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nas-nixpkgs";
    };

    # Impermenance
    nas-impermanence = {
      url = "github:nix-community/impermanence";
    };

    # Lanzaboote
    nas-lanzaboote = {
      url = "github:nix-community/lanzaboote/v0.4.2";
      inputs.nixpkgs.follows = "nas-nixpkgs";
    };

    # Nix hardware
    nas-nixos-hardware = {
      url = "github:NixOS/nixos-hardware/master";
    };

    # Sops-nix
    nas-sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "nas-nixpkgs";
    };

    nas-nixai.url = "github:olafkfreund/nix-ai-help";

    nas-nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";

    #####################################################
    #                     pi5                           #
    #####################################################

    # nixpgs
    pi5-nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };

    # Home Manager
    pi5-home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "pi5-nixpkgs";
    };

    # Impermenance
    pi5-impermanence = {
      url = "github:nix-community/impermanence";
    };

    # Nix hardware
    pi5-nixos-hardware = {
      url = "github:NixOS/nixos-hardware/master";
    };

    # Sops-nix
    pi5-sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "pi5-nixpkgs";
    };

    pi5-disko = {
      # the fork is needed for partition attributes support
      url = "github:nvmd/disko/gpt-attrs";
      # url = "github:nix-community/disko";
      inputs.nixpkgs.follows = "pi5-nixpkgs";
    };

    pi5-cosmic = {
      url = "github:lilyinstarlight/nixos-cosmic";
      inputs.nixpkgs.follows = "pi5-nixpkgs";
    };

    #####################################################
    #                     pi4                           #
    #####################################################

    # nixpgs
    pi4-nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };

    # Home Manager
    pi4-home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "pi4-nixpkgs";
    };

    # Impermenance
    pi4-impermanence = {
      url = "github:nix-community/impermanence";
    };

    # Sops-nix
    pi4-sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "pi4-nixpkgs";
    };

    # Nix hardware
    pi4-nixos-hardware = {
      url = "github:NixOS/nixos-hardware/master";
    };

    pi4-disko = {
      # the fork is needed for partition attributes support
      url = "github:nvmd/disko/gpt-attrs";
      # url = "github:nix-community/disko";
      inputs.nixpkgs.follows = "pi4-nixpkgs";
    };


    nixos-raspberrypi.url = "github:nvmd/nixos-raspberrypi";

    #####################################################
    #                  Steamdeck                        #
    #####################################################

    # nixpgs
    steamdeck-nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };

    # Joviain for steamdeck
    steamdeck-jovian = {
      url = "github:Jovian-Experiments/Jovian-NixOS";
      inputs.nixpkgs.follows = "steamdeck-nixpkgs";
    };

    # Chaotic-nix
    steamdeck-chaotic = {
      url = "github:chaotic-cx/nyx/nyxpkgs-unstable";
    };

    # Impermenance
    steamdeck-impermanence = {
      url = "github:nix-community/impermanence";
    };

    # Home Manager
    steamdeck-home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "steamdeck-nixpkgs";
    };

    # Lanzaboote
    steamdeck-lanzaboote = {
      url = "github:nix-community/lanzaboote/v0.4.2";
      inputs.nixpkgs.follows = "steamdeck-nixpkgs";
    };

    # Sops-nix
    steamdeck-sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "steamdeck-nixpkgs";
    };

    # Nix hardware
    steamdeck-nixos-hardware = {
      url = "github:NixOS/nixos-hardware/master";
    };

    # steam rom manager
    steamdeck-steam-rom-manager = {
      url = "github:mjallen18/nix-steam-rom-manager";
      inputs.nixpkgs.follows = "steamdeck-nixpkgs";
      inputs.home-manager.follows = "steamdeck-home-manager";
    };

    steamdeck-disko = {
      # the fork is needed for partition attributes support
      url = "github:nvmd/disko/gpt-attrs";
      # url = "github:nix-community/disko";
      inputs.nixpkgs.follows = "steamdeck-nixpkgs";
    };

    #####################################################
    #                   MacBook                         #
    #####################################################

    #Apple
    nix-darwin = {
      url = "github:LnL7/nix-darwin";
      inputs.nixpkgs.follows = "desktop-nixpkgs";
    };
  
    #####################################################
    #                 Macbook Nix                       #
    #####################################################

    # nixpgs
    mac-nixpkgs = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };

    mac-nixos-apple-silicon = {
      url = "github:nix-community/nixos-apple-silicon";
    };

    # Home Manager
    mac-home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "mac-nixpkgs";
    };

    # Impermenance
    mac-impermanence = {
      url = "github:nix-community/impermanence";
    };

    # Sops-nix
    mac-sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "mac-nixpkgs";
    };

    #####################################################
    #                    Common                         #
    #####################################################

    nixpkgs-unstable = {
      url = "github:NixOS/nixpkgs/nixos-unstable";
    };

    nixpkgs-stable = {
      url = "github:NixOS/nixpkgs/nixos-25.05";
    };
  };

  outputs =
    {
      self,

      # Desktop
      desktop-nixpkgs,
      desktop-chaotic,
      desktop-home-manager,
      desktop-impermanence,
      desktop-lanzaboote,
      desktop-nixos-hardware,
      desktop-sops-nix,
      desktop-steam-rom-manager,
      desktop-cosmic,

      # NAS
      nas-nixpkgs,
      nas-nixpkgs-stable,
      nas-authentik-nix,
      nas-cosmic,
      nas-crowdsec,
      nas-home-manager,
      nas-impermanence,
      nas-lanzaboote,
      nas-nixos-hardware,
      nas-sops-nix,
      nas-nixai,
      nas-nix-vscode-extensions,

      # pi5
      pi5-nixpkgs,
      pi5-home-manager,
      pi5-impermanence,
      pi5-nixos-hardware,
      pi5-sops-nix,
      pi5-disko,
      pi5-cosmic,

      # pi4
      pi4-nixpkgs,
      pi4-home-manager,
      pi4-impermanence,
      pi4-sops-nix,
      pi4-nixos-hardware,
      pi4-disko,

      nixos-raspberrypi,

      # Steamdeck
      steamdeck-nixpkgs,
      steamdeck-chaotic,
      steamdeck-home-manager,
      steamdeck-impermanence,
      steamdeck-jovian,
      steamdeck-lanzaboote,
      steamdeck-nixos-hardware,
      steamdeck-sops-nix,
      steamdeck-steam-rom-manager,
      steamdeck-disko,

      # MacBook
      nix-darwin,

      # MacBook Nix
      mac-nixpkgs,
      mac-nixos-apple-silicon,
      mac-home-manager,
      mac-impermanence,
      mac-sops-nix,

      # Common
      nixpkgs-unstable,
      nixpkgs-stable,
    }@inputs:
    let
      inherit (self) outputs;
    in
    {
      overlays = import ./overlays { inherit inputs; };

      nixosConfigurations = {
        # Desktop
        "matt-nixos" = desktop-nixpkgs.lib.nixosSystem {
          system = "x86_64-linux";
          specialArgs = {
            inherit inputs outputs;
          };
          modules = [
            ./hosts/base/base-nogui
            ./hosts/base/base-gui
            ./hosts/desktop/configuration.nix

            ./modules/desktop-environments/gnome
            ./modules/desktop-environments/cosmic/specialisation.nix
            ./modules/desktop-environments/hyprland/specialisation.nix

            ./modules/amd
            ./modules/gaming

            # Lanzaboote
            desktop-lanzaboote.nixosModules.lanzaboote

            # Chaotic Nyx
            desktop-chaotic.nixosModules.default

            # Impermanence
            desktop-impermanence.nixosModules.impermanence
            ./modules/impermanence

            desktop-sops-nix.nixosModules.sops

            # Home Manager
            desktop-home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.matt =
                { ... }:
                {
                  imports = [
                    ./hosts/desktop/home.nix
                    ./modules/home/defaults.nix
                    ./modules/home/git.nix
                    ./modules/home/gnome.nix
                    ./modules/home/librewolf.nix
                    ./modules/home/office.nix
                    ./modules/home/shell.nix
                    ./modules/home/vscode.nix
                    desktop-steam-rom-manager.homeManagerModules.default
                    desktop-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.users.root =
                { ... }:
                {
                  imports = [
                    ./modules/root-user
                    desktop-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.backupFileExtension = "backup";
            }

            # nixos hardware
            desktop-nixos-hardware.nixosModules.common-cpu-amd
            desktop-nixos-hardware.nixosModules.common-cpu-amd-pstate
            desktop-nixos-hardware.nixosModules.common-cpu-amd-zenpower
            desktop-nixos-hardware.nixosModules.common-gpu-amd
            desktop-nixos-hardware.nixosModules.common-hidpi
            desktop-nixos-hardware.nixosModules.common-pc
          ];
        };

        # NAS
        "jallen-nas" = nas-nixpkgs.lib.nixosSystem {
          system = "x86_64-linux";
          specialArgs = {
            inherit inputs outputs;
          };
          modules = [
            ./hosts/base/base-nogui
            ./hosts/base/base-gui
            ./hosts/nas/configuration.nix
            ./modules/desktop-environments/cosmic
            ./modules/nvidia

            nas-lanzaboote.nixosModules.lanzaboote

            nas-impermanence.nixosModules.impermanence
            ./hosts/nas/impermanence.nix

            nas-cosmic.nixosModules.default

            # nas-nixai.nixosModules.x86_64-linux.default

            nas-home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = false;
              home-manager.useUserPackages = true;
              home-manager.users.admin =
                { ... }:
                {
                  imports = [
                    ./hosts/nas/home.nix
                    ./modules/home/defaults.nix
                    ./modules/home/git.nix
                    ./modules/home/librewolf.nix
                    ./modules/home/shell.nix
                    ./modules/home/vscode.nix
                    nas-sops-nix.homeManagerModules.sops
                    # nas-nixai.homeManagerModules.x86_64-linux.default
                  ];
                };
              home-manager.users.root =
                { ... }:
                {
                  imports = [
                    ./modules/root-user
                    nas-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.backupFileExtension = "backup";
            }

            nas-authentik-nix.nixosModules.default

            nas-sops-nix.nixosModules.sops

            nas-crowdsec.nixosModules.crowdsec
            nas-crowdsec.nixosModules.crowdsec-firewall-bouncer

            (
              { ... }:
              {
                nixpkgs.overlays = [
                  nas-crowdsec.overlays.default
                  nas-nix-vscode-extensions.overlays.default
                ];
              }
            )

            nas-nixos-hardware.nixosModules.common-pc
            nas-nixos-hardware.nixosModules.common-cpu-amd
            nas-nixos-hardware.nixosModules.common-cpu-amd-pstate
            nas-nixos-hardware.nixosModules.common-cpu-amd-zenpower
            nas-nixos-hardware.nixosModules.common-hidpi
          ];
        };

        # pi5
        "pi5" = nixos-raspberrypi.lib.nixosSystem {
          specialArgs = inputs //
          {
            inherit outputs;
          };
          system = "aarch64-linux";
          modules = [
            ./hosts/base/base-nogui
            ./hosts/base/base-gui
            pi5-disko.nixosModules.disko
            ./hosts/pi5/disko.nix
            pi5-cosmic.nixosModules.default
            pi5-impermanence.nixosModules.impermanence
            pi5-sops-nix.nixosModules.sops
            ./hosts/pi5/configuration.nix
            pi5-nixos-hardware.nixosModules.raspberry-pi-5
            {
              # Hardware specific configuration, see section below for a more complete
              # list of modules
              imports = with nixos-raspberrypi.nixosModules; [
                raspberry-pi-5.base
                raspberry-pi-5.display-vc4
                raspberry-pi-5.bluetooth
              ];
            }
            pi5-home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.backupFileExtension = "backup";
              home-manager.users.matt =
                { ... }:
                {
                  imports = [
                    ./hosts/pi5/home.nix
                    pi5-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.users.root =
                { ... }:
                {
                  imports = [
                    ./modules/root-user
                    pi5-sops-nix.homeManagerModules.sops
                  ];
                };
            }
          ];
        };

        # pi4
        "pi4" = nixos-raspberrypi.lib.nixosSystem {
          specialArgs = inputs //
          {
            inherit outputs;
          };
          system = "aarch64-linux";
          modules = [
            ./hosts/base/base-nogui
            pi4-disko.nixosModules.disko
            ./modules/disko/pi-uefi-disko.nix
            pi4-nixos-hardware.nixosModules.raspberry-pi-4
            {
              # Hardware specific configuration, see section below for a more complete
              # list of modules
              imports = with nixos-raspberrypi.nixosModules; [
                raspberry-pi-4.base
                raspberry-pi-4.display-vc4
                raspberry-pi-4.bluetooth
                raspberry-pi-4.case-argonone
              ];
            }
            pi4-impermanence.nixosModules.impermanence
            pi4-sops-nix.nixosModules.sops
            ./hosts/pi4/configuration.nix
            pi4-home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.backupFileExtension = "backup";
              home-manager.users.matt =
                { ... }:
                {
                  imports = [
                    ./hosts/pi4/home.nix
                    pi4-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.users.root =
                { ... }:
                {
                  imports = [
                    ./modules/root-user
                    pi4-sops-nix.homeManagerModules.sops
                  ];
                };
            }
          ];
        };

        "steamdeck" = steamdeck-nixpkgs.lib.nixosSystem {
          system = "x86_64-linux";
          specialArgs = {
            inherit inputs outputs;
          };
          modules = [
            ./hosts/base/base-nogui
            ./hosts/base/base-gui
            ./hosts/deck/configuration.nix
            ./modules/desktop-environments/gnome

            steamdeck-lanzaboote.nixosModules.lanzaboote

            steamdeck-disko.nixosModules.disko
            ./modules/disko/disko.nix

            steamdeck-impermanence.nixosModules.impermanence
            ./modules/impermanence

            steamdeck-home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.deck =
                { ... }:
                {
                  imports = [
                    ./hosts/deck/home.nix
                    ./modules/home/defaults.nix
                    ./modules/home/git.nix
                    ./modules/home/gnome.nix
                    ./modules/home/librewolf.nix
                    ./modules/home/office.nix
                    ./modules/home/shell.nix
                    ./modules/home/vscode.nix
                    steamdeck-sops-nix.homeManagerModules.sops
                    steamdeck-steam-rom-manager.homeManagerModules.default
                  ];
                };
              home-manager.users.root =
                { ... }:
                {
                  imports = [
                    ./modules/root-user
                    steamdeck-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.backupFileExtension = "backup";
            }

            steamdeck-nixos-hardware.nixosModules.common-cpu-amd
            steamdeck-nixos-hardware.nixosModules.common-cpu-amd-pstate
            steamdeck-nixos-hardware.nixosModules.common-cpu-amd-zenpower
            steamdeck-nixos-hardware.nixosModules.common-gpu-amd
            steamdeck-nixos-hardware.nixosModules.common-hidpi
            steamdeck-nixos-hardware.nixosModules.common-pc

            steamdeck-sops-nix.nixosModules.sops

            steamdeck-jovian.nixosModules.jovian

            steamdeck-chaotic.nixosModules.default
          ];
        };

        # MacBook Nix
        "macbook-pro-nixos" = mac-nixpkgs.lib.nixosSystem {
          system = "aarch64-linux";
          specialArgs = {
            inherit inputs outputs;
            hyprlandSettings = import ./hosts/mac-nixos/hyprland-settings.nix;
          };
          modules = [
            ./hosts/base/base-nogui
            ./hosts/base/base-gui
            ./hosts/mac-nixos/configuration.nix

            ./modules/desktop-environments/hyprland

            # Apple Silicon Support
            mac-nixos-apple-silicon.nixosModules.default

            # Impermanence
            mac-impermanence.nixosModules.impermanence
            ./modules/impermanence

            mac-sops-nix.nixosModules.sops

            # Home Manager
            mac-home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.matt =
                { ... }:
                {
                  imports = [
                    ./hosts/mac-nixos/home.nix
                    ./modules/home/defaults.nix
                    ./modules/home/git.nix
#                    ./modules/home/gnome.nix
#                    ./modules/home/librewolf.nix
                    ./modules/home/office.nix
                    ./modules/home/shell.nix
#                    ./modules/home/vscode.nix
                    mac-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.users.root =
                { ... }:
                {
                  imports = [
                    ./modules/root-user
                    mac-sops-nix.homeManagerModules.sops
                  ];
                };
              home-manager.backupFileExtension = "backup";
            }
          ];
        };

        # home assistant
        # "jallen-hass" = nixpkgs-unstable.lib.nixosSystem {
        #   system = "x86_64-linux";
        #   modules = [
        #     impermanence.nixosModules.impermanence
        #     ./hosts/homeassistant/configuration.nix
        #     sops-nix.nixosModules.sops

        #     home-manager.nixosModules.home-manager
        #     {
        #       home-manager.useGlobalPkgs = true;
        #       home-manager.useUserPackages = true;
        #       home-manager.users.hass-admin = import ./hosts/homeassistant/home.nix;
        #     }
        #   ];
        # };
      };

      darwinConfigurations = {
        "MacBook-Pro" = nix-darwin.lib.darwinSystem {
          system = "aarch64-darwin";
          modules = [
            ./hosts/mac/configuration.nix
            desktop-home-manager.darwinModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.mattjallen = import ./hosts/mac/home.nix;
            }
          ];
        };
      };

      packages.aarch64-linux.vmware-horizon-fhs = 
      let
        pkgs = import mac-nixpkgs { system = "aarch64-linux"; };
        x64 = import mac-nixpkgs { system = "x86_64-linux"; config.allowUnfree = true; };
      in
      pkgs.buildFHSEnv {
        name = "horizon-client-x64";
        targetPkgs = _pkgs: with x64; [
          vmware-horizon-client gtk3 xorg.libX11 libxml2
        ];
        runScript = "box64 vmware-view";
      };

      # Expose the package set, including overlays, for convenience.
      darwinPackages = self.darwinConfigurations."MacBook-Pro".pkgs;

      # Set Git commit hash for darwin-version.
      system.configurationRevision = self.rev or self.dirtyRev or null;
    };
}
