Skip to content

Commit

Permalink
Fix error using nix_file_content with nixpkgs_local_repository
Browse files Browse the repository at this point in the history
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 tweag#140.
  • Loading branch information
avdv committed Apr 1, 2022
1 parent aeeabee commit 6845598
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ nixpkgs_local_repository(
nix_file_deps = ["//:nixpkgs.json"],
)

# same as @nixpkgs but using the `nix_file_content` parameter
nixpkgs_local_repository(
name = "nixpkgs_content",
nix_file_content = "import ./nixpkgs.nix",
nix_file_deps = ["//:nixpkgs.nix", "//:nixpkgs.json"],
)

# This is the commit introducing a Nix version working in the Bazel
# sandbox
nixpkgs_git_repository(
Expand All @@ -72,6 +79,12 @@ nixpkgs_package(
repositories = {"nixpkgs": "@remote_nixpkgs"},
)

nixpkgs_package(
name = "nixpkgs-local-repository-test",
nix_file_content = "with import <nixpkgs> {}; hello",
repositories = {"nixpkgs": "@nixpkgs_content"},
)

nixpkgs_package(
name = "hello",
# Deliberately not repository, to test whether repositories works.
Expand Down
4 changes: 2 additions & 2 deletions core/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def _nixpkgs_local_repository_impl(repository_ctx):
bool(repository_ctx.attr.nix_file_content):
fail("Specify one of 'nix_file' or 'nix_file_content' (but not both).")
if repository_ctx.attr.nix_file_content:
target = "default.nix"
repository_ctx.file(
path = "default.nix",
target,
content = repository_ctx.attr.nix_file_content,
executable = False,
)
target = repository_ctx.path("default.nix")
else:
target = cp(repository_ctx, repository_ctx.attr.nix_file)

Expand Down
1 change: 1 addition & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
] + [
Expand Down

0 comments on commit 6845598

Please sign in to comment.