1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

files: move dry run logic out of onChange hooks

Fixes #751
This commit is contained in:
Naïm Favier 2021-08-01 00:54:47 +02:00 committed by Robert Helgesson
parent 8d68dbd144
commit 5569770d1e
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
8 changed files with 24 additions and 31 deletions

View file

@ -298,9 +298,14 @@ in
home.activation.onFilesChange = hm.dag.entryAfter ["linkGeneration"] ( home.activation.onFilesChange = hm.dag.entryAfter ["linkGeneration"] (
concatMapStrings (v: '' concatMapStrings (v: ''
if [[ ''${changedFiles[${escapeShellArg v.target}]} -eq 1 ]]; then if (( ''${changedFiles[${escapeShellArg v.target}]} == 1 )); then
if [[ -v DRY_RUN || -v VERBOSE ]]; then
echo "Running onChange hook for" ${escapeShellArg v.target}
fi
if [[ ! -v DRY_RUN ]]; then
${v.onChange} ${v.onChange}
fi fi
fi
'') (filter (v: v.onChange != "") (attrValues cfg)) '') (filter (v: v.onChange != "") (attrValues cfg))
); );

View file

@ -6,14 +6,6 @@ let
cfg = config.programs.i3status-rust; cfg = config.programs.i3status-rust;
restartI3 = ''
i3Socket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/i3/ipc-socket.*
if [ -S $i3Socket ]; then
echo "Reloading i3"
$DRY_RUN_CMD ${config.xsession.windowManager.i3.package}/bin/i3-msg -s $i3Socket restart 1>/dev/null
fi
'';
settingsFormat = pkgs.formats.toml { }; settingsFormat = pkgs.formats.toml { };
in { in {
@ -258,7 +250,12 @@ in {
xdg.configFile = mapAttrs' (cfgFileSuffix: cfg: xdg.configFile = mapAttrs' (cfgFileSuffix: cfg:
nameValuePair ("i3status-rust/config-${cfgFileSuffix}.toml") ({ nameValuePair ("i3status-rust/config-${cfgFileSuffix}.toml") ({
onChange = mkIf config.xsession.windowManager.i3.enable restartI3; onChange = mkIf config.xsession.windowManager.i3.enable ''
i3Socket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/i3/ipc-socket.*"
if [[ -S $i3Socket ]]; then
${config.xsession.windowManager.i3.package}/bin/i3-msg -s $i3Socket restart >/dev/null
fi
'';
source = settingsFormat.generate ("config-${cfgFileSuffix}.toml") ({ source = settingsFormat.generate ("config-${cfgFileSuffix}.toml") ({
theme = cfg.theme; theme = cfg.theme;

View file

@ -309,10 +309,9 @@ in {
mkIf pkgs.stdenv.hostPlatform.isLinux { mkIf pkgs.stdenv.hostPlatform.isLinux {
text = qutebrowserConfig; text = qutebrowserConfig;
onChange = '' onChange = ''
hash="$(echo -n $USER | md5sum | cut -d' ' -f1)" hash="$(echo -n "$USER" | md5sum | cut -d' ' -f1)"
socket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/qutebrowser/ipc-$hash" socket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/qutebrowser/ipc-$hash"
if [ -S $socket ]; then if [[ -S $socket ]]; then
echo "Reloading qutebrowser"
command=${ command=${
escapeShellArg (builtins.toJSON { escapeShellArg (builtins.toJSON {
args = [ ":config-source" ]; args = [ ":config-source" ];
@ -320,7 +319,7 @@ in {
protocol_version = 1; protocol_version = 1;
}) })
} }
$DRY_RUN_CMD echo $command | ${pkgs.socat}/bin/socat -lf /dev/null - UNIX-CONNECT:$socket echo "$command" | ${pkgs.socat}/bin/socat -lf /dev/null - UNIX-CONNECT:"$socket"
fi fi
unset hash socket command unset hash socket command
''; '';

View file

@ -192,12 +192,7 @@ in {
xdg.configFile."dunst/dunstrc" = { xdg.configFile."dunst/dunstrc" = {
text = toDunstIni cfg.settings; text = toDunstIni cfg.settings;
onChange = '' onChange = ''
pkillVerbose="" ${pkgs.procps}/bin/pkill -u "$USER" ''${VERBOSE+-e} dunst || true
if [[ -v VERBOSE ]]; then
pkillVerbose="-e"
fi
$DRY_RUN_CMD ${pkgs.procps}/bin/pkill -u $USER $pkillVerbose dunst || true
unset pkillVerbose
''; '';
}; };
}) })

View file

@ -255,8 +255,7 @@ in {
onChange = '' onChange = ''
i3Socket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/i3/ipc-socket.* i3Socket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/i3/ipc-socket.*
if [ -S $i3Socket ]; then if [ -S $i3Socket ]; then
echo "Reloading i3" ${cfg.package}/bin/i3-msg -s $i3Socket reload >/dev/null
$DRY_RUN_CMD ${cfg.package}/bin/i3-msg -s $i3Socket reload 1>/dev/null
fi fi
''; '';
}; };

View file

@ -438,10 +438,9 @@ in {
xdg.configFile."sway/config" = { xdg.configFile."sway/config" = {
source = configFile; source = configFile;
onChange = '' onChange = ''
swaySocket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep -x sway || ${pkgs.coreutils}/bin/true).sock swaySocket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep -x sway || true).sock
if [ -S $swaySocket ]; then if [ -S $swaySocket ]; then
echo "Reloading sway" ${pkgs.sway}/bin/swaymsg -s $swaySocket reload
$DRY_RUN_CMD ${pkgs.sway}/bin/swaymsg -s $swaySocket reload
fi fi
''; '';
}; };

View file

@ -161,9 +161,8 @@ in {
source = xmonadBin; source = xmonadBin;
onChange = '' onChange = ''
# Attempt to restart xmonad if X is running. # Attempt to restart xmonad if X is running.
if [[ -v DISPLAY ]] ; then if [[ -v DISPLAY ]]; then
echo "Restarting xmonad" ${config.xsession.windowManager.command} --restart
$DRY_RUN_CMD ${config.xsession.windowManager.command} --restart
fi fi
''; '';
}; };

View file

@ -93,8 +93,8 @@ in {
++ optionals (cfg.properties != null) ++ optionals (cfg.properties != null)
(mapAttrsToList formatLine cfg.properties)) + "\n"; (mapAttrsToList formatLine cfg.properties)) + "\n";
onChange = '' onChange = ''
if [[ -v DISPLAY ]] ; then if [[ -v DISPLAY ]]; then
$DRY_RUN_CMD ${xrdbMerge} ${xrdbMerge}
fi fi
''; '';
}; };