diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 41196186d..0ea921477 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -168,7 +168,15 @@ in internal = true; default = {}; type = types.attrs; - description = "Activation scripts for the home environment."; + description = '' + Activation scripts for the home environment. + + Any script should respect the DRY_RUN + variable, if it is set then no actual action should be taken. + The variable DRY_RUN_CMD is set to + echo if dry run is enabled. Thus, many cases you + can use the idiom $DRY_RUN_CMD rm -rf /. + ''; }; home.activationPackage = mkOption { @@ -202,8 +210,8 @@ in for sourcePath in "$@" ; do relativePath="$(realpath --relative-to "$newGenFiles" "$sourcePath")" targetPath="$HOME/$relativePath" - mkdir -vp "$(dirname "$targetPath")" - ln -vsf "$sourcePath" "$targetPath" + $DRY_RUN_CMD mkdir -vp "$(dirname "$targetPath")" + $DRY_RUN_CMD ln -vsf "$sourcePath" "$targetPath" done ''; @@ -219,8 +227,8 @@ in echo " exists" else echo " gone (deleting)" - rm -v "$targetPath" - rmdir --ignore-fail-on-non-empty -v -p "$(dirname "$targetPath")" + $DRY_RUN_CMD rm -v "$targetPath" + $DRY_RUN_CMD rmdir --ignore-fail-on-non-empty -v -p "$(dirname "$targetPath")" fi done ''; @@ -284,8 +292,8 @@ in } if [[ "$oldGenPath" != "$newGenPath" ]] ; then - ln -Tsfv "$newGenPath" "$newGenProfilePath" - ln -Tsfv "$newGenPath" "$newGenGcPath" + $DRY_RUN_CMD ln -Tsfv "$newGenPath" "$newGenProfilePath" + $DRY_RUN_CMD ln -Tsfv "$newGenPath" "$newGenGcPath" linkNewGen cleanOldGen else @@ -316,6 +324,14 @@ in sf = pkgs.writeText "activation-script" '' #!${pkgs.stdenv.shell} + if [[ $DRY_RUN ]] ; then + echo "Performing dry run" + export DRY_RUN_CMD=echo + else + echo "Performing live run" + unset DRY_RUN_CMD + fi + ${activationCmds} ''; diff --git a/modules/programs/gnome-terminal.nix b/modules/programs/gnome-terminal.nix index 4a7646f24..6d483b90d 100644 --- a/modules/programs/gnome-terminal.nix +++ b/modules/programs/gnome-terminal.nix @@ -183,7 +183,11 @@ in dconfPath = "/org/gnome/terminal/legacy/"; in '' - ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${sf} + if [[ $DRY_RUN ]]; then + echo ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} "<" ${sf} + else + ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${sf} + fi ''; }; } diff --git a/modules/systemd.nix b/modules/systemd.nix index 450d8f9f5..784be8db6 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -120,7 +120,7 @@ in fi } - systemctl --user daemon-reload + $DRY_RUN_CMD systemctl --user daemon-reload systemdPostReload ''; };