Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

test_provide_builtins failing on macOS when matching against nix --version output #75

Open
lilyball opened this issue Jan 6, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@lilyball
Copy link

lilyball commented Jan 6, 2022

Describe the bug

Building rnix-lsp v0.2.3 against recent nixpkgs (NixOS/nixpkgs@77fda7f) on macOS fails with

thread 'lookup::tests::test_provide_builtins' panicked at 'called `Option::unwrap()` on a `None` value', src/lookup.rs:185:48

It looks like it's failing to run a regex on the nix --version output:

rnix-lsp/src/lookup.rs

Lines 174 to 185 in 1665bc6

let nixver = process::Command::new("nix").args(&["--version"]).output();
// `nix __dump-builtins` is only supported on `nixUnstable` a.k.a. Nix 2.4.
// Thus, we have to check if this is actually available. If not, `rnix-lsp` will fall
// back to a hard-coded list of builtins which is missing additional info such as documentation
// or parameter names though.
match nixver {
Ok(out) => {
match str::from_utf8(&out.stdout) {
Ok(v) => {
let re = regex::Regex::new(r"^nix \(Nix\) (?P<major>\d)\.(?P<minor>\d).*").unwrap();
let m = re.captures(v).unwrap();

Interestingly, cache.nixos.org has binary artifacts for it, though this seems intermittent (on a slightly older revision of nixpkgs, cache.nixos.org had binary artifacts for aarch64-apple-darwin but not for x86_64-apple-darwin; for the referenced version it has artifacts for both. The failure occurs on both architectures though).

Build log
> nix log /nix/store/ngwa65ypzm6gzpgq671fk50iv77bi2a5-rnix-lsp-0.2.3.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/dav99d7fcksybhpfpyy9qmxz1c8r5b07-source
source root is source
Executing cargoSetupPostUnpackHook
unpacking source archive /nix/store/6hgjnhc7qdswn9khscmqmkzkpz2bjsic-rnix-lsp-0.2.3-vendor.tar.gz
Finished cargoSetupPostUnpackHook
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
Executing cargoSetupPostPatchHook
Validating consistency between /private/tmp/nix-build-rnix-lsp-0.2.3.drv-0/source//Cargo.lock and /private/tmp/nix-build-rnix-lsp-0.2.3.drv-0/rnix-lsp-0.2.3-vendor.tar.gz/Cargo.lock
Finished cargoSetupPostPatchHook
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Executing cargoBuildHook
++ env CC_x86_64-apple-darwin=/nix/store/a2sz5pfcilnp7hw9hhqipvs3rvq3s59v-clang-wrapper-11.1.0/bin/cc CXX_x86_64-apple-darwin=/nix/store/a2sz5pfcilnp7hw9hhqipvs3rvq3s59v-clang-wrapper-11.1.0/bin/c++ CC_x86_64-apple-darwin=/nix/store/a2sz5pfcilnp7hw9hhqipvs3rvq3s59v-clang-wrapper-11.1.0/bin/cc CXX_x86_64-apple-darwin=/nix/store/a2sz5pfcilnp7hw9hhqipvs3rvq3s59v-clang-wrapper-11.1.0/bin/c++ cargo build -j 16 --target x86_64-apple-darwin --frozen --release
   Compiling proc-macro2 v1.0.29
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.75
   Compiling serde_derive v1.0.130
   Compiling autocfg v1.0.1
   Compiling serde v1.0.130
   Compiling memchr v2.4.1
   Compiling cfg-if v1.0.0
   Compiling libc v0.2.101
   Compiling log v0.4.14
   Compiling lazy_static v1.4.0
   Compiling crossbeam-utils v0.8.5
   Compiling ryu v1.0.5
   Compiling serde_json v1.0.67
   Compiling regex-syntax v0.6.25
   Compiling tinyvec_macros v0.1.0
   Compiling itoa v0.4.8
   Compiling matches v0.1.9
   Compiling percent-encoding v2.1.0
   Compiling same-file v1.0.6
   Compiling rustc-hash v1.1.0
   Compiling hashbrown v0.9.1
   Compiling unicode-bidi v0.3.6
   Compiling once_cell v1.9.0
   Compiling cfg-if v0.1.10
   Compiling fnv v1.0.7
   Compiling bitflags v1.3.2
   Compiling countme v2.0.4
   Compiling unicode-width v0.1.9
   Compiling smol_str v0.1.18
   Compiling strsim v0.8.0
   Compiling vec_map v0.8.2
   Compiling ansi_term v0.12.1
   Compiling humantime v2.1.0
   Compiling termcolor v1.1.2
   Compiling tinyvec v1.3.1
   Compiling form_urlencoded v1.0.1
   Compiling walkdir v2.3.2
   Compiling crossbeam-utils v0.6.6
   Compiling thread_local v1.1.3
   Compiling textwrap v0.11.0
   Compiling num-traits v0.2.14
   Compiling memoffset v0.6.4
   Compiling crossbeam-channel v0.3.9
   Compiling crossbeam-channel v0.5.1
   Compiling unicode-normalization v0.1.19
   Compiling aho-corasick v0.7.18
   Compiling bstr v0.2.17
   Compiling atty v0.2.14
   Compiling dirs-sys v0.3.6
   Compiling quote v1.0.9
   Compiling clap v2.34.0
   Compiling dirs v3.0.2
   Compiling idna v0.2.3
   Compiling regex v1.5.4
   Compiling cbitset v0.2.0
   Compiling globset v0.4.8
   Compiling env_logger v0.9.0
   Compiling ignore v0.4.18
   Compiling serde_repr v0.1.7
   Compiling text-size v1.1.0
   Compiling url v2.2.2
   Compiling rowan v0.12.6
   Compiling rnix v0.10.1
   Compiling lsp-types v0.89.2
   Compiling lsp-server v0.5.2
   Compiling nixpkgs-fmt-rnix v1.2.0
   Compiling rnix-lsp v0.2.3 (/private/tmp/nix-build-rnix-lsp-0.2.3.drv-0/source)
    Finished release [optimized] target(s) in 48.20s
Executing cargoInstallPostBuildHook
Finished cargoInstallPostBuildHook
Finished cargoBuildHook
@nix { "action": "setPhase", "phase": "checkPhase" }
running tests
Executing cargoCheckHook
++ cargo test -j 16 --release --target x86_64-apple-darwin --frozen -- --test-threads=16
   Compiling rnix-lsp v0.2.3 (/private/tmp/nix-build-rnix-lsp-0.2.3.drv-0/source)
    Finished release [optimized] target(s) in 2.72s
     Running unittests (target/x86_64-apple-darwin/release/deps/rnix_lsp-fa2f5f71aacc1669)

running 17 tests
test lookup::tests::test_provide_builtins_non_mac ... ignored
test lookup::tests::test_builtin_fallback ... ok
test lookup::tests::test_builtin_from_dump_builtins ... ok
test utils::tests::test_get_offset_from_nix_expr ... ok
test utils::tests::test_lookup_pos_in_expr ... ok
test utils::tests::test_ident_attr_path ... ok
test utils::tests::test_offset_across_multiple_lines ... ok
test utils::tests::test_lookup_pos_out_of_range ... ok
test utils::tests::test_find_ident ... ok
test utils::tests::test_inherit_ident ... ok
test utils::tests::test_offset_too_large - should panic ... ok
test lookup::tests::test_ident_traverse_attr_path ... ok
test lookup::tests::test_suggest_let_in_variable ... ok
test lookup::tests::test_find_inherit_scope ... ok
test utils::tests::test_populate_scope ... ok
test utils::tests::test_populate_scope_legacy_let ... ok
test lookup::tests::test_provide_builtins ... FAILED

failures:

---- lookup::tests::test_provide_builtins stdout ----
thread 'lookup::tests::test_provide_builtins' panicked at 'called `Option::unwrap()` on a `None` value', src/lookup.rs:185:48


failures:
    lookup::tests::test_provide_builtins

test result: FAILED. 15 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.09s

error: test failed, to rerun pass '--bin rnix-lsp'

Steps to reproduce

Steps to reproduce the behavior:

  1. nix build --rebuild github:NixOS/nixpkgs/77fda7f672726e1a95c8cd200f27bccfc86c870b#rnix-lsp

Expected behavior

It should compile.

Additional context

  • Operating system: macOS 12 (both x86_64-apple-darwin and aarch64-apple-darwin)
@lilyball lilyball added the bug Something isn't working label Jan 6, 2022
@lilyball
Copy link
Author

lilyball commented Jan 6, 2022

I can't reproduce this in a nix develop shell or with nix-shell. If I patch the source to print the nix --version output and run that through nix build I get v = "".

@lilyball
Copy link
Author

lilyball commented Jan 6, 2022

Here's the whole nixver result struct, which is quite interesting:

rnix-lsp> [src/lookup.rs:175] &nixver = Ok(
rnix-lsp>     Output {
rnix-lsp>         status: ExitStatus(
rnix-lsp>             unix_wait_status(
rnix-lsp>                 6,
rnix-lsp>             ),
rnix-lsp>         ),
rnix-lsp>         stdout: "",
rnix-lsp>         stderr: "libc++abi: terminating with uncaught exception of type nix::SysError: \u{1b}[31;1merror:\u{1b}[0m getting status of \u{1b}[35;1m/System/Library/LaunchDaemons/com.apple.oahd.plist\u{1b}[0m: \u{1b}[35;1mOperation not permitted\u{1b}[0m\n",
rnix-lsp>     },
rnix-lsp> )

@lilyball
Copy link
Author

lilyball commented Jan 6, 2022

If this is a sandboxing issue, that explains why it doesn't reproduce in nix develop or nix-shell. What I don't get is why this still occurs with nix --no-sandbox build. Or why nix is attempting to get the file metadata of /System/Library/LaunchDaemons/com.apple.oahd.plist.

@lilyball
Copy link
Author

lilyball commented Jan 7, 2022

I filed NixOS/nix#5884 about nix --version failing in the macOS sandbox.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant