-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/dock add codex #1502
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
Feat/dock add codex #1502
Changes from all commits
a44a387
12204f3
970abd2
0867b73
5eebaff
5e372cd
2cb5436
db045d9
0c58107
ff9779e
8062ada
9cfd6ed
9233cd7
187310a
8099906
f7816de
0ad62ae
d629b3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ in | |
| ./k3s | ||
| ./karabiner | ||
| ./llm | ||
| ./mempalace | ||
| ./obsidian | ||
| ./omp | ||
| ./openclaw | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "palace": "/home/ubuntu/ghq/github.com/shunkakinoki/wiki" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { ... }: | ||
| { | ||
| home.file.".mempalace/config.json" = { | ||
| source = ./config.json; | ||
| force = true; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| ./local-binaries | ||
| ./local-scripts | ||
| ./npm-globals | ||
| ./secure-dotenv | ||
| ./tailscale | ||
| ./uv-globals | ||
| ./xremap | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,9 @@ set -euo pipefail | |||||
|
|
||||||
| UNIT_NAME="decafinate" | ||||||
| UNIT_FILE="${UNIT_NAME}.service" | ||||||
| PID_FILE="${XDG_STATE_HOME:-$HOME/.local/state}/decafinate.pid" | ||||||
|
|
||||||
| OS="$(uname -s)" | ||||||
|
|
||||||
| notify_local() { | ||||||
| local message="$1" | ||||||
|
|
@@ -28,28 +31,60 @@ EOF | |||||
| } | ||||||
|
|
||||||
| ac_online() { | ||||||
| local ac_path | ||||||
| shopt -s nullglob | ||||||
|
|
||||||
| for ac_path in /sys/class/power_supply/AC*/online; do | ||||||
| if grep -q 1 "$ac_path"; then | ||||||
| return 0 | ||||||
| fi | ||||||
| done | ||||||
| case "$OS" in | ||||||
| Darwin) | ||||||
| pmset -g ps | grep -q "AC Power" | ||||||
| ;; | ||||||
| Linux) | ||||||
| local ac_path | ||||||
| shopt -s nullglob | ||||||
|
|
||||||
| for ac_path in /sys/class/power_supply/AC*/online; do | ||||||
| if grep -q 1 "$ac_path"; then | ||||||
| return 0 | ||||||
| fi | ||||||
| done | ||||||
|
|
||||||
| return 1 | ||||||
| return 1 | ||||||
| ;; | ||||||
| *) | ||||||
| echo "Unsupported OS: $OS" >&2 | ||||||
| return 1 | ||||||
| ;; | ||||||
| esac | ||||||
| } | ||||||
|
|
||||||
| require_ac_path() { | ||||||
| if ! compgen -G "/sys/class/power_supply/AC*/online" >/dev/null; then | ||||||
| echo "No AC power status path found under /sys/class/power_supply/AC*/online" >&2 | ||||||
| notify_local "No AC power status path found." | ||||||
| exit 1 | ||||||
| fi | ||||||
| require_ac() { | ||||||
| case "$OS" in | ||||||
| Darwin) | ||||||
| if ! command -v pmset >/dev/null; then | ||||||
| echo "pmset not found" >&2 | ||||||
| notify_local "pmset not found." | ||||||
| exit 1 | ||||||
| fi | ||||||
| ;; | ||||||
| Linux) | ||||||
| if ! compgen -G "/sys/class/power_supply/AC*/online" >/dev/null; then | ||||||
| echo "No AC power status path found under /sys/class/power_supply/AC*/online" >&2 | ||||||
| notify_local "No AC power status path found." | ||||||
| exit 1 | ||||||
| fi | ||||||
| ;; | ||||||
| esac | ||||||
| } | ||||||
|
|
||||||
| service_active() { | ||||||
| systemctl --user is-active --quiet "$UNIT_FILE" | ||||||
| case "$OS" in | ||||||
| Darwin) | ||||||
| if [[ -f $PID_FILE ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking for file existence with
Suggested change
|
||||||
| return 0 | ||||||
| fi | ||||||
| return 1 | ||||||
| ;; | ||||||
| Linux) | ||||||
| systemctl --user is-active --quiet "$UNIT_FILE" | ||||||
| ;; | ||||||
| esac | ||||||
| } | ||||||
|
|
||||||
| print_status() { | ||||||
|
|
@@ -63,7 +98,7 @@ print_status() { | |||||
| } | ||||||
|
|
||||||
| start_service() { | ||||||
| require_ac_path | ||||||
| require_ac | ||||||
|
|
||||||
| if service_active; then | ||||||
| echo "decafinate is already active" | ||||||
|
|
@@ -76,33 +111,60 @@ start_service() { | |||||
| return 1 | ||||||
| fi | ||||||
|
|
||||||
| local systemd_inhibit | ||||||
| local bash_bin | ||||||
| echo "Starting decafinate. The laptop will stay awake while AC is connected." | ||||||
| notify_local "Keeping the laptop awake while AC is connected." | ||||||
|
|
||||||
| systemd_inhibit="$(command -v systemd-inhibit)" | ||||||
| bash_bin="$(command -v bash)" | ||||||
| case "$OS" in | ||||||
| Darwin) | ||||||
| mkdir -p "$(dirname "$PID_FILE")" | ||||||
|
|
||||||
| if [[ -z $systemd_inhibit || -z $bash_bin ]]; then | ||||||
| echo "Required commands not found: systemd-inhibit and bash must be available." >&2 | ||||||
| return 1 | ||||||
| fi | ||||||
| ( | ||||||
| caffeinate -di & | ||||||
| CAFF_PID=$! | ||||||
|
|
||||||
| echo "Starting decafinate. The laptop will stay awake while AC is connected." | ||||||
| notify_local "Keeping the laptop awake while AC is connected." | ||||||
| while ac_online; do | ||||||
| if ! kill -0 "$CAFF_PID" 2>/dev/null; then | ||||||
| break | ||||||
| fi | ||||||
| sleep 15 | ||||||
| done | ||||||
|
|
||||||
| kill "$CAFF_PID" 2>/dev/null || true | ||||||
| rm -f "$PID_FILE" | ||||||
|
|
||||||
| echo "AC power disconnected; ending decafinate session." | ||||||
| if [[ -x "$HOME/.local/scripts/notify-local" ]]; then | ||||||
| "$HOME/.local/scripts/notify-local" "Decafinate" "AC power disconnected. Ending keep-awake session." >/dev/null 2>&1 || true | ||||||
| fi | ||||||
| ) & | ||||||
| echo $! >"$PID_FILE" | ||||||
| disown | ||||||
| ;; | ||||||
| Linux) | ||||||
| local systemd_inhibit | ||||||
| local bash_bin | ||||||
|
|
||||||
| systemd_inhibit="$(command -v systemd-inhibit)" | ||||||
| bash_bin="$(command -v bash)" | ||||||
|
|
||||||
| if [[ -z $systemd_inhibit || -z $bash_bin ]]; then | ||||||
| echo "Required commands not found: systemd-inhibit and bash must be available." >&2 | ||||||
| return 1 | ||||||
| fi | ||||||
|
|
||||||
| systemctl --user reset-failed "$UNIT_FILE" >/dev/null 2>&1 || true | ||||||
|
|
||||||
| # shellcheck disable=SC2016 | ||||||
| systemd-run --user \ | ||||||
| --unit="$UNIT_NAME" \ | ||||||
| --collect \ | ||||||
| --property=Restart=no \ | ||||||
| --property=Type=simple \ | ||||||
| "$systemd_inhibit" \ | ||||||
| --what=idle:sleep:handle-lid-switch \ | ||||||
| --who="decafinate" \ | ||||||
| --why="Manual AC-only keep-awake session" \ | ||||||
| "$bash_bin" -lc ' | ||||||
| systemctl --user reset-failed "$UNIT_FILE" >/dev/null 2>&1 || true | ||||||
|
|
||||||
| # shellcheck disable=SC2016 | ||||||
| systemd-run --user \ | ||||||
| --unit="$UNIT_NAME" \ | ||||||
| --collect \ | ||||||
| --property=Restart=no \ | ||||||
| --property=Type=simple \ | ||||||
| "$systemd_inhibit" \ | ||||||
| --what=idle:sleep:handle-lid-switch \ | ||||||
| --who="decafinate" \ | ||||||
| --why="Manual AC-only keep-awake session" \ | ||||||
| "$bash_bin" -lc ' | ||||||
| set -euo pipefail | ||||||
|
|
||||||
| ac_online() { | ||||||
|
|
@@ -127,6 +189,8 @@ start_service() { | |||||
| "$HOME/.local/scripts/notify-local" "Decafinate" "AC power disconnected. Ending keep-awake session." >/dev/null 2>&1 || true | ||||||
| fi | ||||||
| ' >/dev/null | ||||||
| ;; | ||||||
| esac | ||||||
| } | ||||||
|
|
||||||
| stop_service() { | ||||||
|
|
@@ -135,7 +199,19 @@ stop_service() { | |||||
| return 0 | ||||||
| fi | ||||||
|
|
||||||
| systemctl --user stop "$UNIT_FILE" | ||||||
| case "$OS" in | ||||||
| Darwin) | ||||||
| local pid | ||||||
| pid="$(cat "$PID_FILE")" | ||||||
| # Kill the wrapper process group (includes caffeinate) | ||||||
| kill -- -"$pid" 2>/dev/null || kill "$pid" 2>/dev/null || true | ||||||
| rm -f "$PID_FILE" | ||||||
| ;; | ||||||
| Linux) | ||||||
| systemctl --user stop "$UNIT_FILE" | ||||||
| ;; | ||||||
| esac | ||||||
|
|
||||||
| echo "Stopped decafinate" | ||||||
| notify_local "Stopped the keep-awake session." | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| pkgs, | ||
| ... | ||
| }: | ||
| let | ||
| homeDir = config.home.homeDirectory; | ||
| script = pkgs.writeShellScript "secure-dotenv" '' | ||
| set -euo pipefail | ||
| # Enforce 600 on all .env files under home directory | ||
| ${pkgs.findutils}/bin/find "${homeDir}" \ | ||
| -maxdepth 4 \ | ||
| -name '.env' -o -name '.env.*' -o -name '*.env' \ | ||
| 2>/dev/null | while IFS= read -r f; do | ||
|
Comment on lines
+12
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parsing References
|
||
| if [ -f "$f" ] && [ ! -L "$f" ]; then | ||
| current=$(${pkgs.coreutils}/bin/stat -c '%a' "$f") | ||
| if [ "$current" != "600" ]; then | ||
| chmod 600 "$f" | ||
| fi | ||
| fi | ||
| done | ||
| ''; | ||
| in | ||
| { | ||
| home.activation.secureDotenv = lib.hm.dag.entryAfter [ "writeBoundary" ] '' | ||
| $DRY_RUN_CMD ${script} | ||
| ''; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration for
mempalacecurrently relies on a static JSON file with a hardcoded home directory path. To improve portability across different users and environments, it is better to generate the JSON content dynamically using Nix and theconfig.home.homeDirectoryoption.