diff --git a/WORKSPACE b/WORKSPACE index 02db25031..9cf74d716 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -36,7 +36,7 @@ nixpkgs_package( nixpkgs_package( name = "expr-test", - nix_file_content = "let pkgs = import {}; in pkgs.hello", + nix_file_content = "let pkgs = import { config = {}; overlays = []; }; in pkgs.hello", # Deliberately not @nixpkgs, to test whether explict file works. repositories = {"nixpkgs": "//:nixpkgs.nix"}, ) @@ -50,7 +50,7 @@ nixpkgs_package( nixpkgs_package( name = "expr-attribute-test", attribute_path = "hello", - nix_file_content = "import {}", + nix_file_content = "import { config = {}; overlays = []; }", repository = "@nixpkgs", ) @@ -77,7 +77,7 @@ nixpkgs_package( nixpkgs_package( name = "extra-args-test", nix_file_content = """ -{ packagePath }: (import {}).${packagePath} +{ packagePath }: (import { config = {}; overlays = []; }).${packagePath} """, repository = "@nixpkgs", nixopts = ["--argstr", "packagePath", "hello"], diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index 007856996..0ceaa8fc4 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -97,7 +97,7 @@ def _nixpkgs_package_impl(repository_ctx): elif not repositories: fail(strFailureImplicitNixpkgs) else: - expr_args = ["-E", "import {}"] + expr_args = ["-E", "import { config = {}; overlays = []; }"] _symlink_nix_file_deps(repository_ctx, repository_ctx.attr.nix_file_deps) @@ -185,11 +185,9 @@ def _nixpkgs_package_impl(repository_ctx): # We ignore some files: # - Anything in /nix/store, they are not explicit dependencies are are supposed to be immutable # - Anything from .cache/bazel, only case I encountered was a local nixpkgs clone handled by bazel - # - .config/nixpkgs. user configuration should not impact the reproducibility of the build if ( not line[2].startswith("'/nix/store") and ".cache/bazel" not in line[2] - and ".config/nixpkgs" not in line[2] ): filename = line[2][1:-1] # trimming quotes @@ -241,6 +239,9 @@ nix_file_deps = [ "{deps_listing}", ] +Note: if it points to the nixpkgs global configuration file, such as ~/.config/nixpkgs/config.nix. You must force nixpkgs to not use the local configuration, by providing at least a `config` and `overlays` arguments to your nixpkgs import, such as: + +import (nixpkgs_path) {{ config = {{}}; overlays = {{}}; }}; """.format(repo_name = repository_ctx.name, deps_listing = '",\n "'.join(deps_minus_declared_deps.keys()))) @@ -371,7 +372,7 @@ def nixpkgs_cc_configure( """ if not nix_file and not nix_file_content: nix_file_content = """ - with import {}; buildEnv { + with import { config = {}; overlays = []; }; buildEnv { name = "bazel-cc-toolchain"; paths = [ stdenv.cc binutils ]; } diff --git a/shell.nix b/shell.nix index 23b3e10da..4a213dcc2 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ -{ pkgs ? import ./nixpkgs.nix {} }: +{ pkgs ? import ./nixpkgs.nix { config = {}; overlays = []; } }: with pkgs; diff --git a/tests/hello.nix b/tests/hello.nix index 285e93f7e..338b17a44 100644 --- a/tests/hello.nix +++ b/tests/hello.nix @@ -1,3 +1,3 @@ with import ./pkgname.nix; -let pkgs = import {}; in builtins.getAttr pkgname pkgs +let pkgs = import { config = {}; overlays = []; }; in builtins.getAttr pkgname pkgs diff --git a/tests/nixpkgs.nix b/tests/nixpkgs.nix index cdd1f58f0..fb0b6757c 100644 --- a/tests/nixpkgs.nix +++ b/tests/nixpkgs.nix @@ -1 +1 @@ -import {} +import { config = {}; overlays = []; } diff --git a/tests/output.nix b/tests/output.nix index a0269adb6..1c88f6063 100644 --- a/tests/output.nix +++ b/tests/output.nix @@ -1,4 +1,4 @@ -with import {}; +with import { config = {}; overlays = []; }; runCommand "some-output" { preferLocalBuild = true;