{
  description = "Nixos config flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    home-manager = {
      url = "github:nix-community/home-manager/release-25.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    plasma-manager = {
      url = "github:pjones/plasma-manager";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.home-manager.follows = "home-manager";
    };
    firefox-addons = {
      url = "gitlab:rycee/nur-expressions?dir=pkgs/firefox-addons";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    hyprland = {
      url = "github:hyprwm/Hyprland";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    hyprland-plugins = {
      url = "github:hyprwm/hyprland-plugins";
      inputs.hyprland.follows = "hyprland";
    };
    nixos-cosmic = {
      url = "github:lilyinstarlight/nixos-cosmic";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    dzgui-nix = {
      url = "github:lelgenio/dzgui-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    audio = {
      url = "github:polygon/audio.nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    nixpkgs,
    nixpkgs-unstable,
    nixos-hardware,
    home-manager,
    nixos-cosmic,
    audio,
    ...
  } @ inputs: let
    system = "x86_64-linux";
    overlay-unstable = final: prev: {
      unstable = import nixpkgs-unstable {
        system = prev.system;
        config.allowUnfree = true;
      };
    };
  in {
    nixosConfigurations = {
      comfy-station = nixpkgs.lib.nixosSystem {
        inherit system;
        specialArgs = {
          inherit inputs;
          isHM = false;
        };
        modules = [
          ({...}: {nixpkgs.overlays = [overlay-unstable self.overlays.default audio.overlays.default];})
          ({...}: {nixpkgs.config.allowUnfree = true;})
          nixos-hardware.nixosModules.msi-b550-a-pro
          inputs.sops-nix.nixosModules.sops
          ./modules
          ./hosts/comfy-station/configuration.nix
        ];
      };
      monolith = nixpkgs.lib.nixosSystem {
        inherit system;
        specialArgs = {
          inherit inputs;
          isHM = false;
        };
        modules = [
          ({...}: {nixpkgs.overlays = [overlay-unstable self.overlays.default audio.overlays.default];})
          ({...}: {
            nixpkgs.config.allowUnfree = true;
            nixpkgs.config.nvidia.acceptLicense = true;
          })
          {
            nix.settings = {
              substituters = ["https://cosmic.cachix.org/"];
              trusted-public-keys = ["cosmic.cachix.org-1:Dya9IyXD4xdBehWjrkPv6rtxpmMdRel02smYzA85dPE="];
            };
          }
          nixos-hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1
          inputs.sops-nix.nixosModules.sops
          nixos-cosmic.nixosModules.default
          ./modules
          ./hosts/monolith/configuration.nix
        ];
      };
      harbor = nixpkgs.lib.nixosSystem {
        inherit system;
        specialArgs = {
          inherit inputs;
          isHM = false;
        };
        modules = [
          ({...}: {nixpkgs.overlays = [overlay-unstable self.overlays.default audio.overlays.default];})
          ({...}: {nixpkgs.config.allowUnfree = true;})
          inputs.sops-nix.nixosModules.sops
          ./modules
          ./hosts/harbor/configuration.nix
        ];
      };
      vm = nixpkgs.lib.nixosSystem {
        inherit system;
        specialArgs = {
          inherit inputs;
        };
        modules = [
          ./hosts/vm/configuration.nix
        ];
      };
    };
    homeConfigurations."jonas@comfy-station" = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};

      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [
        ({...}: {nixpkgs.overlays = [overlay-unstable self.overlays.default audio.overlays.default];})
        ({...}: {nixpkgs.config.allowUnfree = true;})
        inputs.plasma-manager.homeManagerModules.plasma-manager
        inputs.sops-nix.homeManagerModules.sops
        ./modules
        (./home + "/jonas@comfy-station.nix")
      ];

      # Optionally use extraSpecialArgs
      # to pass through arguments to home.nix
      extraSpecialArgs = {
        inherit inputs;
        isHM = true;
      };
    };
    homeConfigurations."jonas@harbor" = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};

      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [
        ({...}: {nixpkgs.overlays = [overlay-unstable self.overlays.default audio.overlays.default];})
        ({...}: {nixpkgs.config.allowUnfree = true;})
        inputs.plasma-manager.homeManagerModules.plasma-manager
        inputs.sops-nix.homeManagerModules.sops
        ./modules
        (./home + "/jonas@harbor.nix")
      ];

      # Optionally use extraSpecialArgs
      # to pass through arguments to home.nix
      extraSpecialArgs = {
        inherit inputs;
        isHM = true;
      };
    };
    homeConfigurations."jonas@monolith" = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};

      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [
        ({...}: {nixpkgs.overlays = [overlay-unstable self.overlays.default audio.overlays.default];})
        ({...}: {nixpkgs.config.allowUnfree = true;})
        inputs.plasma-manager.homeManagerModules.plasma-manager
        inputs.sops-nix.homeManagerModules.sops
        ./modules
        (./home + "/jonas@monolith.nix")
      ];

      # Optionally use extraSpecialArgs
      # to pass through arguments to home.nix
      extraSpecialArgs = {
        inherit inputs;
        isHM = true;
      };
    };
    homeConfigurations."admin-jroeger" = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};

      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [
        ({...}: {nixpkgs.overlays = [overlay-unstable self.overlays.default audio.overlays.default];})
        ({...}: {nixpkgs.config.allowUnfree = true;})
        inputs.plasma-manager.homeManagerModules.plasma-manager
        inputs.sops-nix.homeManagerModules.sops
        ./modules
        ./home/admin-jroeger.nix
      ];

      # Optionally use extraSpecialArgs
      # to pass through arguments to home.nix
      extraSpecialArgs = {
        inherit inputs;
        isHM = true;
      };
    };

    devShells.${system} = {
      transcode-davinci-resolve = (import ./pkgs/transcode-davinci-resolve/shell.nix) {pkgs = nixpkgs.legacyPackages.${system};};
      spotify-shortcuts = (import ./pkgs/spotify-shortcuts/shell.nix) {pkgs = nixpkgs.legacyPackages.${system};};
    };

    overlays.default = import ./pkgs;

    templates = {
      rust = {
        path = ./templates/rust;
        description = "A simple rust binary template";
        welcomeText = ''
          # Rust template
          This is a simple rust binary template.
          To build the project run `cargo build`.
          To run the project run `cargo run`.
          Before running nix build, make sure to run `cargo generate-lockfile` first.
        '';
      };
    };
  };
}
