diff --git a/doc/manual/rl-next/nix-path-shadow-error.md b/doc/manual/rl-next/nix-path-shadow-error.md new file mode 100644 index 000000000..433ca7273 --- /dev/null +++ b/doc/manual/rl-next/nix-path-shadow-error.md @@ -0,0 +1,11 @@ +--- +synopsis: "Shadowing internal files through the Nix search path is now an error" +issues: [998] +cls: [4632, 5370] +category: "Breaking Changes" +credits: [thubrecht, jade, horrors] +--- + +As Lix uses the path `` for bootstrapping purposes, the ability to shadow it by adding `nix=/some/path` (or `/other/path` that contains a `nix` directory) to the search path is not desirable. + +Lix 2.95 deprecated this behavior with a warning, Lix 2.96 now turns it into a hard error if the `nix-path-shadow` deprecated feature isn't enabled. This deprecated feature is slated to be removed in Lix 2.98. diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 58a2e844f..b42dc0e7b 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -297,30 +297,29 @@ EvalPaths::EvalPaths( } } -#if LIX_MAJOR >= 3 || (LIX_MAJOR == 2 && LIX_MINOR >= 96) +#if LIX_MAJOR >= 3 || (LIX_MAJOR == 2 && LIX_MINOR >= 98) #warning \ - "The feature nix-path-shadow was deprecated in 2.95 with a warning, which needs to be turned into an error in 2.96" + "The feature nix-path-shadow was deprecated in 2.95 with a warning, error in 2.96, and we should consider removing the bypass in 2.98" #endif + if (!featureSettings.isEnabled(DeprecatedFeature::NixPathShadow)) { for (auto & [prefix, path] : searchPath_.elements) { // Match on the 'nix' prefix if (prefix.s == "nix") { - logWarning( - {.msg = HintFmt( - "The prefix '%s' is reserved for internal use by Lix in the Nix search " - "path, its usage is deprecated and will be forbidden in the future.\n" - "Use %s to silence this warning.\n" - "This is due to adding '%s=%s' in the Nix search path, either through the " - "environment variable '%s' or by passing the flag %s to the nix " - "invocation.", - "nix", - "--extra-deprecated-features nix-path-shadow", - prefix.s, - path.s, - "NIX_PATH", - "-I" - )} - ); + throw EvalError(HintFmt( + "The prefix '%s' is reserved for internal use by Lix in the Nix search " + "path, its usage is deprecated and will be forbidden in the future.\n" + "Use %s to silence this error.\n" + "This is due to adding '%s=%s' in the Nix search path, either through the " + "environment variable '%s' or by passing the flag %s to the nix " + "invocation.", + "nix", + "--extra-deprecated-features nix-path-shadow", + prefix.s, + path.s, + "NIX_PATH", + "-I" + )); } else // Match prefixless paths that contain a `nix` directory if (auto res = @@ -333,21 +332,19 @@ EvalPaths::EvalPaths( }); })) { - logWarning( - {.msg = HintFmt( - "Shadowing '%s' by configuring the nix-path is deprecated and " - "will be forbidden in the future.\n" - "Use %s to silence this warning.\n" - "This is due to adding '%s' to the nix-path without a prefix, " - "either by passing the flag '-I %s' to the nix invocation or by " - "adding this path to the environment variable '%s'.", - "", - "--extra-deprecated-features nix-path-shadow", - path.s, - path.s, - "NIX_PATH" - )} - ); + throw EvalError(HintFmt( + "Shadowing '%s' by configuring the nix-path is deprecated and " + "will be forbidden in the future.\n" + "Use %s to silence this error.\n" + "This is due to adding '%s' to the nix-path without a prefix, " + "either by passing the flag '-I %s' to the nix invocation or by " + "adding this path to the environment variable '%s'.", + "", + "--extra-deprecated-features nix-path-shadow", + path.s, + path.s, + "NIX_PATH" + )); } } } diff --git a/tests/functional2/lang/search-path/eval-okay-prefixed.err.exp b/tests/functional2/lang/search-path/eval-okay-prefixed.err.exp index 79b54f511..a2d44d53d 100644 --- a/tests/functional2/lang/search-path/eval-okay-prefixed.err.exp +++ b/tests/functional2/lang/search-path/eval-okay-prefixed.err.exp @@ -1,3 +1,3 @@ -warning: The prefix 'nix' is reserved for internal use by Lix in the Nix search path, its usage is deprecated and will be forbidden in the future. - Use --extra-deprecated-features nix-path-shadow to silence this warning. - This is due to adding 'nix=nix-shadow' in the Nix search path, either through the environment variable 'NIX_PATH' or by passing the flag -I to the nix invocation. +error: The prefix 'nix' is reserved for internal use by Lix in the Nix search path, its usage is deprecated and will be forbidden in the future. + Use --extra-deprecated-features nix-path-shadow to silence this error. + This is due to adding 'nix=nix-shadow' in the Nix search path, either through the environment variable 'NIX_PATH' or by passing the flag -I to the nix invocation. diff --git a/tests/functional2/lang/search-path/eval-okay-prefixless.err.exp b/tests/functional2/lang/search-path/eval-okay-prefixless.err.exp index cd78fe0f9..4b2fd1654 100644 --- a/tests/functional2/lang/search-path/eval-okay-prefixless.err.exp +++ b/tests/functional2/lang/search-path/eval-okay-prefixless.err.exp @@ -1,3 +1,3 @@ -warning: Shadowing '' by configuring the nix-path is deprecated and will be forbidden in the future. - Use --extra-deprecated-features nix-path-shadow to silence this warning. - This is due to adding 'nix-shadow' to the nix-path without a prefix, either by passing the flag '-I nix-shadow' to the nix invocation or by adding this path to the environment variable 'NIX_PATH'. +error: Shadowing '' by configuring the nix-path is deprecated and will be forbidden in the future. + Use --extra-deprecated-features nix-path-shadow to silence this error. + This is due to adding 'nix-shadow' to the nix-path without a prefix, either by passing the flag '-I nix-shadow' to the nix invocation or by adding this path to the environment variable 'NIX_PATH'. diff --git a/tests/functional2/lang/search-path/test_search_path.py b/tests/functional2/lang/search-path/test_search_path.py index 795099663..b71c2e117 100644 --- a/tests/functional2/lang/search-path/test_search_path.py +++ b/tests/functional2/lang/search-path/test_search_path.py @@ -1,7 +1,7 @@ from collections.abc import Callable from pathlib import Path -from lang.test_lang import test_eval_okay as nix_eval +from lang.test_lang import test_eval_fail as nix_eval_fail, test_eval_okay as nix_eval_okay from testlib.fixtures.file_helper import AssetSymlink, CopyFile, CopyTree, with_files from testlib.fixtures.nix import Nix from testlib.fixtures.snapshot import Snapshot @@ -21,7 +21,7 @@ from testlib.fixtures.snapshot import Snapshot ) def test_search_path(files: Path, nix: Nix, snapshot: Callable[[str], Snapshot]): nix.env.set_env("NIX_PATH", "dir3:dir4") - nix_eval( + nix_eval_okay( files, nix, [ @@ -43,12 +43,26 @@ def test_search_path(files: Path, nix: Nix, snapshot: Callable[[str], Snapshot]) "nix-shadow": CopyTree("nix-shadow"), "in.nix": CopyFile("in-fetchurl.nix"), "out.exp": AssetSymlink("eval-okay-prefixed.out.exp"), + } +) +def test_prefixed_search_path_deprecated( + files: Path, nix: Nix, snapshot: Callable[[str], Snapshot] +): + nix.env.set_env("NIX_PATH", "nix=nix-shadow") + nix.settings.add_dp_feature("nix-path-shadow") + nix_eval_okay(files, nix, [], snapshot) + + +@with_files( + { + "nix-shadow": CopyTree("nix-shadow"), + "in.nix": CopyFile("in-fetchurl.nix"), "err.exp": AssetSymlink("eval-okay-prefixed.err.exp"), } ) def test_prefixed_search_path(files: Path, nix: Nix, snapshot: Callable[[str], Snapshot]): nix.env.set_env("NIX_PATH", "nix=nix-shadow") - nix_eval(files, nix, [], snapshot) + nix_eval_fail(files, nix, [], snapshot) @with_files( @@ -56,11 +70,24 @@ def test_prefixed_search_path(files: Path, nix: Nix, snapshot: Callable[[str], S "nix-shadow": CopyTree("nix-shadow"), "in.nix": CopyFile("in-fetchurl.nix"), "out.exp": AssetSymlink("eval-okay-prefixless.out.exp"), + } +) +def test_prefixless_search_path_deprecated( + files: Path, nix: Nix, snapshot: Callable[[str], Snapshot] +): + nix.settings.add_dp_feature("nix-path-shadow") + nix_eval_okay(files, nix, ["-I", "nix-shadow"], snapshot) + + +@with_files( + { + "nix-shadow": CopyTree("nix-shadow"), + "in.nix": CopyFile("in-fetchurl.nix"), "err.exp": AssetSymlink("eval-okay-prefixless.err.exp"), } ) def test_prefixless_search_path(files: Path, nix: Nix, snapshot: Callable[[str], Snapshot]): - nix_eval(files, nix, ["-I", "nix-shadow"], snapshot) + nix_eval_fail(files, nix, ["-I", "nix-shadow"], snapshot) @with_files( @@ -71,4 +98,4 @@ def test_prefixless_search_path(files: Path, nix: Nix, snapshot: Callable[[str], } ) def test_empty_search_path(files: Path, nix: Nix, snapshot: Callable[[str], Snapshot]): - nix_eval(files, nix, [], snapshot) + nix_eval_okay(files, nix, [], snapshot) diff --git a/version.json b/version.json index badc2b321..48bfe26c4 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "2.95.0", + "version": "2.96.0-dev", "official_release": false, - "release_name": "Kakigōri" + "release_name": "TBD" }