{
  description = "Sealight NixOS Config";

  nixConfig = {
    extra-substituters = [ "https://cache.numtide.com" ];
    extra-trusted-public-keys = [ "niks3.numtide.com-1:DTx8wZduET09hRmMtKdQDxNNthLQETkc/yaX7M4qK0g=" ];
  };

  inputs = {
    # Nixpkgs
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
    unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";

    # ngipkgs.url = "github:Chickensoupwithrice/ngipkgs?ref=aynish/atomic-server-module";
    # ngipkgs-local.url = "path:/home/anish/usr/ngipkgs";

    # Home manager
    home-manager.url = "github:nix-community/home-manager/release-25.05";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    hardware.url = "github:nixos/nixos-hardware";

    # Tools
    agenix.url = "github:ryantm/agenix";
    agenix.inputs.nixpkgs.follows = "nixpkgs";
    deploy-rs.url = "github:serokell/deploy-rs";
    deploy-rs.inputs.nixpkgs.follows = "nixpkgs";
    disko.url = "github:nix-community/disko";
    disko.inputs.nixpkgs.follows = "nixpkgs";

    # My Packages
    poonam.url = "git+ssh://gitea@git.sealight.xyz/aynish/kitaab?ref=main";
    poonam.inputs.nixpkgs.follows = "nixpkgs";
    basant.url = "git+ssh://gitea@git.sealight.xyz/aynish/basant?ref=main";
    vimwikicli.url =
      "git+ssh://gitea@git.sealight.xyz/aynish/vimwiki-cli?ref=main";
    basant.inputs.nixpkgs.follows = "nixpkgs";
    basant.inputs.poonam.follows = "poonam";
    vimwikicli.inputs.nixpkgs.follows = "nixpkgs";
    grasp.url = "git+ssh://gitea@git.sealight.xyz/aynish/grasp.git?ref=main";
    grasp.inputs.nixpkgs.follows = "nixpkgs";

    # Matrix
    nix-matrix-appservices.url = "gitlab:coffeetables/nix-matrix-appservices";

    # Darwin
    darwin = {
      url = "github:LnL7/nix-darwin/nix-darwin-25.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-homebrew = {
      url = "github:zhaofengli-wip/nix-homebrew";
    };
    homebrew-bundle = {
      url = "github:homebrew/homebrew-bundle";
      flake = false;
    };
    homebrew-core = {
      url = "github:homebrew/homebrew-core";
      flake = false;
    };
    homebrew-cask = {
      url = "github:homebrew/homebrew-cask";
      flake = false;
    };

    # Steam Deck / Gaming
    jovian = {
      url = "github:Jovian-Experiments/Jovian-NixOS";
      inputs.nixpkgs.follows = "unstable";
    };

    # Tangled (atproto tools)
    tangled = {
      url = "git+https://tangled.org/@tangled.org/core";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    # LLM Agents
    llm-agents.url = "github:numtide/llm-agents.nix";

    # Others
    nur.url = "github:nix-community/NUR";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    tidalcycles.url = "github:mitchmindtree/tidalcycles.nix";
    tidalcycles.inputs.nixpkgs.follows = "unstable";
    autohide-tdrop = {
      url = "github:I-Want-ToBelieve/autohide-tdrop";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    # TODO hundred rabbits software
    # TODO needs secrets
    # dhyan.url = "git+ssh://gitea@git.sealight.xyz/aynish/dhyan?ref=main";
    # dhyan.inputs.nixpkgs.follows = "nixpkgs";
    # TODO needs secrets
    # muneem.url = "git+ssh://gitea@git.sealight.xyz/aynish/muneem?ref=main";
    # muneem.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, unstable, nixos-hardware, home-manager, deploy-rs
    , agenix, disko, basant, grasp, nix-matrix-appservices, nur, tidalcycles
    , rust-overlay, vimwikicli, autohide-tdrop, darwin, nix-homebrew, homebrew-bundle
    , homebrew-core, homebrew-cask, jovian, tangled, llm-agents, ... }@inputs:
    let
      forAllSystems = nixpkgs.lib.genAttrs [
        "aarch64-linux"
        "i686-linux"
        "x86_64-linux"
        "aarch64-darwin"
        "x86_64-darwin"
      ];
      unstableOverlay = final: prev: {
        # We already have these in scope
        unstable = unstable.legacyPackages.${prev.system};
        deploy = deploy-rs.packages.${prev.system}.deploy-rs;
      };
      vimwikiOverlay = final: prev: {
        vimwiki-cli = vimwikicli.packages.${prev.system}.vimwiki-cli;
        autohide-tdrop = autohide-tdrop.packages.${prev.system}.default;
      };

      nixpkgsFor = forAllSystems (system:
        import nixpkgs {
          inherit system;
          config = {
            permittedInsecurePackages = [
              "olm-3.2.16" 
            ];
            allowUnfreePredicate = pkg:
              builtins.elem (nixpkgs.lib.getName pkg) [
                "ripcord"
                "vcv-rack"
                "SunVox"
                "renoise"
                "bitwig-studio-unwrapped"
              ];
          };
          overlays = [
            rust-overlay.overlays.default
            tidalcycles.overlays.default
            agenix.overlays.default
            nur.overlay
            # nix-matrix-appservices.overlay # nixpkgs has these packages and newer ones at that
            unstableOverlay
            vimwikiOverlay
            self.overlays.additions
            self.overlays.modifications
          ];
        });

      # for when space matters
      litePkgsFor = forAllSystems (system:
        import nixpkgs {
          inherit system;
          # config.permittedInsecurePackages = [
          #   "forgejo-1.19.4-0" # Needed for archivebox deployments on curve
          #   # Check when archive box updates it's dependeny
          # ];
          overlays = [
            agenix.overlays.default
            tangled.overlays.default # atproto tools only on lite deployments
            self.overlays.additions
            self.overlays.modifications
            tidalcycles.overlays.default # needed for nvim which comes pre-installed lol
          ];
        });

      # Package set for Darwin systems  
      darwinPkgsFor = forAllSystems (system:
        import nixpkgs {
          inherit system;
          config = {
            permittedInsecurePackages = [
              "olm-3.2.16" 
            ];
            allowUnfreePredicate = pkg:
              builtins.elem (nixpkgs.lib.getName pkg) [
                "ripcord"
                "vcv-rack"
                "SunVox"
                "renoise"
              ];
          };
          overlays = [
            rust-overlay.overlays.default
            tidalcycles.overlays.default
            agenix.overlays.default
            nur.overlay
            unstableOverlay
            vimwikiOverlay
            self.overlays.additions
            self.overlays.modifications
          ];
        });

      # Package set for Steam Deck (gaming-focused)
      deckPkgsFor = forAllSystems (system:
        import unstable {
          inherit system;
          config = {
            permittedInsecurePackages = [
              "olm-3.2.16" 
            ];
            allowUnfreePredicate = pkg:
              builtins.elem (nixpkgs.lib.getName pkg) [
                "ripcord"
                "vcv-rack"
                "SunVox"
                "renoise"
                "steam"
                "steam-original"
                "steam-runtime"
                "steamdeck-hw-theme"
                "steam-jupiter-unwrapped"
              ];
          };
          overlays = [
            rust-overlay.overlays.default
            tidalcycles.overlays.default
            agenix.overlays.default
            nur.overlay
            unstableOverlay
            vimwikiOverlay
            self.overlays.additions
            self.overlays.modifications
          ];
        });
    in {
      # Your custom packages
      # Acessible through 'nix build', 'nix shell', etc
      packages = forAllSystems (system:
        let pkgs = nixpkgsFor.${system};
        in import ./pkgs { pkgs = pkgs; });
      # Devshell for bootstrapping
      # Acessible through 'nix develop' or 'nix-shell' (legacy)
      devShells = forAllSystems (system:
        let pkgs = nixpkgsFor.${system};
        in import ./shell.nix { pkgs = pkgs; });

      # Your custom packages and modifications, exported as overlays
      overlays = import ./overlays;
      # Reusable nixos modules you might want to export
      # These are usually stuff you would upstream into nixpkgs
      nixosModules = import ./modules/nixos;
      # Reusable home-manager modules you might want to export
      # These are usually stuff you would upstream into home-manager
      homeManagerModules = import ./modules/home-manager;

      # NixOS configuration entrypoint
      nixosConfigurations = {
        curve = nixpkgs.lib.nixosSystem rec {
          specialArgs = { inherit inputs self; };
          system = "x86_64-linux";
          pkgs = nixpkgsFor.${system};
          modules = [
            ./hosts/curve
            agenix.nixosModules.age
            self.nixosModules.backup
            self.nixosModules.wireguard
            self.nixosModules.wallabag
            nixos-hardware.nixosModules.lenovo-thinkpad-x270
            home-manager.nixosModules.home-manager
            {
              nix.registry.nixpkgs.flake = nixpkgs;
              nix.registry.unstable.flake = unstable;
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.extraSpecialArgs = { inherit inputs; };
              home-manager.users.anish = import ./home/gui;
            }
          ];
        };

        helix = nixpkgs.lib.nixosSystem rec {
          specialArgs = { inherit inputs self; };
          system = "x86_64-linux";
          pkgs = litePkgsFor.${system};
          modules = [
            ./hosts/helix
            agenix.nixosModules.age
            self.nixosModules.backup
            self.nixosModules.wireguard
            basant.nixosModule
            # self.nixosModules.microbin
            disko.nixosModules.disko
            {
              nixpkgs.flake.setNixPath = false;
              nixpkgs.flake.setFlakeRegistry = false;
            }
          ];
        };

        lituus = nixpkgs.lib.nixosSystem rec {
          specialArgs = { inherit inputs self; };
          system = "x86_64-linux";
          pkgs = nixpkgsFor.${system};
          modules = [
            ./hosts/lituus
            agenix.nixosModules.age
            self.nixosModules.backup
            self.nixosModules.hesienbridge
            nix-matrix-appservices.nixosModule
            home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.anish = import ./home/core;
            }
          ];
        };

        box = nixpkgs.lib.nixosSystem rec {
          specialArgs = { inherit inputs self; };
          system = "x86_64-linux";
          pkgs = nixpkgsFor.${system};
          modules = [
            ./hosts/box
            agenix.nixosModules.age
            self.nixosModules.backup
            self.nixosModules.wireguard
            self.nixosModules.gonic
            self.nixosModules.gpodder2go
            self.nixosModules.wallabag
            self.nixosModules.ulogger-server
            grasp.nixosModule
            home-manager.nixosModules.home-manager
            {
              nix.registry.nixpkgs.flake = nixpkgs;
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.extraSpecialArgs = { inherit inputs; };
              home-manager.users.anish = import ./home/dev;
            }
          ];
        };

        # new version of unstable has many changes I couldn't be bothered to deal with rn
        #deck = unstable.lib.nixosSystem rec {
        #  specialArgs = { inherit inputs self; };
        #  system = "x86_64-linux";
        #  pkgs = deckPkgsFor.${system};
        #  modules = [
        #    ./hosts/deck
        #    jovian.nixosModules.default
        #    self.nixosModules.wireguard
        #    agenix.nixosModules.age
        #    self.nixosModules.backup
        #    home-manager.nixosModules.home-manager
        #    {
        #      nix.registry.nixpkgs.flake = unstable;
        #      home-manager.useGlobalPkgs = true;
        #      home-manager.useUserPackages = true;
        #      home-manager.users.anish = import ./home/gui;
        #    }
        #  ];
        #};
      };

      # Darwin configuration entrypoint  
      darwinConfigurations = {
        "Anishs-MacBook-Pro" = darwin.lib.darwinSystem rec {
          system = "aarch64-darwin";
          pkgs = darwinPkgsFor.${system};
          specialArgs = { inherit inputs self; };
          modules = [
            ./hosts/darwin
            home-manager.darwinModules.home-manager
            agenix.darwinModules.default
            {
              users.users.anishlakhwara.home = "/Users/anishlakhwara";
              home-manager = {
                users.anishlakhwara = import ./home/darwin;
                useGlobalPkgs = true;
                useUserPackages = true;
                extraSpecialArgs = { inherit inputs; };
              };
            }
          ];
        };
      };

      # Standalone home-manager configuration entrypoint
      # Available through 'home-manager --flake .#your-username@your-hostname'
      homeConfigurations = {
        "anish@work" = home-manager.lib.homeManagerConfiguration {
          pkgs =
            nixpkgsFor."x86_64-linux"; # Home-manager requires 'pkgs' instance
          extraSpecialArgs = { inherit inputs; };
          modules = [ ./home/core.nix ./home/profiles/firefox ];
        };
      };

      deploy.nodes = {
        box = {
          hostname = "mossnet.lan";
          autoRollback = false;
          magicRollback = false;
          remoteBuild = true;
          profiles.system = {
            user = "root";
            path = deploy-rs.lib.x86_64-linux.activate.nixos
              self.nixosConfigurations.box;
          };
        };
        lituus = {
          hostname = "67.219.99.225";
          autoRollback = false;
          remoteBuild = true;
          profiles.system = {
            user = "root";
            path = deploy-rs.lib.x86_64-linux.activate.nixos
              self.nixosConfigurations.lituus;
          };
        };
        helix = {
          hostname = "git.sealight.xyz";
          autoRollback = false;
          magicRollback = false;
          profiles.system = {
            user = "root";
            path = deploy-rs.lib.x86_64-linux.activate.nixos
              self.nixosConfigurations.helix;
          };
        };
      };

     # checks = builtins.mapAttrs
     #   (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
    };
}
