{
  inputs = {
    # nixpkgs.url = "github:NixOS/nixpkgs/release-24.11";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

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

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

    t.url = "github:jdonszelmann/t-rs";
    dumpasm.url = "github:jdonszelmann/dumpasm";

    kitty-search = {
      url = "github:trygveaa/kitty-kitten-search";
      flake = false;
    };

    jujutsu = {
      url = "github:martinvonz/jj";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    p1n3appl3 = {
      url = "github:p1n3appl3/config";
      inputs.rahul-config.follows = "rahul-config";
    };
    rahul-config.url = "github:jdonszelmann/nix-config";

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

    niri-unstable.url = "github:YaLTeR/niri";
    niri = {
      url = "github:sodiboo/niri-flake";
      inputs.niri-unstable.follows = "niri-unstable";
    };
    matugen = {
      url = "github:/InioX/matugen/main";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    noctalia = {
      url = "github:noctalia-dev/noctalia-shell";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nixgl.url = "github:nix-community/nixGL";
    pipethon.url = "git+ssh://forgejo@git.donsz.nl/jana/pipethon.git";
  };

  outputs =
    {
      home-manager,
      nixpkgs,
      flake-utils,
      nixvim,
      t,
      dumpasm,
      jujutsu,
      nixgl,
      cosmic-manager,
      pipethon,
      niri,
      matugen,
      noctalia,
      ...
    }@inputs:
    let
      homeManagerModules = [
        nixvim.homeManagerModules.nixvim
        niri.homeModules.niri
        matugen.nixosModules.default
        noctalia.homeModules.default
      ];

      pkgsForSystem =
        system:
        import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          overlays = [
            nixgl.overlay
            (_: _: {
              custom = {
                t = t.packages.${system}.default;
                inherit (dumpasm.packages.${system}) dumpasm;
                inherit (jujutsu.packages.${system}) jujutsu;
                pipethon = pipethon.packages.${system}.python;
              };
              p1n3appl3 = inputs.p1n3appl3.packages.${system};
            })
          ];
        };
      mkHomeConfiguration =
        root: args:
        home-manager.lib.homeManagerConfiguration (
          {
            modules = [
              cosmic-manager.homeManagerModules.cosmic-manager
              root
            ]
            ++ homeManagerModules
            ++ (args.modules or [ ]);
            pkgs = pkgsForSystem (args.system or "x86_64-linux");
          }
          // {
            inherit (args) extraSpecialArgs;
          }
        );
    in
    flake-utils.lib.eachDefaultSystem (system: rec {
      formatter = legacyPackages.nixfmt-classic;
      legacyPackages = pkgsForSystem system;
      pkgs = legacyPackages;
      devShells.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          (pkgs.writeShellScriptBin "fast-repl" ''
            source /etc/set-environment
            nix repl --file "${./.}/repl.nix" $@
          '')

          (pkgs.writeShellScriptBin "apply-home" ''
            export NIX_BUILD_CORES=$(($(nproc) * 2))
            nix run .#home-manager -- switch --flake .#$@ -j $(nproc) --cores $(nproc)
          '')

          (pkgs.writeShellScriptBin "apply" ''
            apply-home $(hostname -f)
          '')
        ];
      };
    })
    // {

      homeConfigurations = {
        kili = mkHomeConfiguration (import ./hosts/kili/home.nix) {
          extraSpecialArgs = { inherit inputs; };
        };
        ori = mkHomeConfiguration (import ./hosts/ori/home.nix) {
          extraSpecialArgs = { inherit inputs; };
        };
        icecube = mkHomeConfiguration (import ./hosts/icecube/home.nix) {
          extraSpecialArgs = { inherit inputs; };
        };
      };

      inherit home-manager;
      inherit (home-manager) packages;
    };

  nixConfig = {
    extra-substituters = [ "https://jana.cachix.org" ];
    extra-trusted-public-keys = [
      "jana.cachix.org-1:LN0lzHx7QH1RBoDn3+psi4HOEAXW3EqRa/u0ncQ1XBE="
    ];
  };
}
