···11+# Tcl {#sec-language-tcl}
22+33+## User guide {#sec-language-tcl-user-guide}
44+55+Tcl interpreters are available under the `tcl` and `tcl-X_Y` attributes, where `X_Y` is the Tcl version.
66+77+Tcl libraries are available in the `tclPackages` attribute set.
88+They are only guaranteed to work with the default Tcl version, but will probably also work with others thanks to the [stubs mechanism](https://wiki.tcl-lang.org/page/Stubs).
99+1010+## Packaging guide {#sec-language-tcl-packaging}
1111+1212+Tcl packages are typically built with `tclPackages.mkTclDerivation`.
1313+Tcl dependencies go in `buildInputs`/`nativeBuildInputs`/... like other packages.
1414+For more complex package definitions, such as packages with mixed languages, use `tcl.tclPackageHook`.
1515+1616+Where possible, make sure to enable stubs for maximum compatibility, usually with the `--enable-stubs` configure flag.
1717+1818+Here is a simple package example to be called with `tclPackages.callPackage`.
1919+2020+```
2121+{ lib, fetchzip, mkTclDerivation, openssl }:
2222+2323+mkTclDerivation rec {
2424+ pname = "tcltls";
2525+ version = "1.7.22";
2626+2727+ src = fetchzip {
2828+ url = "https://core.tcl-lang.org/tcltls/uv/tcltls-${version}.tar.gz";
2929+ hash = "sha256-TOouWcQc3MNyJtaAGUGbaQoaCWVe6g3BPERct/V65vk=";
3030+ };
3131+3232+ buildInputs = [ openssl ];
3333+3434+ configureFlags = [
3535+ "--with-ssl-dir=${openssl.dev}"
3636+ "--enable-stubs"
3737+ ];
3838+3939+ meta = {
4040+ homepage = "https://core.tcl-lang.org/tcltls/index";
4141+ description = "OpenSSL / RSA-bsafe Tcl extension";
4242+ maintainers = [ lib.maintainers.agbrooks ];
4343+ license = lib.licenses.tcltk;
4444+ platforms = lib.platforms.unix;
4545+ };
4646+}
4747+```
4848+4949+All Tcl libraries are declared in `pkgs/top-level/tcl-packages.nix` and are defined in `pkgs/development/tcl-modules/`.
5050+If possible, prefer the by-name hierarchy in `pkgs/development/tcl-modules/by-name/`.
5151+Its use is documented in `pkgs/development/tcl-modules/by-name/README.md`.
5252+5353+All Tcl applications reside elsewhere.
5454+In case a package is used as both a library and an application (for example `expect`), it should be defined in `tcl-packages.nix`, with an alias elsewhere.