Move the profile to the system level.
This commit is contained in:
parent
1620a81d15
commit
8f31818a27
2 changed files with 20 additions and 19 deletions
|
|
@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{env, fs, process, str};
|
use std::{fs, process, str};
|
||||||
|
|
||||||
use super::{create_store_link, StorePath, FLAKE_ATTR, PROFILE_NAME};
|
use super::{create_store_link, StorePath, FLAKE_ATTR, PROFILE_NAME};
|
||||||
|
|
||||||
|
|
@ -14,13 +14,8 @@ struct NixBuildOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate(flake_uri: &str) -> Result<()> {
|
pub fn generate(flake_uri: &str) -> Result<()> {
|
||||||
let user = env::var("USER")?;
|
let profile_path = format!("/nix/var/nix/profiles/{}", PROFILE_NAME);
|
||||||
// TODO: we temporarily put this under per-user to avoid needing root access
|
let gcroot_path = format!("/nix/var/nix/gcroots/{}-current", PROFILE_NAME);
|
||||||
// we will move this to /nix/var/nix/profiles/ later on.
|
|
||||||
let profiles_dir = format!("profiles/per-user/{}", user);
|
|
||||||
let gcroots_dir = format!("gcroots/per-user/{}", user);
|
|
||||||
let profile_path = format!("/nix/var/nix/{}/{}", profiles_dir, PROFILE_NAME);
|
|
||||||
let gcroot_path = format!("/nix/var/nix/{}/{}-current", gcroots_dir, PROFILE_NAME);
|
|
||||||
|
|
||||||
// FIXME: we should not hard-code the system here
|
// FIXME: we should not hard-code the system here
|
||||||
let flake_attr = format!("{}.x86_64-linux", FLAKE_ATTR);
|
let flake_attr = format!("{}.x86_64-linux", FLAKE_ATTR);
|
||||||
|
|
|
||||||
28
src/main.rs
28
src/main.rs
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::process::ExitCode;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
|
@ -22,29 +24,33 @@ enum Action {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> ExitCode {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
// FIXME: set default level to info
|
// FIXME: set default level to info
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||||
|
handle_toplevel_error(go(args.action))
|
||||||
match args.action {
|
|
||||||
Action::Activate { store_path } => handle_toplevel_error(activate(store_path)),
|
|
||||||
Action::Generate { flake_uri } => {
|
|
||||||
handle_toplevel_error(service_manager::generate::generate(&flake_uri))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn go(action: Action) -> Result<()> {
|
||||||
|
check_root()?;
|
||||||
|
match action {
|
||||||
|
Action::Activate { store_path } => service_manager::activate::activate(store_path),
|
||||||
|
Action::Generate { flake_uri } => service_manager::generate::generate(&flake_uri),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate(store_path: StorePath) -> Result<()> {
|
fn check_root() -> Result<()> {
|
||||||
if !nix::unistd::Uid::is_root(nix::unistd::getuid()) {
|
if !nix::unistd::Uid::is_root(nix::unistd::getuid()) {
|
||||||
return Err(anyhow!("We need root permissions."));
|
return Err(anyhow!("We need root permissions."));
|
||||||
}
|
}
|
||||||
service_manager::activate::activate(store_path)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_toplevel_error<T>(r: Result<T>) {
|
fn handle_toplevel_error<T>(r: Result<T>) -> ExitCode {
|
||||||
if let Err(e) = r {
|
if let Err(e) = &r {
|
||||||
log::error!("{}", e)
|
log::error!("{}", e);
|
||||||
|
return ExitCode::FAILURE;
|
||||||
}
|
}
|
||||||
|
ExitCode::SUCCESS
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue