{
  description = "Main Flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixpkgs-stable.url = "github:NixOS/nixpkgs/release-24.05";

    flake-utils.url = "github:numtide/flake-utils";

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

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

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

    stylix = {
      url = "github:danth/stylix";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        flake-utils.follows = "flake-utils";
        home-manager.follows = "home-manager";
      };
    };

    hyprland = {
      url = "git+https://github.com/hyprwm/Hyprland";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    hyprgrass = {
      url = "github:horriblename/hyprgrass";
      inputs.hyprland.follows = "hyprland";
    };

    hyprpanel = {
      url = "github:jas-singhfsu/hyprpanel";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    rose-pine-hyprcursor = {
      url = "github:ndom91/rose-pine-hyprcursor";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.utils.follows = "flake-utils";
      inputs.hyprlang.follows = "hyprland/hyprlang";
    };

    zen-browser = {
      url = "github:firelilith/zen-browser-nix/native-messaging-collision";
      inputs.nixpkgs.follows = "nixpkgs";
    };

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

  outputs =
    {
      self,
      nixpkgs,
      home-manager,
      nur,
      zen-browser,
      ...
    }@inputs:
    let
      inherit (nixpkgs) lib;

      systemFromHardwareConf =
        hostname:
        let
          hardware = import ./hosts/${hostname}/hardware-configuration.nix;
          args = builtins.functionArgs hardware // {
            lib.mkDefault = lib.id;
          };
        in
        (hardware args).nixpkgs.hostPlatform;

      importNixpkgs =
        system: nixpkgs:
        let
          config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) (import ./unfree.nix).allowed;
        in
        import nixpkgs {
          inherit system config;
          overlays = [
            nur.overlays.default
            zen-browser.overlay
          ];
        };

      makeHost =
        host: system:
        lib.nixosSystem {
          system = system;
          pkgs = importNixpkgs system nixpkgs;
          specialArgs = inputs // {
            inherit system;
          };
          modules = [
            ./hosts/${host}/default.nix
            ./hosts/${host}/hardware-configuration.nix
            ./system
            { networking.hostName = host; }

            ./home
          ];
        };
    in
    {
      nixosConfigurations = lib.pipe ./hosts [
        builtins.readDir
        (lib.filterAttrs (_: type: type == "directory"))
        (lib.filterAttrs (
          name: _:
          builtins.pathExists ./hosts/${name}/default.nix
          && builtins.pathExists ./hosts/${name}/hardware-configuration.nix
        ))
        (builtins.mapAttrs (name: _: makeHost name (systemFromHardwareConf name)))
      ];
    };
}
