{
  description = "Configuration flake for RandomCTF";

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

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

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

  outputs = { self, nixpkgs, home, nix-unstable, home-unstable, nix-index-database, ... } @ inputs:
    let
      mkNixosConfig = hostname: modules: nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = { inherit inputs; };
        inherit modules;
      };

      mkHomeConfig = username: modules: home.lib.homeManagerConfiguration {
        pkgs = import nixpkgs {
          system = "x86_64-linux";
        };

        extraSpecialArgs = {
          inherit inputs;
          user = username;
        };

        inherit modules;
      };

      mkNixosUnstableConfig = hostname: modules: nix-unstable.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = { inherit inputs; };
        inherit modules;
      };

      mkHomeUnstableConfig = username: modules: home-unstable.lib.homeManagerConfiguration {
        pkgs = import nix-unstable {
          system = "x86_64-linux";
        };

        extraSpecialArgs = {
          inherit inputs;
          user = username;
        };

        inherit modules;
      };
    in {

      # Nixos Configurations
      nixosConfigurations = {
        randomctf = mkNixosUnstableConfig "randomctf" [ ./config/shared.nix ./config/omen.nix ];
        r330-media = mkNixosConfig "r330-media" [ ./config/media.nix ];
        sampledb-dev = mkNixosConfig "sampledb-dev" [ ./config/sampledb.nix ];
        r330-logging = mkNixosConfig "r330-logging" [ ./config/logging.nix ];
        mindforge = mkNixosConfig "mindforge" [ ./config/ai.nix ];
      };

      # Home-Manager Configurations
      homeConfigurations = {
        random = mkHomeUnstableConfig "random" [
          ./home/headful-nixos.nix
          ./home/modules/development.nix
          ./home/modules/gui-apps.nix
          ./home/modules/hacking.nix
        ];

        sampledb = mkHomeConfig "sampledb" [
          ./home/headless-nixos.nix
          ./home/modules/development.nix
        ];

        media = mkHomeConfig "media" [ ./home/headless-nixos.nix ];
        logging = mkHomeConfig "logging" [ ./home/headless-nixos.nix ];
        mindforge = mkHomeConfig "mindforge" [ ./home/headless-nixos.nix ];
      };
    };
}
