# Why does this code work without rec {}?

**URL:** https://discourse.nixos.org/t/why-does-this-code-work-without-rec/23608
**Category:** Help
**Created:** [December 1, 2022, 9:11am UTC](https://discourse.nixos.org/t/why-does-this-code-work-without-rec/23608 "2022-12-01T09:11:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zanc](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@zanc](https://discourse.nixos.org/u/zanc)
#### Post date: [December 1, 2022, 9:11am UTC](https://discourse.nixos.org/t/why-does-this-code-work-without-rec/23608/1 "2022-12-01T09:11:51Z")

</div>

I’m talking about this code:

> <https://github.com/NixOS/nixpkgs/blob/fecf05d4861f3985e8dee73f08bc82668ef75125/pkgs/top-level/linux-kernels.nix#L569>

If it’s not obvious, it’s basically:

```auto
{
  packages = {
    linux_5_10 = ...;
    linux_5_15 = ...;
  };

  packageAliases = {
    linux_default = if stdenv.hostPlatform.isi686 then packages.linux_5_10 else packages.linux_5_15;
  };
}

```

The things inside `packageAliases` can somehow access `packages` without `rec {}`.

Where it should’ve been:

```auto
rec {
  packages = {
    linux_5_10 = ...;
    linux_5_15 = ...;
  };

  packageAliases = {
    linux_default = if stdenv.hostPlatform.isi686 then packages.linux_5_10 else packages.linux_5_15;
  };
}

```

---

<div class="post-metadata">

### Author: ![raphi](https://discourse.nixos.org/user_avatar/discourse.nixos.org/raphi/32/6291_2.png) [@raphi](https://discourse.nixos.org/u/raphi)
#### Post date: [December 1, 2022, 9:34am UTC](https://discourse.nixos.org/t/why-does-this-code-work-without-rec/23608/2 "2022-12-01T09:34:33Z")

</div>

Fix point magic:

[linux-kernels.nix](https://github.com/NixOS/nixpkgs/blob/fecf05d4861f3985e8dee73f08bc82668ef75125/pkgs/top-level/linux-kernels.nix#L22) starts with `with linuxKernel;`. This means that `packages ` will be resolved to `linuxKernel.packages`.

[all-packages.nix](https://raw.githubusercontent.com/NixOS/nixpkgs/fecf05d4861f3985e8dee73f08bc82668ef75125/pkgs/top-level/all-packages.nix) defines linuxKernel as `linuxKernel = recurseIntoAttrs (callPackage ./linux-kernels.nix { });`. This means that the `linuxKernel` argument in linux-kernels.nix is whatever linux-kernels.nix itself returns.

This basically simplifies to:

```auto
$ cat linux-kernels.nix
linuxKernels:
with linuxKernels;

{
  a = 1;
  b = a + 1;
}

$ cat test.nix
let lib = import <nixpkgs/lib>;
in

lib.fix (import ./linux-kernels.nix)

$ nix-instantiate --eval --strict test.nix
{ a = 1; b = 2; }

```
