1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00
nix/tests
Jeremy Fleischman 929423476e
WIP: Allow for null packages and formatters
This is useful for frameworks (such as flake-parts) to avoid unnecessary
evaluation. See discussion here:
https://github.com/hercules-ci/flake-parts/issues/288#issuecomment-2912459614

While digging into this, I discovered that `nix fmt` already handles
`null` formatters identically to undefined formatters. I added a couple
of tests to demonstrate this behavior.

`nix flake show` needs some reworking to avoid crashing with a "error:
expected a derivation" when it encounters a `null` formatter or package.
My changes here avoid the crash, but has some cosmetic issues, which is why
I've labeled this PR as a draft.

Cosmetic issues
===============

With the following `flake.nix`:

```nix
{
  outputs = _: {
    packages.x86_64-linux.default = null;
  };
}
```

`nix flake show` shows a weird empty system:

```
$ nix flake show
path:/tmp/tmp.uL0iGuNwXB?lastModified=1748472558&narHash=sha256-tC%2BhdXAyoeFvWHNllJbois8X%2B7wpZ6CJzEzbcaGQxtM%3D
└───packages
    └───x86_64-linux
```

Similarly, `nix flake show --json` includes an empty object:

```
$ nix flake show --json
{
  "packages": {
    "x86_64-linux": {
      "default": null
    }
  }
}
```

`nix build` crashes:

```
$ nix build .#default
error: expected flake output attribute 'packages.x86_64-linux.default' to be a derivation or path but found null: null
```
2025-05-28 16:03:58 -07:00
..
functional WIP: Allow for null packages and formatters 2025-05-28 16:03:58 -07:00
installer Format .nix files 2025-01-24 17:04:02 +01:00
nixos Make the S3 test more robust 2025-05-24 01:30:51 +02:00
repl-completion.nix Format .nix files 2025-01-24 17:04:02 +01:00