Compare commits
2 commits
f05aa81847
...
759db4e208
Author | SHA1 | Date | |
---|---|---|---|
|
759db4e208 | ||
|
48a22d3999 |
2 changed files with 98 additions and 50 deletions
|
@ -3,8 +3,9 @@
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.system.permown;
|
cfg = config.system.permown;
|
||||||
nameGenerator = path: "permown.${replaceStrings [ "/" ] [ "_" ] path}";
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -27,6 +28,15 @@ in
|
||||||
default = null;
|
default = null;
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
};
|
};
|
||||||
|
keepGoing = mkOption {
|
||||||
|
default = false;
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Whether to keep going when chowning or chmodding fails.
|
||||||
|
If set to false, then errors will cause the service to restart
|
||||||
|
instead.
|
||||||
|
'';
|
||||||
|
};
|
||||||
owner = mkOption { type = types.str; };
|
owner = mkOption { type = types.str; };
|
||||||
path = mkOption {
|
path = mkOption {
|
||||||
default = config._module.args.name;
|
default = config._module.args.name;
|
||||||
|
@ -47,52 +57,91 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let plans = lib.attrValues cfg;
|
let
|
||||||
|
plans = attrValues cfg;
|
||||||
in mkIf (plans != [ ]) {
|
in
|
||||||
|
mkIf (plans != [ ]) {
|
||||||
system.activationScripts.permown =
|
system.activationScripts.permown =
|
||||||
let
|
let
|
||||||
mkdir = { path, ... }: ''
|
mkdir = { path, ... }: ''
|
||||||
${pkgs.coreutils}/bin/mkdir -p ${path}
|
${pkgs.coreutils}/bin/mkdir -p "${path}"
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
concatMapStrings mkdir plans;
|
concatMapStrings mkdir plans;
|
||||||
|
|
||||||
systemd.services = listToAttrs (flip map plans
|
systemd.services =
|
||||||
({ path, directory-mode, file-mode, owner, group, umask, ... }: {
|
let
|
||||||
name = nameGenerator path;
|
nameGenerator = { path, ... }:
|
||||||
value = {
|
"permown.${replaceStrings [ "/" ] [ "_" ] path}";
|
||||||
environment = {
|
serviceDefinition =
|
||||||
DIR_MODE = directory-mode;
|
{ path, directory-mode, file-mode, owner, group, umask, keepGoing, ... }:
|
||||||
FILE_MODE = file-mode;
|
{
|
||||||
OWNER_GROUP = "${owner}:${group}";
|
environment = {
|
||||||
ROOT_PATH = path;
|
DIR_MODE = directory-mode;
|
||||||
};
|
FILE_MODE = file-mode;
|
||||||
path = [ pkgs.coreutils pkgs.findutils pkgs.inotifyTools ];
|
OWNER_GROUP = "${owner}:${group}";
|
||||||
serviceConfig = {
|
ROOT_PATH = path;
|
||||||
ExecStart = pkgs.writers.writeDash "permown" ''
|
};
|
||||||
set -efu
|
path = [
|
||||||
find "$ROOT_PATH" -exec chown -h "$OWNER_GROUP" {} +
|
pkgs.coreutils
|
||||||
find "$ROOT_PATH" -type d -exec chmod "$DIR_MODE" {} +
|
pkgs.findutils
|
||||||
find "$ROOT_PATH" -type f -exec chmod "$FILE_MODE" {} +
|
pkgs.inotifyTools
|
||||||
'';
|
];
|
||||||
PrivateTmp = true;
|
serviceConfig = {
|
||||||
#Restart = "always";
|
ExecStart =
|
||||||
#RestartSec = 10;
|
let
|
||||||
UMask = umask;
|
continuable = command:
|
||||||
};
|
if keepGoing
|
||||||
wantedBy = [ "multi-user.target" ];
|
then "{ ${command}; } || :"
|
||||||
};
|
else command;
|
||||||
}));
|
in
|
||||||
|
pkgs.writers.writeDash "permown" ''
|
||||||
|
set -efu
|
||||||
|
|
||||||
|
find "$ROOT_PATH" -exec chown -h "$OWNER_GROUP" {} +
|
||||||
|
find "$ROOT_PATH" -type d -exec chmod "$DIR_MODE" {} +
|
||||||
|
find "$ROOT_PATH" -type f -exec chmod "$FILE_MODE" {} +
|
||||||
|
|
||||||
|
paths=/tmp/paths
|
||||||
|
rm -f "$paths"
|
||||||
|
mkfifo "$paths"
|
||||||
|
|
||||||
|
inotifywait -mrq -e CREATE --format %w%f "$ROOT_PATH" > "$paths" &
|
||||||
|
inotifywaitpid=$!
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
cleanup() {
|
||||||
|
kill "$inotifywaitpid"
|
||||||
|
}
|
||||||
|
|
||||||
|
while read -r path
|
||||||
|
do
|
||||||
|
if test -d "$path"; then
|
||||||
|
cleanup
|
||||||
|
exec "$0" "$@"
|
||||||
|
fi
|
||||||
|
${continuable ''chown -h "$OWNER_GROUP" "$path"''}
|
||||||
|
if test -f "$path"; then
|
||||||
|
${continuable ''chmod "$FILE_MODE" "$path"''}
|
||||||
|
fi
|
||||||
|
done < "$paths"
|
||||||
|
'';
|
||||||
|
PrivateTmp = true;
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = 10;
|
||||||
|
UMask = umask;
|
||||||
|
};
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
listToAttrs (map
|
||||||
|
(plan:
|
||||||
|
{
|
||||||
|
name = nameGenerator plan;
|
||||||
|
value = serviceDefinition plan;
|
||||||
|
})
|
||||||
|
plans);
|
||||||
|
|
||||||
systemd.timers = listToAttrs (flip map plans ({ path, timer, ... }: {
|
|
||||||
name = nameGenerator path;
|
|
||||||
value = {
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
timerConfig.OnCalendar = timer;
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -188,17 +188,16 @@ in
|
||||||
"${cfg.config.modifier}+Shift+minus" = "move scratchpad";
|
"${cfg.config.modifier}+Shift+minus" = "move scratchpad";
|
||||||
"${cfg.config.modifier}+minus" = "scratchpad show";
|
"${cfg.config.modifier}+minus" = "scratchpad show";
|
||||||
|
|
||||||
"${cfg.config.modifier}+1" = "workspace number 1";
|
"${cfg.config.modifier}+1" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 1";
|
||||||
"${cfg.config.modifier}+2" = "workspace number 2";
|
"${cfg.config.modifier}+2" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 2";
|
||||||
"${cfg.config.modifier}+3" = "workspace number 3";
|
"${cfg.config.modifier}+3" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 3";
|
||||||
"${cfg.config.modifier}+4" = "workspace number 4";
|
"${cfg.config.modifier}+4" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 4";
|
||||||
"${cfg.config.modifier}+5" = "workspace number 5";
|
"${cfg.config.modifier}+5" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 5";
|
||||||
"${cfg.config.modifier}+6" = "workspace number 6";
|
"${cfg.config.modifier}+6" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 6";
|
||||||
"${cfg.config.modifier}+7" = "workspace number 7";
|
"${cfg.config.modifier}+7" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 7";
|
||||||
"${cfg.config.modifier}+8" = "workspace number 8";
|
"${cfg.config.modifier}+8" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 8";
|
||||||
"${cfg.config.modifier}+9" = "workspace number 9";
|
"${cfg.config.modifier}+9" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 9";
|
||||||
"${cfg.config.modifier}+0" = "workspace number 10";
|
"${cfg.config.modifier}+0" = "exec --no-startup-id ${pkgs.i3-wk-switch}/bin/i3-wk-switch 10";
|
||||||
|
|
||||||
|
|
||||||
"${cfg.config.modifier}+Shift+1" = "move container to workspace number 1";
|
"${cfg.config.modifier}+Shift+1" = "move container to workspace number 1";
|
||||||
"${cfg.config.modifier}+Shift+2" = "move container to workspace number 2";
|
"${cfg.config.modifier}+Shift+2" = "move container to workspace number 2";
|
||||||
|
|
Loading…
Reference in a new issue