mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-24 23:06:16 +02:00
introduce CmdSystemApply, CmdSystemBoot
This commit is contained in:
parent
8a11cfdda8
commit
42f9da1ffc
3 changed files with 104 additions and 0 deletions
15
src/nix/system-apply.md
Normal file
15
src/nix/system-apply.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
R""(
|
||||
|
||||
# Description
|
||||
|
||||
This command activates NixOS configurations and sets it as the default boot configuration.
|
||||
|
||||
The `profile` parameter is used to specify the system profile to use.
|
||||
|
||||
The default system profile is `/nix/var/nix/profiles/system`.
|
||||
|
||||
A system profile named `hello` would be located at `/nix/var/nix/profiles/system-profiles/hello`.
|
||||
|
||||
)""
|
||||
|
||||
|
16
src/nix/system-boot.md
Normal file
16
src/nix/system-boot.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
R""(
|
||||
|
||||
# Description
|
||||
|
||||
This command sets the given NixOS configuration as the default boot configuration. It will be activated on the next boot.
|
||||
|
||||
The `profile` parameter is used to specify the system profile to use.
|
||||
|
||||
The default system profile is `/nix/var/nix/profiles/system`.
|
||||
|
||||
A system profile named `hello` would be located at `/nix/var/nix/profiles/system-profiles/hello`.
|
||||
|
||||
)""
|
||||
|
||||
|
||||
|
|
@ -91,6 +91,35 @@ struct SystemCommand : InstallableCommand
|
|||
}
|
||||
};
|
||||
|
||||
struct SystemInstalledActivationCommand : SystemCommand, MixProfile
|
||||
{
|
||||
std::string activationType;
|
||||
|
||||
void run(nix::ref<nix::Store> store) override
|
||||
{
|
||||
std::vector<std::shared_ptr<Installable>> installableContext;
|
||||
auto state = getEvalState();
|
||||
installableContext.emplace_back(transformInstallable(state, installable));
|
||||
auto buildables = Installable::build(
|
||||
getEvalStore(), store,
|
||||
Realise::Outputs,
|
||||
installableContext, bmNormal);
|
||||
|
||||
if (!profile) {
|
||||
profile = settings.nixStateDir + "/profiles/system";
|
||||
} else {
|
||||
profile = settings.nixStateDir + "/profiles/system-profiles/" + profile.value();
|
||||
}
|
||||
|
||||
BuiltPaths buildables2;
|
||||
for (auto & b : buildables)
|
||||
buildables2.push_back(b.path);
|
||||
updateProfile(buildables2);
|
||||
|
||||
executePrivileged(profile.value() + "/bin/switch-to-configuration", Strings{activationType});
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdSystemBuild : SystemCommand, MixDryRun
|
||||
{
|
||||
Path outLink = "result";
|
||||
|
@ -228,12 +257,56 @@ struct CmdSystemActivate : SystemCommand, MixDryRun
|
|||
}
|
||||
};
|
||||
|
||||
struct CmdSystemApply : SystemInstalledActivationCommand
|
||||
{
|
||||
std::string activationType = "switch";
|
||||
|
||||
CmdSystemApply()
|
||||
{
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "activate a NixOS system configuration and make it the default boot configuration";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "system-apply.md"
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdSystemBoot : SystemInstalledActivationCommand
|
||||
{
|
||||
std::string activationType = "boot";
|
||||
|
||||
CmdSystemBoot()
|
||||
{
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "make a NixOS configuration the default boot configuration";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "system-boot.md"
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdSystem : NixMultiCommand
|
||||
{
|
||||
CmdSystem()
|
||||
: MultiCommand({
|
||||
{"build", []() { return make_ref<CmdSystemBuild>(); }},
|
||||
{"activate", []() { return make_ref<CmdSystemActivate>(); }},
|
||||
{"apply", []() { return make_ref<CmdSystemApply>(); }},
|
||||
{"boot", []() { return make_ref<CmdSystemBoot>(); }},
|
||||
})
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue