Skip to content
Merged
Changes from 1 commit
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
16 changes: 13 additions & 3 deletions home-manager/modules/paperclip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let
inherit (inputs) host;
homeDir = config.home.homeDirectory;
repoDir = "${homeDir}/ghq/github.com/paperclipai/paperclip";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify whether repo provisioning exists anywhere in Home Manager/Nix code.
rg -n --type nix --type sh 'paperclipai/paperclip|ghq/github.com/paperclipai/paperclip|ConditionPathExists'

Repository: shunkakinoki/dotfiles

Length of output: 173


🏁 Script executed:

#!/bin/bash
# View the full paperclip service configuration
cat -n home-manager/modules/paperclip/default.nix

Repository: shunkakinoki/dotfiles

Length of output: 2337


🏁 Script executed:

#!/bin/bash
# Search for ghq initialization, git clone, or Home Manager activation scripts
rg -n 'ghq|git clone|activation' --type nix --type sh -A 3 -B 3

Repository: shunkakinoki/dotfiles

Length of output: 37004


Add a guard for missing repo directory before service start.

The paperclipSetup activation script (lines 15-18) only creates directories—it does not clone the repository. If ${repoDir} doesn't exist at service start, WorkingDirectory (line 47) and ExecStart (line 33) will cause systemd to hard-fail the unit. Add ConditionPathExists to make the failure explicit rather than flaky.

Suggested hardening
   systemd.user.services.paperclip = {
     Unit = {
       Description = "Paperclip AI agent orchestration platform";
       After = [ "network-online.target" ];
       Wants = [ "network-online.target" ];
+      ConditionPathExists = "${repoDir}/server/src/index.ts";
     };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@home-manager/modules/paperclip/default.nix` at line 10, The systemd unit can
hard-fail if the repo directory (repoDir =
"${homeDir}/ghq/github.com/paperclipai/paperclip") is missing because
paperclipSetup only creates directories; add a ConditionPathExists check to the
generated unit so systemd will skip/explicitly fail when the repo is absent.
Modify the code that emits the unit (look for the unit section referencing
WorkingDirectory and ExecStart in the paperclipSetup/unit or service generation
logic) to include ConditionPathExists=<path> using the same repoDir symbol,
ensuring the path guard is added alongside the existing WorkingDirectory and
ExecStart entries.

in
# Only enable on kyber (server host)
lib.mkIf host.isKyber {
Expand All @@ -18,7 +19,9 @@ lib.mkIf host.isKyber {
'';

# Systemd service for Paperclip
# Uses bun runtime instead of node to avoid pino-http crash (logger[stringifySym] is not a function)
# Runs from cloned repo via pnpm dev:once — the global bun install has a
# pino-http/pino version mismatch that crashes node after the first request.
# The repo's lockfile resolves deps correctly.
systemd.user.services.paperclip = {
Unit = {
Description = "Paperclip AI agent orchestration platform";
Expand All @@ -27,14 +30,21 @@ lib.mkIf host.isKyber {
};
Service = {
Type = "simple";
ExecStart = "${homeDir}/.nix-profile/bin/bun run ${homeDir}/.bun/install/global/node_modules/paperclipai/dist/index.js run --no-repair";
ExecStart = "${homeDir}/.bun/bin/pnpm dev:once";
Restart = "always";
RestartSec = "5s";
Environment = [
"HOME=${homeDir}"
"HOST=0.0.0.0"
"PAPERCLIP_DEPLOYMENT_MODE=authenticated"
"PAPERCLIP_ALLOWED_HOSTNAMES=paperclip.shunkakinoki.com,172.17.0.1"
"PATH=${homeDir}/.local/bin:${homeDir}/.bun/bin:${homeDir}/.nix-profile/bin:${homeDir}/.local/share/pnpm:${homeDir}/.local/share/fnm/current/bin:${homeDir}/.npm-global/bin:/usr/local/bin:/usr/bin:/bin"
];
WorkingDirectory = "${homeDir}/.paperclip";
EnvironmentFile = [
"${homeDir}/dotfiles/.env"
"${homeDir}/.paperclip/instances/default/.env"
Comment on lines +40 to +41

Copilot AI Apr 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvironmentFile entries are required by systemd; if either ${homeDir}/dotfiles/.env or ${homeDir}/.paperclip/instances/default/.env is missing, the unit will fail to start. Either ensure these files (and the instances/default directory) are created with appropriate permissions during activation, or prefix the paths with - to make them optional and handle missing values another way.

Suggested change
"${homeDir}/dotfiles/.env"
"${homeDir}/.paperclip/instances/default/.env"
"-${homeDir}/dotfiles/.env"
"-${homeDir}/.paperclip/instances/default/.env"

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +41

@cubic-dev-ai cubic-dev-ai Bot Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Systemd's EnvironmentFile directive treats unprefixed paths as required — the service will refuse to start if either file is missing (e.g. fresh machine, before manual setup). Prefix with - to make them optional:

EnvironmentFile = [
  "-${homeDir}/dotfiles/.env"
  "-${homeDir}/.paperclip/instances/default/.env"
];
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/modules/paperclip/default.nix, line 44:

<comment>Systemd's `EnvironmentFile` directive treats unprefixed paths as required — the service will refuse to start if either file is missing (e.g. fresh machine, before manual setup). Prefix with `-` to make them optional:
```nix
EnvironmentFile = [
  "-${homeDir}/dotfiles/.env"
  "-${homeDir}/.paperclip/instances/default/.env"
];
```</comment>

<file context>
@@ -27,14 +30,21 @@ lib.mkIf host.isKyber {
       ];
-      WorkingDirectory = "${homeDir}/.paperclip";
+      EnvironmentFile = [
+        "${homeDir}/dotfiles/.env"
+        "${homeDir}/.paperclip/instances/default/.env"
+      ];
</file context>
Suggested change
"${homeDir}/dotfiles/.env"
"${homeDir}/.paperclip/instances/default/.env"
"-${homeDir}/dotfiles/.env"
"-${homeDir}/.paperclip/instances/default/.env"
Fix with Cubic

];
Comment on lines +39 to +42

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The EnvironmentFile directive in systemd will cause the service to fail to start if any of the specified files do not exist. Since these files (such as ~/dotfiles/.env or the instance-specific .env) might be missing on a fresh installation or before manual configuration, it is more robust to prefix the paths with -. This tells systemd to ignore the file if it is missing, allowing the service to attempt to start and let the application handle missing environment variables (consistent with the logic in hydrate.sh).

      EnvironmentFile = [
        "-${homeDir}/dotfiles/.env"
        "-${homeDir}/.paperclip/instances/default/.env"
      ];

Comment on lines +39 to +42

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

EnvironmentFile entries will cause service failure if files are missing.

Systemd's EnvironmentFile directive will fail service startup if the specified file doesn't exist. Consider prefixing with - to make them optional if that's acceptable, or ensure the files are created before service start.

       EnvironmentFile = [
-        "${homeDir}/dotfiles/.env"
-        "${homeDir}/.paperclip/instances/default/.env"
+        "-${homeDir}/dotfiles/.env"
+        "-${homeDir}/.paperclip/instances/default/.env"
       ];

Alternatively, if these files are strictly required, add assertions or activation scripts to validate their existence.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
EnvironmentFile = [
"${homeDir}/dotfiles/.env"
"${homeDir}/.paperclip/instances/default/.env"
];
EnvironmentFile = [
"-${homeDir}/dotfiles/.env"
"-${homeDir}/.paperclip/instances/default/.env"
];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@home-manager/modules/paperclip/default.nix` around lines 43 - 46, The
EnvironmentFile entries under EnvironmentFile will cause service failure if the
files are missing; update the EnvironmentFile array to mark the entries optional
by prefixing each path with "-" (e.g. "-${homeDir}/dotfiles/.env") so systemd
won't fail when a file is absent, or alternatively add an assertion or an
activation script that creates/validates the files before the service starts;
locate the EnvironmentFile attribute in the Nix service declaration and apply
one of these fixes to ensure the service doesn't fail on missing files.

WorkingDirectory = "${repoDir}";

Copilot AI Apr 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The service now WorkingDirectorys into ${repoDir}, but this module doesn't ensure the repo exists. If the directory is missing (fresh machine, different ghq root, etc.), systemd will fail with a CHDIR error and keep restarting. Consider adding a ConditionPathIsDirectory= / AssertPathIsDirectory= in the unit, or an ExecStartPre check that exits with a clear log message when the repo isn't present.

Copilot uses AI. Check for mistakes.
StandardOutput = "append:/tmp/paperclip/paperclip.log";
StandardError = "append:/tmp/paperclip/paperclip.log";
};
Expand Down
Loading