Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression test for relative imports
Invocations of `nixpkgs_package` with a Nix file that refers to other files by relative path into a separate directory, e.g. `./foo/bar.nix`, or `../baz.nix` fail with `No such file or directory`. The reason is that `nixpkgs_package` will flatten the directory hierarchy of files defined in `nix_file_deps`. See the following error: ``` $ nix-shell --pure --run 'bazel test //tests:run-relative-imports' ERROR: /home/aj/tweag.io/da/bazel-projects/rules_nixpkgs/tests/BUILD.bazel:7:5: no such package '@relative-imports//': Traceback (most recent call last): File "/home/aj/tweag.io/da/bazel-projects/rules_nixpkgs/nixpkgs/nixpkgs.bzl", line 149 _execute_or_fail(repository_ctx, nix_build, failure_m...), ...) File "/home/aj/tweag.io/da/bazel-projects/rules_nixpkgs/nixpkgs/nixpkgs.bzl", line 318, in _execute_or_fail fail("\n{failure_message}\nCommand: {...)) Cannot build Nix attribute 'hello'. Command: [/nix/store/zw52rvbzhh6x447yc0hn3w7s0wmcq3pw-nix-2.2.2/bin/nix-build, "-A", "hello", "--out-link", "bazel-support/nix-out-link", "-I", "nixpkgs=/home/aj/.cache/bazel/_bazel_aj/cf7431ac3fb5fc6f4c6a5569d7b55e4a/external/nixpkgs/nixpkgs"] Return code: 1 Error output: error: getting status of '/home/aj/.cache/bazel/_bazel_aj/cf7431ac3fb5fc6f4c6a5569d7b55e4a/external/relative-imports/relative_imports/nixpkgs.nix': No such file or directory and referenced by '//tests:run-relative-imports' ERROR: Analysis of target '//tests:run-relative-imports' failed; build aborted: no such package '@relative-imports//': Traceback (most recent call last): File "/home/aj/tweag.io/da/bazel-projects/rules_nixpkgs/nixpkgs/nixpkgs.bzl", line 149 _execute_or_fail(repository_ctx, nix_build, failure_m...), ...) File "/home/aj/tweag.io/da/bazel-projects/rules_nixpkgs/nixpkgs/nixpkgs.bzl", line 318, in _execute_or_fail fail("\n{failure_message}\nCommand: {...)) Cannot build Nix attribute 'hello'. Command: [/nix/store/zw52rvbzhh6x447yc0hn3w7s0wmcq3pw-nix-2.2.2/bin/nix-build, "-A", "hello", "--out-link", "bazel-support/nix-out-link", "-I", "nixpkgs=/home/aj/.cache/bazel/_bazel_aj/cf7431ac3fb5fc6f4c6a5569d7b55e4a/external/nixpkgs/nixpkgs"] Return code: 1 Error output: error: getting status of '/home/aj/.cache/bazel/_bazel_aj/cf7431ac3fb5fc6f4c6a5569d7b55e4a/external/relative-imports/relative_imports/nixpkgs.nix': No such file or directory ```
- Loading branch information