diff options
| author | Soispha Peetz <soispha@b-peetz.de> | 2026-11-11 19:29:59 +0100 |
|---|---|---|
| committer | Soispha Peetz <soispha@b-peetz.de> | 2026-11-14 18:35:52 +0100 |
| commit | 9e22855a1a9561e99c86bd5b61fe2fa0a4f77b39 (patch) | |
| tree | bbc32709f1dc8e6ac3a7f5c420ca608756d54da9 /pkgs/by-name/ro/rollup/src/config.rs | |
| parent | pkgs/rollup: Support a `--dry-run` flag (diff) | |
| download | nixos-config-9e22855a1a9561e99c86bd5b61fe2fa0a4f77b39.zip | |
pkgs/rollup: Add config, specifying clear ownership based on targets
Thus applies are possible to ignore certain directories for certain
targets.
Diffstat (limited to 'pkgs/by-name/ro/rollup/src/config.rs')
| -rw-r--r-- | pkgs/by-name/ro/rollup/src/config.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/pkgs/by-name/ro/rollup/src/config.rs b/pkgs/by-name/ro/rollup/src/config.rs new file mode 100644 index 00000000..64e0b792 --- /dev/null +++ b/pkgs/by-name/ro/rollup/src/config.rs @@ -0,0 +1,79 @@ +use std::{ + collections::HashMap, + ffi::OsStr, + fs::{self}, + path::PathBuf, +}; + +use anyhow::{Result, bail}; +use serde::{Deserialize, Serialize}; + +pub(crate) const MAIN_CONFIG_NAME: &str = "rollup.toml"; +pub(crate) const DROP_IN_NAME: &str = ".rollup.owner"; + +#[derive(Serialize, Deserialize, Debug)] +pub(crate) struct MainConfig { + pub(crate) owners: Vec<Owner>, + pub(crate) drop_ins: HashMap<PathBuf, DropInConfig>, +} + +impl MainConfig { + pub(crate) fn get_owner(&self, owner: &str) -> Result<&Owner> { + if let Some(own) = self.owners.iter().find(|o| o.name == owner) { + Ok(own) + } else { + bail!("Failed to find owner with name: `{}`", owner) + } + } +} + +#[derive(Serialize, Deserialize, Debug)] +pub(crate) struct Owner { + pub(crate) name: String, + pub(crate) applies_to: PathBuf, + pub(crate) last_applied_tag: String, +} + +#[derive(Serialize, Deserialize, Debug)] +pub(crate) struct DropInConfig { + pub(crate) owner: String, +} + +pub(crate) fn load(root: &PathBuf) -> Result<MainConfig> { + let mut main: MainConfig = { + let path = root.join(MAIN_CONFIG_NAME); + let content = fs::read_to_string(path)?; + toml::from_str(&content)? + }; + + let drop_ins = collect_drop_ins(root)?; + + for (path, config) in drop_ins { + assert!(main.drop_ins.insert(path, config).is_none()); + } + + Ok(main) +} + +fn collect_drop_ins(path: &PathBuf) -> Result<Vec<(PathBuf, DropInConfig)>> { + let mut output = vec![]; + for entry in fs::read_dir(path)? { + let entry = entry?; + let ft = entry.file_type()?; + + if ft.is_dir() { + output.extend(collect_drop_ins(&entry.path())?); + } else if ft.is_file() && entry.file_name() == OsStr::new(DROP_IN_NAME) { + let drop_in: DropInConfig = { + let content = fs::read_to_string(entry.path())?; + toml::from_str(&content)? + }; + output.push(( + entry.path().parent().expect("All drop-ins have a parent").to_owned(), + drop_in, + )); + } + } + + Ok(output) +} |
