mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-09 15:58:05 +02:00
CmdHome: init
This commit is contained in:
parent
a2e3eee48f
commit
f9717a9141
4 changed files with 146 additions and 0 deletions
9
src/nix/home-apply.md
Normal file
9
src/nix/home-apply.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
R""(
|
||||
|
||||
# Description
|
||||
|
||||
This command activates a home-manager configuration.
|
||||
|
||||
)""
|
||||
|
||||
|
7
src/nix/home-build.md
Normal file
7
src/nix/home-build.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
R""(
|
||||
|
||||
# Description
|
||||
|
||||
This command builds NixOS configurations. The default attribute name is the current system hostname.
|
||||
|
||||
)""
|
123
src/nix/home.cc
Normal file
123
src/nix/home.cc
Normal file
|
@ -0,0 +1,123 @@
|
|||
#include "command.hh"
|
||||
#include "activatables.hh"
|
||||
#include "progress-bar.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
void execute(std::string program, Strings args) {
|
||||
stopProgressBar();
|
||||
restoreProcessContext();
|
||||
args.push_front(program);
|
||||
execvp(program.c_str(), stringsToCharPtrs(args).data());
|
||||
|
||||
throw SysError("unable to execute '%s'", program);
|
||||
}
|
||||
|
||||
struct HomeCommand : ActivatableCommand
|
||||
{
|
||||
HomeCommand()
|
||||
: ActivatableCommand("activationPackage")
|
||||
{}
|
||||
|
||||
Strings getDefaultFlakeAttrPaths() override
|
||||
{
|
||||
auto username = getUserName();
|
||||
char hostname[1024];
|
||||
hostname[1023] = '\0';
|
||||
gethostname(hostname, 1024);
|
||||
|
||||
Strings res{
|
||||
"homeConfigurations." + username,
|
||||
"homeConfigurations." + username + "@" + std::string(hostname),
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
Strings getDefaultFlakeAttrPathPrefixes() override
|
||||
{
|
||||
Strings res{"homeConfigurations."};
|
||||
return res;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct HomeActivationCommand : ActivationCommand<HomeCommand>
|
||||
{
|
||||
HomeActivationCommand(std::string activationType, std::string selfCommandName)
|
||||
: ActivationCommand<HomeCommand>(activationType, selfCommandName)
|
||||
{ }
|
||||
|
||||
void run(nix::ref<nix::Store> store) override
|
||||
{
|
||||
auto out = buildActivatable(store);
|
||||
execute(store->printStorePath(out) + "/activate", Strings{});
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdHomeBuild : ActivatableBuildCommand<HomeCommand>
|
||||
{
|
||||
std::string description() override
|
||||
{
|
||||
return "build a home-manager configuration";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "home-build.md"
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdHomeApply : HomeActivationCommand
|
||||
{
|
||||
CmdHomeApply() : HomeActivationCommand("switch", "apply")
|
||||
{
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "activate a home-manager configuration";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "home-apply.md"
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdHome : NixMultiCommand
|
||||
{
|
||||
CmdHome()
|
||||
: MultiCommand({
|
||||
{"build", []() { return make_ref<CmdHomeBuild>(); }},
|
||||
{"apply", []() { return make_ref<CmdHomeApply>(); }},
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "manage home-manager configurations";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "home.md"
|
||||
;
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
if (!command)
|
||||
throw UsageError("'nix home' requires a sub-command.");
|
||||
settings.requireExperimentalFeature(Xp::NixCommand);
|
||||
command->second->prepare();
|
||||
command->second->run();
|
||||
}
|
||||
};
|
||||
|
||||
static auto rCmdHome = registerCommand<CmdHome>("home");
|
7
src/nix/home.md
Normal file
7
src/nix/home.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
R""(
|
||||
|
||||
# Description
|
||||
|
||||
This is a group of commands for managing home-manager configurations.
|
||||
|
||||
)""
|
Loading…
Reference in a new issue