Home Explore Blog Models CI



nixpkgs

doc/languages-frameworks/hy.section.md
c7d48d0b64069ba2dee06c663c29d2784a6d6b98408281ee000000030000049d
# Hy {#sec-language-hy}

## Installation {#ssec-hy-installation}

### Installation without packages {#installation-without-packages}

You can install `hy` via nix-env or by adding it to `configuration.nix` by referring to it as a `hy` attribute. This kind of installation adds `hy` to your environment and it successfully works with `python3`.

::: {.caution}
Packages that are installed with your python derivation, are not accessible by `hy` this way.
:::

### Installation with packages {#installation-with-packages}

Creating a `hy` derivation with custom `python` packages is really simple and similar to the way that python does it. The attribute `hy` provides the function `withPackages` that creates a custom `hy` derivation with specified packages.

For example, if you want to create a shell with `matplotlib` and `numpy`, you can do it like so:

```ShellSession
$ nix-shell -p "hy.withPackages (ps: with ps; [ numpy matplotlib ])"
```

Or if you want to extend your `configuration.nix`:
```nix
{
  # ...

  environment.systemPackages = with pkgs; [
    (hy.withPackages (
      py-packages: with py-packages; [
        numpy
        matplotlib
      ]
    ))
  ];
}
```

Chunks
86badb40 (1st chunk of `doc/languages-frameworks/hy.section.md`)
Title: Hy Installation Methods
Summary
This section details two methods for installing 'Hy', a Lisp-like language for Python, within a Nix environment. The first method, 'installation without packages,' involves adding the `hy` attribute via `nix-env` or `configuration.nix`, which makes it compatible with `python3` but restricts access to custom Python packages. The second method, 'installation with packages,' describes how to create a custom `hy` derivation that includes specified Python packages (e.g., `numpy`, `matplotlib`) using the `hy.withPackages` function, providing examples for both `nix-shell` and `configuration.nix`.