{
  pkgs,
  lib,
  config,
  inputs',
  ...
}: let
  cfg = config.niko.dev.rust;
  rustToolchain = inputs'.fenix.packages.complete.withComponents [
    "cargo"
    "clippy"
    "llvm-tools-preview"
    "rust-analyzer-preview"
    "rust-src"
    "rust-std"
    "rustc"
    "rustfmt"
    "rustc-dev"
  ];
in {
  options.niko.dev.rust = {
    enable = lib.mkEnableOption "Rust toolchain";
    package = with lib;
      mkOption {
        type = types.package;
        default = rustToolchain;
        description = ''
          Rust toolchain package to use. It should contain all components you want to use.
          By default it will use 'pkgs.fenix.complete'
          so fenix overlay has to be enabled if this option isn't going to be changed.
        '';
      };
    mold = with lib;
      mkOption {
        type = types.bool;
        default = false;
        description = ''
          Whether to install and configure mold as the default linker.
          (May break some projects, especially when they require linking C libraries)
        '';
      };
    lldb = with lib;
      mkOption {
        type = types.bool;
        default = true;
        description = ''
          Whether to install and configure LLDB.
        '';
      };
    taplo = with lib;
      mkOption {
        type = types.bool;
        default = true;
        description = ''
          Whether to install and configure taplo (LSP and formatter for TOML).
        '';
      };
  };

  config =
    lib.mkIf cfg.enable
    {
      home.packages =
        [
          # pkgs.bintools
          cfg.package
          pkgs.stdenv.cc
        ]
        ++ (lib.optional cfg.lldb pkgs.lldb)
        ++ (lib.optionals cfg.mold [pkgs.clang pkgs.mold])
        ++ (lib.optional cfg.taplo inputs'.niko-nur.packages.taplo);

      home.file = lib.mkIf cfg.mold {
        ".cargo/config.toml".source = (pkgs.formats.toml {}).generate "cargo-config" {
          target.x86_64-unknown-linux-gnu = {
            linker = "clang";
            rustflags = ["-C" "link-arg=-fuse-ld=${pkgs.mold}/bin/mold"];
          };
        };
      };
    };
}