Avoid an unneeded extra "etc" directory.

This commit is contained in:
r-vdp 2023-03-17 15:47:56 +01:00
parent 527e0269ff
commit 6a7910bab1
No known key found for this signature in database
2 changed files with 15 additions and 8 deletions

View file

@ -57,13 +57,13 @@ in
isManaged = name: lib.elem name nixosConfig.system-manager.etcFiles; isManaged = name: lib.elem name nixosConfig.system-manager.etcFiles;
addToStore = name: file: pkgs.runCommandLocal "${name}-etc-link" { } '' addToStore = name: file: pkgs.runCommandLocal "${name}-etc-link" { } ''
mkdir -p "$out/etc/$(dirname "${file.target}")" mkdir -p "$out/$(dirname "${file.target}")"
ln -s "${file.source}" "$out/etc/${file.target}" ln -s "${file.source}" "$out/${file.target}"
if [ "${file.mode}" != symlink ]; then if [ "${file.mode}" != symlink ]; then
echo "${file.mode}" > "$out/etc/${file.target}.mode" echo "${file.mode}" > "$out/${file.target}.mode"
echo "${file.user}" > "$out/etc/${file.target}.uid" echo "${file.user}" > "$out/${file.target}.uid"
echo "${file.group}" > "$out/etc/${file.target}.gid" echo "${file.group}" > "$out/${file.target}.gid"
fi fi
''; '';

View file

@ -181,7 +181,6 @@ fn create_etc_link(link_target: &OsStr, etc_dir: &Path, state: EtcTree) -> (EtcT
create_link( create_link(
&Path::new(".") &Path::new(".")
.join(SYSTEM_MANAGER_STATIC_NAME) .join(SYSTEM_MANAGER_STATIC_NAME)
.join("etc")
.join(link_target), .join(link_target),
&link_path, &link_path,
) )
@ -211,7 +210,7 @@ fn create_etc_entry(
let (new_state, status) = create_dir_recursively(target_path.parent().unwrap(), state); let (new_state, status) = create_dir_recursively(target_path.parent().unwrap(), state);
match status.and_then(|_| { match status.and_then(|_| {
copy_file( copy_file(
&entry.source.store_path.join("etc").join(&entry.target), &entry.source.store_path.join(&entry.target),
&target_path, &target_path,
&entry.mode, &entry.mode,
old_state, old_state,
@ -266,8 +265,16 @@ fn create_dir_recursively(dir: &Path, state: EtcTree) -> (EtcTree, Result<()>) {
fn copy_file(source: &Path, target: &Path, mode: &str, old_state: &EtcTree) -> Result<()> { fn copy_file(source: &Path, target: &Path, mode: &str, old_state: &EtcTree) -> Result<()> {
let exists = target.try_exists()?; let exists = target.try_exists()?;
let old_status = old_state.get_status(target); let old_status = old_state.get_status(target);
log::debug!("Status for target {}: {old_status:?}", target.display()); log::debug!(
"Status for target {} before copy: {old_status:?}",
target.display()
);
if !exists || *old_status == EtcFileStatus::Managed { if !exists || *old_status == EtcFileStatus::Managed {
log::debug!(
"Copying file {} to {}...",
source.display(),
target.display()
);
fs::copy(source, target)?; fs::copy(source, target)?;
let mode_int = u32::from_str_radix(mode, 8)?; let mode_int = u32::from_str_radix(mode, 8)?;
fs::set_permissions(target, Permissions::from_mode(mode_int))?; fs::set_permissions(target, Permissions::from_mode(mode_int))?;