···1+# Tcl {#sec-language-tcl}
2+3+## User guide {#sec-language-tcl-user-guide}
4+5+Tcl interpreters are available under the `tcl` and `tcl-X_Y` attributes, where `X_Y` is the Tcl version.
6+7+Tcl libraries are available in the `tclPackages` attribute set.
8+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).
9+10+## Packaging guide {#sec-language-tcl-packaging}
11+12+Tcl packages are typically built with `tclPackages.mkTclDerivation`.
13+Tcl dependencies go in `buildInputs`/`nativeBuildInputs`/... like other packages.
14+For more complex package definitions, such as packages with mixed languages, use `tcl.tclPackageHook`.
15+16+Where possible, make sure to enable stubs for maximum compatibility, usually with the `--enable-stubs` configure flag.
17+18+Here is a simple package example to be called with `tclPackages.callPackage`.
19+20+```
21+{ lib, fetchzip, mkTclDerivation, openssl }:
22+23+mkTclDerivation rec {
24+ pname = "tcltls";
25+ version = "1.7.22";
26+27+ src = fetchzip {
28+ url = "https://core.tcl-lang.org/tcltls/uv/tcltls-${version}.tar.gz";
29+ hash = "sha256-TOouWcQc3MNyJtaAGUGbaQoaCWVe6g3BPERct/V65vk=";
30+ };
31+32+ buildInputs = [ openssl ];
33+34+ configureFlags = [
35+ "--with-ssl-dir=${openssl.dev}"
36+ "--enable-stubs"
37+ ];
38+39+ meta = {
40+ homepage = "https://core.tcl-lang.org/tcltls/index";
41+ description = "OpenSSL / RSA-bsafe Tcl extension";
42+ maintainers = [ lib.maintainers.agbrooks ];
43+ license = lib.licenses.tcltk;
44+ platforms = lib.platforms.unix;
45+ };
46+}
47+```
48+49+All Tcl libraries are declared in `pkgs/top-level/tcl-packages.nix` and are defined in `pkgs/development/tcl-modules/`.
50+If possible, prefer the by-name hierarchy in `pkgs/development/tcl-modules/by-name/`.
51+Its use is documented in `pkgs/development/tcl-modules/by-name/README.md`.
52+53+All Tcl applications reside elsewhere.
54+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.