Write generation state into a state file and restructure the services.json file produced by nix.
This commit is contained in:
parent
8f31818a27
commit
c3be9ceb19
6 changed files with 143 additions and 80 deletions
17
src/lib.rs
17
src/lib.rs
|
|
@ -3,29 +3,34 @@ pub mod generate;
|
|||
mod systemd;
|
||||
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::os::unix;
|
||||
use std::path::Path;
|
||||
use std::{fs, str};
|
||||
|
||||
const FLAKE_ATTR: &str = "serviceConfig";
|
||||
const PROFILE_NAME: &str = "service-manager";
|
||||
const PROFILE_PATH: &str = "/nix/var/nix/profiles/service-manager";
|
||||
const GCROOT_PATH: &str = "/nix/var/nix/gcroots/service-manager-current";
|
||||
const SYSTEMD_UNIT_DIR: &str = "/run/systemd/system";
|
||||
const SERVICE_MANAGER_STATE_DIR: &str = "/var/lib/service-manager/state";
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StorePath {
|
||||
pub path: String,
|
||||
pub store_path: String,
|
||||
}
|
||||
|
||||
impl From<String> for StorePath {
|
||||
fn from(path: String) -> Self {
|
||||
StorePath {
|
||||
path: path.trim().into(),
|
||||
store_path: path.trim().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for StorePath {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.path)
|
||||
write!(f, "{}", self.store_path)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +39,7 @@ fn create_store_link(store_path: &StorePath, from: &Path) -> Result<()> {
|
|||
if from.is_symlink() {
|
||||
fs::remove_file(from)?;
|
||||
}
|
||||
unix::fs::symlink(&store_path.path, from).map_err(anyhow::Error::from)
|
||||
unix::fs::symlink(&store_path.store_path, from).map_err(anyhow::Error::from)
|
||||
}
|
||||
|
||||
pub fn compose<A, B, C, G, F>(f: F, g: G) -> impl Fn(A) -> C
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue