mirror of
https://gitlab.com/TECHNOFAB/soonix.git
synced 2025-12-11 22:00:05 +01:00
chore(lib): add "auto generated" comment to nix generator outputs
fix copy not being able to overwrite generated files due to them being read only (r--r--r--) by removing them first
This commit is contained in:
parent
1246175082
commit
3baef660cf
2 changed files with 21 additions and 1 deletions
20
lib/lib.nix
20
lib/lib.nix
|
|
@ -14,8 +14,26 @@
|
||||||
format = opts.format or "json";
|
format = opts.format or "json";
|
||||||
formatOpts = builtins.removeAttrs opts ["format"];
|
formatOpts = builtins.removeAttrs opts ["format"];
|
||||||
formatter = formats.${format} formatOpts;
|
formatter = formats.${format} formatOpts;
|
||||||
|
|
||||||
|
autogeneratedMessage =
|
||||||
|
{
|
||||||
|
yaml = "# Generated by soonix, DO NOT EDIT";
|
||||||
|
toml = "# Generated by soonix, DO NOT EDIT";
|
||||||
|
lua = "--- Generated by soonix, DO NOT EDIT";
|
||||||
|
xml = "<!-- Generated by soonix, DO NOT EDIT -->";
|
||||||
|
}.${
|
||||||
|
format
|
||||||
|
} or "";
|
||||||
in
|
in
|
||||||
formatter.generate name data;
|
(formatter.generate name data).overrideAttrs (pre: {
|
||||||
|
buildCommand =
|
||||||
|
# sh
|
||||||
|
''
|
||||||
|
${pre.buildCommand}
|
||||||
|
cp $out tmp
|
||||||
|
cat <(echo "${autogeneratedMessage}") tmp > $out
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
|
||||||
string = {
|
string = {
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,8 @@ in {
|
||||||
if [[ ! -f "${hook.output}" ]] || ! cmp -s "${hook.generatedDerivation}" "${hook.output}"; then
|
if [[ ! -f "${hook.output}" ]] || ! cmp -s "${hook.generatedDerivation}" "${hook.output}"; then
|
||||||
_soonix_log "info" "${hookName}" "Copying file: ${hook.generatedDerivation} -> ${hook.output}"
|
_soonix_log "info" "${hookName}" "Copying file: ${hook.generatedDerivation} -> ${hook.output}"
|
||||||
mkdir -p "$(dirname "${hook.output}")"
|
mkdir -p "$(dirname "${hook.output}")"
|
||||||
|
# required since they're read only
|
||||||
|
rm -f "${hook.output}"
|
||||||
cp "${hook.generatedDerivation}" "${hook.output}"
|
cp "${hook.generatedDerivation}" "${hook.output}"
|
||||||
_changed=true
|
_changed=true
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue