Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/manual/generate-dp-features-shortlist.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
with builtins;
with import <nix/utils.nix>;

let
showDeprecatedFeature = name: doc: ''
- [`${name}`](@docroot@/development/deprecated-features.md#dp-feature-${name})
'';
in
dps: indent " " (concatStrings (attrValues (mapAttrs showDeprecatedFeature dps)))
14 changes: 14 additions & 0 deletions doc/manual/generate-dp-features.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
with builtins;
with import <nix/utils.nix>;

let
showDeprecatedFeature =
name: doc:
squash ''
## [`${name}`]{#dp-feature-${name}}
${doc}
'';
in

dps: (concatStringsSep "\n" (attrValues (mapAttrs showDeprecatedFeature dps)))
8 changes: 7 additions & 1 deletion doc/manual/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ if get_option('html-manual')
nix3_cli_files,
experimental_features_shortlist_md,
experimental_feature_descriptions_md,
deprecated_features_shortlist_md,
deprecated_feature_descriptions_md,
types_dir,
conf_file_md,
builtins_md,
Expand Down Expand Up @@ -393,7 +395,11 @@ nix_manpages = [
'nix.conf',
5,
conf_file_md.full_path(),
[ conf_file_md, experimental_features_shortlist_md ],
[
conf_file_md,
experimental_features_shortlist_md,
deprecated_features_shortlist_md,
],
],
[ 'nix-daemon', 8 ],
[ 'nix-profiles', 5, 'files/profiles.md' ],
Expand Down
8 changes: 8 additions & 0 deletions doc/manual/rl-next/disallow-url-literals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
synopsis: Disallow URL literals
---

- URL literals (unquoted URLs) are now disabled by default in the Nix language.
They were previously optionally disallowable via the `no-url-literals` experimental feature, which has now been removed.
Existing Nix expressions containing URL literals must be updated to use quoted strings (e.g. `"http://example.com"` instead of `http://example.com`).
However, for transitional purposes, URL literals can be re-enabled using the new `url-literals` deprecated feature (e.g. `--extra-deprecated-features url-literals`).
1 change: 1 addition & 0 deletions doc/manual/source/SUMMARY.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
- [JSON guideline](development/json-guideline.md)
- [C++ style guide](development/cxx.md)
- [Experimental Features](development/experimental-features.md)
- [Deprecated Features](development/deprecated-features.md)
- [Contributing](development/contributing.md)
- [Releases](release-notes/index.md)
{{#include ./SUMMARY-rl-next.md}}
Expand Down
20 changes: 20 additions & 0 deletions doc/manual/source/command-ref/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ experimental_features_shortlist_md = custom_target(
env : nix_env_for_docs,
)

dp_features_json = custom_target(
command : [ nix, '__dump-dp-features' ],
capture : true,
output : 'dp-features.json',
env : nix_env_for_docs,
)

deprecated_features_shortlist_md = custom_target(
command : nix_eval_for_docs + [
'--expr', 'import @INPUT0@ (builtins.fromJSON (builtins.readFile ./@INPUT1@))',
],
input : [
'../../generate-dp-features-shortlist.nix',
dp_features_json,
],
output : 'deprecated-features-shortlist.md',
capture : true,
env : nix_env_for_docs,
)

nix3_cli_files = custom_target(
command : [ python.full_path(), '@INPUT0@', '@OUTPUT@', '--' ] + nix_eval_for_docs + [
'--expr', 'import @INPUT1@ true (builtins.readFile ./@INPUT2@)',
Expand Down
11 changes: 11 additions & 0 deletions doc/manual/source/development/deprecated-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This section describes the notion of *deprecated features*, and how it fits into the big picture of the development of Nix.

# What are deprecated features?

Deprecated features are legacy features that are scheduled for removal.
They are disabled by default but can be re-enabled by toggling the associated [deprecated feature flags](@docroot@/command-ref/conf-file.md#conf-deprecated-features).
This allows for a transition period where users can adapt their code.

# Deprecated feature descriptions

{{#include @generated@/development/deprecated-feature-descriptions.md}}
13 changes: 13 additions & 0 deletions doc/manual/source/development/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ experimental_feature_descriptions_md = custom_target(
env : nix_env_for_docs,
output : 'experimental-feature-descriptions.md',
)

deprecated_feature_descriptions_md = custom_target(
command : nix_eval_for_docs + [
'--expr', 'import @INPUT0@ (builtins.fromJSON (builtins.readFile @INPUT1@))',
],
input : [
'../../generate-dp-features.nix',
dp_features_json,
],
capture : true,
env : nix_env_for_docs,
output : 'deprecated-feature-descriptions.md',
)
5 changes: 3 additions & 2 deletions src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "nix/util/finally.hh"
#include "nix/util/util.hh"
#include "nix/util/users.hh"
#include "nix/util/configuration.hh"

#include "nix/expr/nixexpr.hh"
#include "nix/expr/eval.hh"
Expand Down Expand Up @@ -314,12 +315,12 @@ expr_simple
state->exprs.add<ExprString>(state->exprs.alloc, path)});
}
| URI {
static bool noURLLiterals = experimentalFeatureSettings.isEnabled(Xp::NoUrlLiterals);
if (noURLLiterals)
if (!experimentalFeatureSettings.isEnabled(DeprecatedFeature::UrlLiterals)) {
throw ParseError({
.msg = HintFmt("URL literals are disabled"),
.pos = state->positions[CUR_POS]
});
}
$$ = state->exprs.add<ExprString>(state->exprs.alloc, $1);
}
| '(' expr ')' { $$ = $2; }
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/config-global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ GlobalConfig::Register::Register(Config * config)
configRegistrations().emplace_back(config);
}

ExperimentalFeatureSettings experimentalFeatureSettings;
FeatureSettings experimentalFeatureSettings;

static GlobalConfig::Register rSettings(&experimentalFeatureSettings);

Expand Down
63 changes: 59 additions & 4 deletions src/libutil/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "nix/util/abstract-setting-to-json.hh"
#include "nix/util/environment-variables.hh"
#include "nix/util/experimental-features.hh"
#include "nix/util/deprecated-features.hh"
#include "nix/util/util.hh"
#include "nix/util/file-system.hh"

Expand Down Expand Up @@ -425,6 +426,36 @@ std::string BaseSetting<std::set<ExperimentalFeature>>::to_string() const
return concatStringsSep(" ", stringifiedXpFeatures);
}

template<>
std::set<DeprecatedFeature> BaseSetting<std::set<DeprecatedFeature>>::parse(const std::string & str) const
{
std::set<DeprecatedFeature> res;
for (auto & s : tokenizeString<StringSet>(str)) {
if (auto thisDpFeature = parseDeprecatedFeature(s); thisDpFeature)
res.insert(thisDpFeature.value());
else
warn("unknown deprecated feature '%s'", s);
}
return res;
}

template<>
void BaseSetting<std::set<DeprecatedFeature>>::appendOrSet(std::set<DeprecatedFeature> newValue, bool append)
{
if (!append)
value.clear();
value.insert(std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end()));
}

template<>
std::string BaseSetting<std::set<DeprecatedFeature>>::to_string() const
{
StringSet stringifiedDpFeatures;
for (const auto & feature : value)
stringifiedDpFeatures.insert(std::string(showDeprecatedFeature(feature)));
return concatStringsSep(" ", stringifiedDpFeatures);
}

template<>
StringMap BaseSetting<StringMap>::parse(const std::string & str) const
{
Expand Down Expand Up @@ -505,6 +536,7 @@ template class BaseSetting<Strings>;
template class BaseSetting<StringSet>;
template class BaseSetting<StringMap>;
template class BaseSetting<std::set<ExperimentalFeature>>;
template class BaseSetting<std::set<DeprecatedFeature>>;
template class BaseSetting<std::filesystem::path>;
template class BaseSetting<std::optional<std::filesystem::path>>;

Expand Down Expand Up @@ -548,24 +580,47 @@ void OptionalPathSetting::operator=(const std::optional<Path> & v)
this->assign(v);
}

bool ExperimentalFeatureSettings::isEnabled(const ExperimentalFeature & feature) const
bool FeatureSettings::isEnabled(const ExperimentalFeature & feature) const
{
auto & f = experimentalFeatures.get();
return std::find(f.begin(), f.end(), feature) != f.end();
}

void ExperimentalFeatureSettings::require(const ExperimentalFeature & feature, std::string reason) const
void FeatureSettings::require(const ExperimentalFeature & feature, std::string reason) const
{
if (!isEnabled(feature))
throw MissingExperimentalFeature(feature, std::move(reason));
}

bool ExperimentalFeatureSettings::isEnabled(const std::optional<ExperimentalFeature> & feature) const
bool FeatureSettings::isEnabled(const std::optional<ExperimentalFeature> & feature) const
{
return !feature || isEnabled(*feature);
}

void FeatureSettings::require(const std::optional<ExperimentalFeature> & feature) const
{
if (feature)
require(*feature);
}

bool FeatureSettings::isEnabled(const DeprecatedFeature & feature) const
{
auto & f = deprecatedFeatures.get();
return std::find(f.begin(), f.end(), feature) != f.end();
}

void FeatureSettings::require(const DeprecatedFeature & feature) const
{
if (!isEnabled(feature))
throw MissingDeprecatedFeature(feature);
}

bool FeatureSettings::isEnabled(const std::optional<DeprecatedFeature> & feature) const
{
return !feature || isEnabled(*feature);
}

void ExperimentalFeatureSettings::require(const std::optional<ExperimentalFeature> & feature) const
void FeatureSettings::require(const std::optional<DeprecatedFeature> & feature) const
{
if (feature)
require(*feature);
Expand Down
100 changes: 100 additions & 0 deletions src/libutil/deprecated-features.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "nix/util/deprecated-features.hh"
#include "nix/util/fmt.hh"
#include "nix/util/strings.hh"
#include "nix/util/util.hh"

#include <nlohmann/json.hpp>

namespace nix {

struct DeprecatedFeatureDetails
{
DeprecatedFeature tag;
std::string_view name;
std::string_view description;
};

// Add features here
constexpr std::array<DeprecatedFeatureDetails, 1> depFeatureDetails = {{{
.tag = DeprecatedFeature::UrlLiterals,
.name = "url-literals",
.description = R"(
Re-enable support for URL literals.
)",
}}};

const std::optional<DeprecatedFeature> parseDeprecatedFeature(const std::string_view & name)
{
using ReverseDepMap = std::map<std::string_view, DeprecatedFeature>;

static std::unique_ptr<ReverseDepMap> reverseDepMap = []() {
auto reverseDepMap = std::make_unique<ReverseDepMap>();
for (auto & depFeature : depFeatureDetails)
(*reverseDepMap)[depFeature.name] = depFeature.tag;
return reverseDepMap;
}();

if (auto feature = get(*reverseDepMap, name))
return *feature;
else
return std::nullopt;
}

std::string_view showDeprecatedFeature(const DeprecatedFeature tag)
{
for (const auto & detail : depFeatureDetails) {
if (detail.tag == tag)
return detail.name;
}
throw Error("Unknown deprecated feature tag");
}

nlohmann::json documentDeprecatedFeatures()
{
std::map<std::string, std::string> res;
for (auto & depFeature : depFeatureDetails)
res[std::string{depFeature.name}] = trim(stripIndentation(depFeature.description));
return (nlohmann::json) res;
}

std::set<DeprecatedFeature> parseDeprecatedFeatures(const std::set<std::string> & rawFeatures)
{
std::set<DeprecatedFeature> res;
for (auto & rawFeature : rawFeatures)
if (auto feature = parseDeprecatedFeature(rawFeature))
res.insert(*feature);
else
warn("unknown deprecated feature '%s'", rawFeature);
return res;
}

MissingDeprecatedFeature::MissingDeprecatedFeature(DeprecatedFeature feature)
: Error(
"Feature '%1%' is deprecated and should not be used anymore; use '--extra-deprecated-features %1%' to disable this error",
showDeprecatedFeature(feature))
, missingFeature(feature)
{
}

std::ostream & operator<<(std::ostream & str, const DeprecatedFeature & feature)
{
return str << showDeprecatedFeature(feature);
}

void to_json(nlohmann::json & j, const DeprecatedFeature & feature)
{
j = showDeprecatedFeature(feature);
}

void from_json(const nlohmann::json & j, DeprecatedFeature & feature)
{
const std::string input = j;
const auto parsed = parseDeprecatedFeature(input);

if (parsed.has_value())
feature = *parsed;
else
throw Error("Unknown deprecated feature '%s' in JSON input", input);
}

} // namespace nix
Loading
Loading