mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-11-08 11:36:07 +01:00
Add environment.etcBackupExtension option
This commit is contained in:
parent
6c80065616
commit
15f5d97457
3 changed files with 45 additions and 17 deletions
|
|
@ -24,6 +24,9 @@
|
|||
#unzip
|
||||
];
|
||||
|
||||
# Backup etc files instead of failing to activate generation if a file already exists in /etc
|
||||
environment.etcBackupExtension = ".bak";
|
||||
|
||||
# Read the changelog before changing this value
|
||||
system.stateVersion = "19.09";
|
||||
|
||||
|
|
|
|||
|
|
@ -72,20 +72,37 @@ in
|
|||
|
||||
options = {
|
||||
|
||||
environment.etc = mkOption {
|
||||
type = types.loaOf fileType;
|
||||
default = {};
|
||||
example = literalExample ''
|
||||
{
|
||||
example-configuration-file = {
|
||||
source = "/nix/store/.../etc/dir/file.conf.example";
|
||||
};
|
||||
"default/useradd".text = "GROUP=100 ...";
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Set of files that have to be linked in <filename>/etc</filename>.
|
||||
'';
|
||||
environment = {
|
||||
etc = mkOption {
|
||||
type = types.loaOf fileType;
|
||||
default = {};
|
||||
example = literalExample ''
|
||||
{
|
||||
example-configuration-file = {
|
||||
source = "/nix/store/.../etc/dir/file.conf.example";
|
||||
};
|
||||
"default/useradd".text = "GROUP=100 ...";
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Set of files that have to be linked in <filename>/etc</filename>.
|
||||
'';
|
||||
};
|
||||
|
||||
etcBackupExtension = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = ".bak";
|
||||
description = ''
|
||||
Backup file extension.
|
||||
</para><para>
|
||||
If a file in <filename>/etc</filename> already exists and is not managed
|
||||
by nix-on-droid, the activation fails because we do not overwrite unknown
|
||||
files. When an extension is provided through this option, the original
|
||||
file will be moved in respect of the backup extension and the activation
|
||||
executes successfully.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
|
@ -99,7 +116,7 @@ in
|
|||
inherit etc;
|
||||
|
||||
activation.setUpEtc = ''
|
||||
$DRY_RUN_CMD bash ${./setup-etc.sh} /etc ${etc}/etc
|
||||
$DRY_RUN_CMD bash ${./setup-etc.sh} /etc ${etc}/etc ${config.environment.etcBackupExtension}
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
etc="${1}"
|
||||
static="/etc/static"
|
||||
new_etc="${2}"
|
||||
backup_extension="${3:-}"
|
||||
|
||||
function atomic_symlink() {
|
||||
local source="${1}"
|
||||
|
|
@ -25,7 +26,7 @@ function cleanup() {
|
|||
for file in $(find "${etc}" -xtype l); do
|
||||
local target="$(readlink "${file}")"
|
||||
if [[ ! -L "${target}" ]]; then
|
||||
echo "removing obsolete symlink '${file}'..."
|
||||
echo "Removing obsolete symlink '${file}'..."
|
||||
rm "${file}"
|
||||
fi
|
||||
done
|
||||
|
|
@ -64,7 +65,14 @@ function link() {
|
|||
mkdir -p "$(dirname "${target}")"
|
||||
|
||||
if [[ -e "${target}" ]] && ! is_static "${target}"; then
|
||||
echo "Linking of ${target} failed. Please remove this file."
|
||||
if [[ -n "${backup_extension}" ]]; then
|
||||
echo "Backing up '${target}' to '${target}${backup_extension}'..."
|
||||
cp "${target}" "${target}${backup_extension}"
|
||||
|
||||
atomic_symlink "${static}/${name}" "${target}"
|
||||
else
|
||||
echo "Linking of ${target} failed. Please remove this file."
|
||||
fi
|
||||
else
|
||||
atomic_symlink "${static}/${name}" "${target}"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue