summaryrefslogtreecommitdiffstats
path: root/krebs
diff options
context:
space:
mode:
Diffstat (limited to 'krebs')
-rw-r--r--krebs/2configs/reaktor2.nix5
-rw-r--r--krebs/3modules/permown.nix104
-rw-r--r--krebs/3modules/syncthing.nix9
-rw-r--r--krebs/5pkgs/simple/qrscan.nix27
-rw-r--r--krebs/nixpkgs.json6
5 files changed, 106 insertions, 45 deletions
diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix
index 4d90ae3d5..b52125ae8 100644
--- a/krebs/2configs/reaktor2.nix
+++ b/krebs/2configs/reaktor2.nix
@@ -115,6 +115,11 @@ let
in {
+ users.users.reaktor2 = {
+ uid = genid_uint31 "reaktor2";
+ home = stateDir;
+ };
+
krebs.reaktor2 = {
freenode = {
hostname = "irc.freenode.org";
diff --git a/krebs/3modules/permown.nix b/krebs/3modules/permown.nix
index 7a86013e1..63adb2236 100644
--- a/krebs/3modules/permown.nix
+++ b/krebs/3modules/permown.nix
@@ -2,8 +2,8 @@ with import <stockholm/lib>;
{ config, pkgs, ... }: {
options.krebs.permown = mkOption {
- default = [];
- type = types.listOf (types.submodule {
+ default = {};
+ type = types.attrsOf (types.submodule ({ config, ... }: {
options = {
directory-mode = mkOption {
default = "=rwx";
@@ -22,6 +22,7 @@ with import <stockholm/lib>;
type = types.username;
};
path = mkOption {
+ default = config._module.args.name;
type = types.absolute-pathname;
};
umask = mkOption {
@@ -29,46 +30,73 @@ with import <stockholm/lib>;
type = types.file-mode;
};
};
- });
+ }));
};
- config.systemd.services = genAttrs' config.krebs.permown (plan: {
- name = "permown.${replaceStrings ["/"] ["_"] plan.path}";
- value = {
- environment = {
- DIR_MODE = plan.directory-mode;
- FILE_MODE = plan.file-mode;
- OWNER_GROUP = "${plan.owner}:${plan.group}";
- ROOT_PATH = plan.path;
- };
- path = [
- pkgs.coreutils
- pkgs.findutils
- pkgs.inotifyTools
- ];
- serviceConfig = {
- ExecStart = pkgs.writeDash "permown" ''
- set -efu
+ config = let
+ plans = attrValues config.krebs.permown;
+ in mkIf (plans != []) {
+
+ system.activationScripts.permown = let
+ mkdir = plan: /* sh */ ''
+ ${pkgs.coreutils}/bin/mkdir -p ${shell.escape plan.path}
+ '';
+ in concatMapStrings mkdir plans;
+
+ systemd.services = genAttrs' plans (plan: {
+ name = "permown.${replaceStrings ["/"] ["_"] plan.path}";
+ value = {
+ environment = {
+ DIR_MODE = plan.directory-mode;
+ FILE_MODE = plan.file-mode;
+ OWNER_GROUP = "${plan.owner}:${plan.group}";
+ ROOT_PATH = plan.path;
+ };
+ path = [
+ pkgs.coreutils
+ pkgs.findutils
+ pkgs.inotifyTools
+ ];
+ serviceConfig = {
+ ExecStart = pkgs.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" {} +
- find "$ROOT_PATH" -exec chown "$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" |
- while read -r path; do
- if test -d "$path"; then
- exec "$0" "$@"
- fi
- chown "$OWNER_GROUP" "$path"
- chmod "$FILE_MODE" "$path"
- done
- '';
- Restart = "always";
- RestartSec = 10;
- UMask = plan.umask;
+ 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
+ chown -h "$OWNER_GROUP" "$path"
+ if test -f "$path"; then
+ chmod "$FILE_MODE" "$path"
+ fi
+ done < "$paths"
+ '';
+ PrivateTemp = true;
+ Restart = "always";
+ RestartSec = 10;
+ UMask = plan.umask;
+ };
+ wantedBy = [ "multi-user.target" ];
};
- wantedBy = [ "multi-user.target" ];
- };
- });
+ });
+
+ };
}
diff --git a/krebs/3modules/syncthing.nix b/krebs/3modules/syncthing.nix
index bfbac1db9..897ba1e7f 100644
--- a/krebs/3modules/syncthing.nix
+++ b/krebs/3modules/syncthing.nix
@@ -10,7 +10,7 @@ let
addresses = peer.addresses;
}) cfg.peers;
- folders = map (folder: {
+ folders = mapAttrsToList ( _: folder: {
inherit (folder) path id type;
devices = map (peer: { deviceId = cfg.peers.${peer}.id; }) folder.peers;
rescanIntervalS = folder.rescanInterval;
@@ -81,17 +81,18 @@ in
};
folders = mkOption {
- default = [];
- type = types.listOf (types.submodule ({ config, ... }: {
+ default = {};
+ type = types.attrsOf (types.submodule ({ config, ... }: {
options = {
path = mkOption {
type = types.absolute-pathname;
+ default = config._module.args.name;
};
id = mkOption {
type = types.str;
- default = config.path;
+ default = config._module.args.name;
};
peers = mkOption {
diff --git a/krebs/5pkgs/simple/qrscan.nix b/krebs/5pkgs/simple/qrscan.nix
new file mode 100644
index 000000000..7d99dcee7
--- /dev/null
+++ b/krebs/5pkgs/simple/qrscan.nix
@@ -0,0 +1,27 @@
+{ coreutils, gnused, writeDashBin, zbar }:
+
+writeDashBin "qrscan" ''
+ set -efu
+
+ tmpdir=$(${coreutils}/bin/mktemp --tmpdir -d qrscan.XXXXXXXX)
+ codefile=$tmpdir/code
+
+ cleanup() {
+ ${coreutils}/bin/rm "$codefile"
+ ${coreutils}/bin/rmdir "$tmpdir"
+ }
+
+ ${coreutils}/bin/mkfifo "$codefile"
+
+ ${zbar}/bin/zbarcam > "$codefile" &
+ zbarcampid=$!
+
+ exec < "$codefile"
+ while read -r code; do
+ code=$(printf %s "$code" | ${gnused}/bin/sed -n 's/^QR-Code://p')
+ if test -n "$code"; then
+ ${coreutils}/bin/kill "$zbarcampid"
+ echo "$code"
+ fi
+ done
+''
diff --git a/krebs/nixpkgs.json b/krebs/nixpkgs.json
index de6403bd0..d5ca0e21f 100644
--- a/krebs/nixpkgs.json
+++ b/krebs/nixpkgs.json
@@ -1,7 +1,7 @@
{
"url": "https://github.com/NixOS/nixpkgs-channels",
- "rev": "5c52b25283a6cccca443ffb7a358de6fe14b4a81",
- "date": "2019-04-09T21:48:56+02:00",
- "sha256": "0fhbl6bgabhi1sw1lrs64i0hibmmppy1bh256lq8hxy3a2p1haip",
+ "rev": "8ea36d732567c80b2d11eb029e10400fe85ca786",
+ "date": "2019-04-18T22:37:03+01:00",
+ "sha256": "1d59i55qwqd76n2d0hr1si26q333ydizkd91h8lfczb00xnr5pqn",
"fetchSubmodules": false
}