Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix call to repository_ctx.file using nix_file_content with nixpkgs_local_repository #210

Merged
merged 2 commits into from
Apr 1, 2022

Conversation

avdv
Copy link
Member

@avdv avdv commented Mar 29, 2022

ERROR: An error occurred during the fetch of repository 'nixpkgs':
   Traceback (most recent call last):
	File "/home/claudio/.cache/bazel/_bazel_claudio/c7ff5b30a595e0e5def985dcafaa7d4c/external/io_tweag_rules_nixpkgs/nixpkgs/nixpkgs.bzl", line 54, column 28, in _nixpkgs_local_repository_impl
		repository_ctx.file(
Error in file: file() got named argument for positional-only parameter 'path'

Fixes #140.

@avdv
Copy link
Member Author

avdv commented Mar 29, 2022

Would be nice to add some example / test for this...

@fricklerhandwerk fricklerhandwerk changed the title Fix call to repository_ctx.file using nix_content_file with nixpkgs_local_repository Fix call to repository_ctx.file using nix_file_content with nixpkgs_local_repository Mar 31, 2022
@fricklerhandwerk
Copy link
Member

How did you reproduce this? We have repository rules used for tests that exercise nix_file_content.

@avdv
Copy link
Member Author

avdv commented Mar 31, 2022

How did you reproduce this? We have repository rules used for tests that exercise nix_file_content.

There is no test for nixpkgs_local_repository with nix_file_content. The error can be seen with:

nixpkgs_local_repository(
    name = "nixpkgs",
    nix_file_content = "...",
    nix_file_deps = [],
)

@fricklerhandwerk
Copy link
Member

fricklerhandwerk commented Mar 31, 2022

That makes for a test.

diff --git a/WORKSPACE b/WORKSPACE
index 82dc73e..29a07d2 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -51,6 +51,12 @@ nixpkgs_local_repository(
     nix_file_deps = ["//:nixpkgs.json"],
 )
 
+nixpkgs_local_repository(
+    name = "local_nixpkgs",
+    nix_file_content = "import <nixpkgs> { config = {}; overlays = []; }",
+    nix_file_deps = ["//:nixpkgs.json"],
+)
+
 # This is the commit introducing a Nix version working in the Bazel
 # sandbox
 nixpkgs_git_repository(
@@ -72,6 +78,12 @@ nixpkgs_package(
     repositories = {"nixpkgs": "@remote_nixpkgs"},
 )
 
+nixpkgs_package(
+    name = "nixpkgs-local-repository-test",
+    nix_file_content = "with import <nixpkgs> {}; hello",
+    repositories = {"nixpkgs": "@local_nixpkgs"},
+)
+
 nixpkgs_package(
     name = "hello",
     # Deliberately not repository, to test whether repositories works.
diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel
index 7e02357..a9ed1d2 100644
--- a/tests/BUILD.bazel
+++ b/tests/BUILD.bazel
@@ -27,6 +27,7 @@ expand_location_unit_test_suite()
         "nix-file-test",
         "nix-file-deps-test",
         "nixpkgs-git-repository-test",
+        "nixpkgs-local-repository-test",
         "relative-imports",
     ]
 ] + [

But it produces a new error...

ERROR: An error occurred during the fetch of repository 'local_nixpkgs':
   Traceback (most recent call last):
	File "/private/var/tmp/_bazel_tweag/0060e94eb8cc5b3692d332a00756b8a8/external/rules_nixpkgs_core/nixpkgs.bzl", line 102, column 61, in _nixpkgs_local_repository_impl
		repository_ctx.file("nix-file-deps", content = "\n".join(repository_files))
Error in join: expected string for sequence element 0, got 'path'

Using `nixpkgs_local_repository` with the `nix_file_content` parameter:

```
nixpkgs_local_repository(
    name = "nixpkgs",
    nix_file_content = "...",
    nix_file_deps = [],
)
```

resulted in an error:

```
ERROR: An error occurred during the fetch of repository 'nixpkgs':
   Traceback (most recent call last):
	File "/home/claudio/.cache/bazel/_bazel_claudio/c7ff5b30a595e0e5def985dcafaa7d4c/external/io_tweag_rules_nixpkgs/nixpkgs/nixpkgs.bzl", line 54, column 28, in _nixpkgs_local_repository_impl
		repository_ctx.file(
Error in file: file() got named argument for positional-only parameter 'path'
```

After the call to `repository_ctx.file` was fixed, another error showed up:

```
ERROR: An error occurred during the fetch of repository 'local_nixpkgs':
   Traceback (most recent call last):
	File "/private/var/tmp/_bazel_tweag/0060e94eb8cc5b3692d332a00756b8a8/external/rules_nixpkgs_core/nixpkgs.bzl", line 102, column 61, in _nixpkgs_local_repository_impl
		repository_ctx.file("nix-file-deps", content = "\n".join(repository_files))
Error in join: expected string for sequence element 0, got 'path'
```

Fixes #140.
@avdv avdv force-pushed the fix-named-arg-for-file-140 branch from cc0043f to 6845598 Compare April 1, 2022 06:35
@avdv avdv marked this pull request as ready for review April 1, 2022 06:36
@avdv
Copy link
Member Author

avdv commented Apr 1, 2022

That makes for a test.

Thank you, @fricklerhandwerk I just re-used the existing nixpkgs definition for the sake of simplicity, and because I did not want to rely on global <nixpkgs>.

But it produces a new error...

ERROR: An error occurred during the fetch of repository 'local_nixpkgs':
   Traceback (most recent call last):
	File "/private/var/tmp/_bazel_tweag/0060e94eb8cc5b3692d332a00756b8a8/external/rules_nixpkgs_core/nixpkgs.bzl", line 102, column 61, in _nixpkgs_local_repository_impl
		repository_ctx.file("nix-file-deps", content = "\n".join(repository_files))
Error in join: expected string for sequence element 0, got 'path'

Fixed too.

@fricklerhandwerk fricklerhandwerk added the merge-queue merge on green CI label Apr 1, 2022
@mergify mergify bot merged commit c9a0897 into master Apr 1, 2022
@mergify mergify bot deleted the fix-named-arg-for-file-140 branch April 1, 2022 07:34
@mergify mergify bot removed the merge-queue merge on green CI label Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test the nix_file_content attribute of the nixpkgs_local_repository rule
2 participants