Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning if file cannot be managed by hjem #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,43 @@ in {
"${mode} '${file.target}' - - - - ${file.source}"
) (filter (f: f.enable && f.source != null) (attrValues files));
}) (filterAttrs (_: u: (u.enable && u.files != {})) cfg.users);
systemd.services = mapAttrs' (name: {files, ...}: {
name = "hjem-monitor-" + name;
value = {
wants = ["systemd-tmpfiles-setup.service" "nix-daemon.socket"];
after = ["nix-daemon.socket"];
wantedBy = ["multi-user.target"];
description = "Monitoring for Hjem files";
scriptArgs = "${toString (map (
file: file.target
) (filter (f: f.enable && f.source != null) (attrValues files)))}";
enableStrictShellChecks = true;
script = ''
#! ${pkgs.runtimeShell} -e
code=0
err=""
normal=""
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test "$ncolors" -ge 8; then
err="$(tput bold)$(tput setaf 3)"
normal="$(tput sgr0)"
fi
fi
for var in "$@"
do
if [ ! -L "$var" ] ; then
echo "''${err}$var is not managed by Hjem due to a file conflict, please move or remove the current file.''${normal}"
code=1
fi
done
exit $code
'';
serviceConfig = {
Type = "exec";
};
};
}) (filterAttrs (_: u: u.files != {}) config.homes);
}

(mkIf (cfg.users != {}) {
Expand Down