Skip to content

Commit

Permalink
Simplify nix_file_deps checking
Browse files Browse the repository at this point in the history
To check that dependencies of `nix_file_deps` are correctly declared,
we copy all declared dependencies into the external repository
directory. If any dependencies were missed, then nix evaluation will
fail.

To test that this really works, remove the

```
    nix_file_deps = ["//tests:pkgname.nix"],
```

line in `@nix-file-deps-test`. I tried writing a failure test for this
using Skylibs `analysistest` framework, but that doesn't seem to work
for failures in external repositories.

Like #76, this likewise closes #74, but in a simpler way.
  • Loading branch information
mboes committed Jul 20, 2019
1 parent e0be8ab commit 29691e2
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ def _nixpkgs_local_repository_impl(repository_ctx):
target = repository_ctx.path("default.nix")
else:
target = repository_ctx.path(repository_ctx.attr.nix_file)
repository_ctx.symlink(target, target.basename)
_cp(repository_ctx, target, target.basename)

# Make "@nixpkgs" (syntactic sugar for "@nixpkgs//:nixpkgs") a valid
# label for the target Nix file.
repository_ctx.symlink(target.basename, repository_ctx.name)

_symlink_nix_file_deps(repository_ctx, repository_ctx.attr.nix_file_deps)

nixpkgs_local_repository = repository_rule(
implementation = _nixpkgs_local_repository_impl,
attrs = {
Expand Down Expand Up @@ -91,15 +89,17 @@ def _nixpkgs_package_impl(repository_ctx):
if repository_ctx.attr.nix_file and repository_ctx.attr.nix_file_content:
fail("Specify one of 'nix_file' or 'nix_file_content', but not both.")
elif repository_ctx.attr.nix_file:
repository_ctx.symlink(repository_ctx.attr.nix_file, "default.nix")
_cp(repository_ctx, repository_ctx.path(repository_ctx.attr.nix_file), "default.nix")
elif repository_ctx.attr.nix_file_content:
expr_args = ["-E", repository_ctx.attr.nix_file_content]
elif not repositories:
fail(strFailureImplicitNixpkgs)
else:
expr_args = ["-E", "import <nixpkgs> { config = {}; overlays = []; }"]

_symlink_nix_file_deps(repository_ctx, repository_ctx.attr.nix_file_deps)
for dep in repository_ctx.attr.nix_file_deps:
path = repository_ctx.path(dep)
_cp(repository_ctx, path, path.basename)

expr_args.extend([
"-A",
Expand Down Expand Up @@ -349,9 +349,5 @@ def _executable_path(repository_ctx, exe_name, extra_msg = ""):
.format(exe_name, " " + extra_msg if extra_msg else ""))
return path

def _symlink_nix_file_deps(repository_ctx, deps):
"""Introduce an artificial dependency with a bogus name on each input."""
for dep in deps:
components = [c for c in [dep.workspace_root, dep.package, dep.name] if c]
link = "/".join(components).replace("_", "_U").replace("/", "_S")
repository_ctx.symlink(dep, link)
def _cp(repository_ctx, src, dest):
repository_ctx.template(dest, src, executable = False)

0 comments on commit 29691e2

Please sign in to comment.