Skip to content

Rename nix profile install to nix profile add #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2025
Merged
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
2 changes: 0 additions & 2 deletions doc/manual/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ nix3_manpages = [
'nix3-print-dev-env',
'nix3-profile-diff-closures',
'nix3-profile-history',
'nix3-profile-install',
'nix3-profile-list',
'nix3-profile',
'nix3-profile-remove',
Expand Down Expand Up @@ -283,7 +282,6 @@ nix3_manpages = [
'nix3-store',
'nix3-store-optimise',
'nix3-store-path-from-hash-part',
'nix3-store-ping',
'nix3-store-prefetch-file',
'nix3-store-repair',
'nix3-store-sign',
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ RawInstallablesCommand::RawInstallablesCommand()
void RawInstallablesCommand::applyDefaultInstallables(std::vector<std::string> & rawInstallables)
{
if (rawInstallables.empty()) {
// FIXME: commands like "nix profile install" should not have a
// FIXME: commands like "nix profile add" should not have a
// default, probably.
rawInstallables.push_back(".");
}
Expand Down
21 changes: 21 additions & 0 deletions src/libutil/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,25 @@ nlohmann::json MultiCommand::toJSON()
return res;
}

Strings::iterator MultiCommand::rewriteArgs(Strings & args, Strings::iterator pos)
{
if (command)
return command->second->rewriteArgs(args, pos);

if (aliasUsed || pos == args.end()) return pos;
auto arg = *pos;
auto i = aliases.find(arg);
if (i == aliases.end()) return pos;
auto & info = i->second;
if (info.status == AliasStatus::Deprecated) {
warn("'%s' is a deprecated alias for '%s'",
arg, concatStringsSep(" ", info.replacement));
}
pos = args.erase(pos);
for (auto j = info.replacement.rbegin(); j != info.replacement.rend(); ++j)
pos = args.insert(pos, *j);
aliasUsed = true;
return pos;
}

}
22 changes: 22 additions & 0 deletions src/libutil/include/nix/util/args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,30 @@ public:

nlohmann::json toJSON() override;

enum struct AliasStatus {
/** Aliases that don't go away */
AcceptedShorthand,
/** Aliases that will go away */
Deprecated,
};

/** An alias, except for the original syntax, which is in the map key. */
struct AliasInfo {
AliasStatus status;
std::vector<std::string> replacement;
};

/**
* A list of aliases (remapping a deprecated/shorthand subcommand
* to something else).
*/
std::map<std::string, AliasInfo> aliases;

Strings::iterator rewriteArgs(Strings & args, Strings::iterator pos) override;

protected:
std::string commandName = "";
bool aliasUsed = false;
};

Strings argvToStrings(int argc, char * * argv);
Expand Down
83 changes: 25 additions & 58 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ void chrootHelper(int argc, char * * argv);

namespace nix {

enum struct AliasStatus {
/** Aliases that don't go away */
AcceptedShorthand,
/** Aliases that will go away */
Deprecated,
};

/** An alias, except for the original syntax, which is in the map key. */
struct AliasInfo {
AliasStatus status;
std::vector<std::string> replacement;
};

/* Check if we have a non-loopback/link-local network interface. */
static bool haveInternet()
{
Expand Down Expand Up @@ -151,54 +138,34 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
.category = miscCategory,
.handler = {[&]() { refresh = true; }},
});
}

std::map<std::string, AliasInfo> aliases = {
{"add-to-store", { AliasStatus::Deprecated, {"store", "add-path"}}},
{"cat-nar", { AliasStatus::Deprecated, {"nar", "cat"}}},
{"cat-store", { AliasStatus::Deprecated, {"store", "cat"}}},
{"copy-sigs", { AliasStatus::Deprecated, {"store", "copy-sigs"}}},
{"dev-shell", { AliasStatus::Deprecated, {"develop"}}},
{"diff-closures", { AliasStatus::Deprecated, {"store", "diff-closures"}}},
{"dump-path", { AliasStatus::Deprecated, {"store", "dump-path"}}},
{"hash-file", { AliasStatus::Deprecated, {"hash", "file"}}},
{"hash-path", { AliasStatus::Deprecated, {"hash", "path"}}},
{"ls-nar", { AliasStatus::Deprecated, {"nar", "ls"}}},
{"ls-store", { AliasStatus::Deprecated, {"store", "ls"}}},
{"make-content-addressable", { AliasStatus::Deprecated, {"store", "make-content-addressed"}}},
{"optimise-store", { AliasStatus::Deprecated, {"store", "optimise"}}},
{"ping-store", { AliasStatus::Deprecated, {"store", "info"}}},
{"sign-paths", { AliasStatus::Deprecated, {"store", "sign"}}},
{"shell", { AliasStatus::AcceptedShorthand, {"env", "shell"}}},
{"show-derivation", { AliasStatus::Deprecated, {"derivation", "show"}}},
{"show-config", { AliasStatus::Deprecated, {"config", "show"}}},
{"to-base16", { AliasStatus::Deprecated, {"hash", "to-base16"}}},
{"to-base32", { AliasStatus::Deprecated, {"hash", "to-base32"}}},
{"to-base64", { AliasStatus::Deprecated, {"hash", "to-base64"}}},
{"verify", { AliasStatus::Deprecated, {"store", "verify"}}},
{"doctor", { AliasStatus::Deprecated, {"config", "check"}}},
aliases = {
{"add-to-store", { AliasStatus::Deprecated, {"store", "add-path"}}},
{"cat-nar", { AliasStatus::Deprecated, {"nar", "cat"}}},
{"cat-store", { AliasStatus::Deprecated, {"store", "cat"}}},
{"copy-sigs", { AliasStatus::Deprecated, {"store", "copy-sigs"}}},
{"dev-shell", { AliasStatus::Deprecated, {"develop"}}},
{"diff-closures", { AliasStatus::Deprecated, {"store", "diff-closures"}}},
{"dump-path", { AliasStatus::Deprecated, {"store", "dump-path"}}},
{"hash-file", { AliasStatus::Deprecated, {"hash", "file"}}},
{"hash-path", { AliasStatus::Deprecated, {"hash", "path"}}},
{"ls-nar", { AliasStatus::Deprecated, {"nar", "ls"}}},
{"ls-store", { AliasStatus::Deprecated, {"store", "ls"}}},
{"make-content-addressable", { AliasStatus::Deprecated, {"store", "make-content-addressed"}}},
{"optimise-store", { AliasStatus::Deprecated, {"store", "optimise"}}},
{"ping-store", { AliasStatus::Deprecated, {"store", "info"}}},
{"sign-paths", { AliasStatus::Deprecated, {"store", "sign"}}},
{"shell", { AliasStatus::AcceptedShorthand, {"env", "shell"}}},
{"show-derivation", { AliasStatus::Deprecated, {"derivation", "show"}}},
{"show-config", { AliasStatus::Deprecated, {"config", "show"}}},
{"to-base16", { AliasStatus::Deprecated, {"hash", "to-base16"}}},
{"to-base32", { AliasStatus::Deprecated, {"hash", "to-base32"}}},
{"to-base64", { AliasStatus::Deprecated, {"hash", "to-base64"}}},
{"verify", { AliasStatus::Deprecated, {"store", "verify"}}},
{"doctor", { AliasStatus::Deprecated, {"config", "check"}}},
};
};

bool aliasUsed = false;

Strings::iterator rewriteArgs(Strings & args, Strings::iterator pos) override
{
if (aliasUsed || command || pos == args.end()) return pos;
auto arg = *pos;
auto i = aliases.find(arg);
if (i == aliases.end()) return pos;
auto & info = i->second;
if (info.status == AliasStatus::Deprecated) {
warn("'%s' is a deprecated alias for '%s'",
arg, concatStringsSep(" ", info.replacement));
}
pos = args.erase(pos);
for (auto j = info.replacement.rbegin(); j != info.replacement.rend(); ++j)
pos = args.insert(pos, *j);
aliasUsed = true;
return pos;
}

std::string description() override
{
return "a tool for reproducible and declarative configuration management";
Expand Down
37 changes: 37 additions & 0 deletions src/nix/profile-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
R""(

# Examples

- Add a package from Nixpkgs:

```console
# nix profile add nixpkgs#hello
```

- Add a package from a specific branch of Nixpkgs:

```console
# nix profile add nixpkgs/release-20.09#hello
```

- Add a package from a specific revision of Nixpkgs:

```console
# nix profile add nixpkgs/d73407e8e6002646acfdef0e39ace088bacc83da#hello
```

- Add a specific output of a package:

```console
# nix profile add nixpkgs#bash^man
```

# Description

This command adds [_installables_](./nix.md#installables) to a Nix profile.

> **Note**
>
> `nix profile install` is an alias for `nix profile add` in Determinate Nix.

)""
34 changes: 0 additions & 34 deletions src/nix/profile-install.md

This file was deleted.

38 changes: 20 additions & 18 deletions src/nix/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,28 +338,28 @@ builtPathsPerInstallable(
return res;
}

struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
struct CmdProfileAdd : InstallablesCommand, MixDefaultProfile
{
std::optional<int64_t> priority;

CmdProfileInstall() {
CmdProfileAdd() {
addFlag({
.longName = "priority",
.description = "The priority of the package to install.",
.description = "The priority of the package to add.",
.labels = {"priority"},
.handler = {&priority},
});
};

std::string description() override
{
return "install a package into a profile";
return "add a package to a profile";
}

std::string doc() override
{
return
#include "profile-install.md"
#include "profile-add.md"
;
}

Expand Down Expand Up @@ -415,7 +415,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
&& existingSource->originalRef == elementSource->originalRef
&& existingSource->attrPath == elementSource->attrPath
) {
warn("'%s' is already installed", elementName);
warn("'%s' is already added", elementName);
continue;
}
}
Expand Down Expand Up @@ -462,15 +462,15 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
"\n"
" nix profile remove %3%\n"
"\n"
"The new package can also be installed next to the existing one by assigning a different priority.\n"
"The new package can also be added next to the existing one by assigning a different priority.\n"
"The conflicting packages have a priority of %5%.\n"
"To prioritise the new package:\n"
"\n"
" nix profile install %4% --priority %6%\n"
" nix profile add %4% --priority %6%\n"
"\n"
"To prioritise the existing package:\n"
"\n"
" nix profile install %4% --priority %7%\n",
" nix profile add %4% --priority %7%\n",
originalConflictingFilePath,
newConflictingFilePath,
originalEntryName,
Expand Down Expand Up @@ -708,16 +708,14 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf

if (!element.source) {
warn(
"Found package '%s', but it was not installed from a flake, so it can't be checked for upgrades!",
element.identifier()
);
"Found package '%s', but it was not added from a flake, so it can't be checked for upgrades!",
element.identifier());
continue;
}
if (element.source->originalRef.input.isLocked()) {
warn(
"Found package '%s', but it was installed from a locked flake reference so it can't be upgraded!",
element.identifier()
);
"Found package '%s', but it was added from a locked flake reference so it can't be upgraded!",
element.identifier());
continue;
}

Expand Down Expand Up @@ -787,7 +785,7 @@ struct CmdProfileList : virtual EvalCommand, virtual StoreCommand, MixDefaultPro
{
std::string description() override
{
return "list installed packages";
return "list packages in the profile";
}

std::string doc() override
Expand Down Expand Up @@ -978,7 +976,7 @@ struct CmdProfile : NixMultiCommand
: NixMultiCommand(
"profile",
{
{"install", []() { return make_ref<CmdProfileInstall>(); }},
{"add", []() { return make_ref<CmdProfileAdd>(); }},
{"remove", []() { return make_ref<CmdProfileRemove>(); }},
{"upgrade", []() { return make_ref<CmdProfileUpgrade>(); }},
{"list", []() { return make_ref<CmdProfileList>(); }},
Expand All @@ -987,7 +985,11 @@ struct CmdProfile : NixMultiCommand
{"rollback", []() { return make_ref<CmdProfileRollback>(); }},
{"wipe-history", []() { return make_ref<CmdProfileWipeHistory>(); }},
})
{ }
{
aliases = {
{"install", { AliasStatus::Deprecated, {"add"}}},
};
}

std::string description() override
{
Expand Down
15 changes: 2 additions & 13 deletions src/nix/store-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace nix;

struct CmdPingStore : StoreCommand, MixJSON
struct CmdInfoStore : StoreCommand, MixJSON
{
std::string description() override
{
Expand Down Expand Up @@ -46,15 +46,4 @@ struct CmdPingStore : StoreCommand, MixJSON
}
};

struct CmdInfoStore : CmdPingStore
{
void run(nix::ref<nix::Store> store) override
{
warn("'nix store ping' is a deprecated alias for 'nix store info'");
CmdPingStore::run(store);
}
};


static auto rCmdPingStore = registerCommand2<CmdPingStore>({"store", "info"});
static auto rCmdInfoStore = registerCommand2<CmdInfoStore>({"store", "ping"});
static auto rCmdInfoStore = registerCommand2<CmdInfoStore>({"store", "info"});
Loading