NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.79k stars 1.52k forks source link

value is a thunk while a Boolean was expected #6955

Open ElvishJerricco opened 2 years ago

ElvishJerricco commented 2 years ago

Describe the bug

When trying to use --debugger and builtins.break, I sometimes get error: value is a thunk while a Boolean was expected, causing evaluation to fail when it wouldn't have without builtins.break.

Steps To Reproduce

# foo.nix
let set = { value = true; }; in if (builtins.break set.value) then "has value" else "no has value"
$ nix eval -f foo.nix --debugger
info: breakpoint reached

      at /home/will/github/nix/foo.nix:1:37:

           1| let set = { value = true; }; in if (builtins.break set.value) then "has value" else "no has value"
            |                                     ^

Starting REPL to allow you to inspect the current state of the evaluator.

Welcome to Nix 2.10.3. Type :? for help.

nix-repl> :c
error: value is a thunk while a Boolean was expected

       at /home/will/github/nix/foo.nix:1:33:

            1| let set = { value = true; }; in if (builtins.break set.value) then "has value" else "no has value"
             |                                 ^

Starting REPL to allow you to inspect the current state of the evaluator.

Welcome to Nix 2.10.3. Type :? for help.

nix-repl> :c
error: value is a thunk while a Boolean was expected

       at /home/will/github/nix/foo.nix:1:33:

            1| let set = { value = true; }; in if (builtins.break set.value) then "has value" else "no has value"
             |                                 ^
(use '--show-trace' to show detailed location information)

$ echo $?
1

Expected behavior

Should have evaluated to "has value" without errors.

nix-env --version output

nix-env (Nix) 2.10.3

dermetfan commented 1 year ago

This is not limited to if. It also affect builtins.toJSON, for example:

❯ cat test.nix
builtins.toJSON { x = builtins.break {}; }
❯ nix run github:nixos/nix/2.12-maintenance -- eval --debugger --file ./test.nix
info: breakpoint reached

      at …/test.nix:1:16:

           1| builtins.toJSON { x = builtins.break {}; }
            |                ^

Starting REPL to allow you to inspect the current state of the evaluator.

Welcome to Nix 2.12.1. Type :? for help.

nix-repl> :c
error: cannot convert a thunk to JSON

       at …/test.nix:1:12:

            1| builtins.toJSON { x = builtins.break {}; }
             |            ^

Starting REPL to allow you to inspect the current state of the evaluator.

Welcome to Nix 2.12.1. Type :? for help.

nix-repl> :c
error: cannot convert a thunk to JSON

       at …/test.nix:1:12:

            1| builtins.toJSON { x = builtins.break {}; }
             |            ^
(use '--show-trace' to show detailed location information)

This snippet evaluates fine (1 instead of {}):

builtins.toJSON { x = builtins.break 1; }