{ inputs, lib, ... }:

{
  nix = {
    settings = {
      # Enable experimental features for modern Nix commands and flakes
      experimental-features = [ "nix-command" "flakes" ];
      
      # Allow users in the wheel group to manage the Nix store
      trusted-users = [ "root" "@wheel" ];
      
      # Optimize storage by hard-linking identical files
      auto-optimise-store = lib.mkDefault true;
    };

    # Populates NIX_PATH with the nixpkgs input from the flake.
    # This is critical for making 'nix-shell -p ...' and other legacy
    # Nix commands work in a flake-based environment without channels.
    nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];

    # Map all flake inputs to the system registry.
    # This ensures 'nix shell nixpkgs#...' uses the exact same version
    # as the rest of the system and doesn't need to re-download.
    registry = lib.mapAttrs (_: value: { flake = value; }) inputs;
  };
}
