Skip to content

Commit ac86367

Browse files
tmpltkiriwalawren
andauthored
lib/secrets: trim all right-hand newlines with jq (#237)
Passwords declared in external files can now end with multiple newlines. Consider: bash> cat --show-all /path/to/secret/password hunter2$ $ bash> # Before (with rstrimstr): bash> jq -n --rawfile passwordContent /path/to/secret/password \ '{password: ($passwordContent | rtrimstr("\n")), }' { "password": "hunter2\n" } bash> # After (with regex): bash> jq -n --rawfile passwordContent /path/to/secret/password \ '{password: ($passwordContent | sub("\n+$"; "")), }' { "password": "hunter2" } Co-authored-by: Kiri Carlson <kiri@walawren.com>
1 parent cf00e69 commit ac86367

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
88

99
### Fixed
1010

11+
- `_secret` pattern not trimming all terminating newlines in decrypted files.
1112
- qBittorrent potentially starting before `nixflix.serviceDependencies` and thus losing track of downloaded files, lest a recheck was manually forced.
1213

1314
### Added

lib/secrets/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ rec {
6464
else if isSecretRef value then
6565
{
6666
flag = "--rawfile ${name}Content ${lib.escapeShellArg (toString value._secret)}";
67-
ref = "($" + name + "Content | rtrimstr(\"\\n\"))";
67+
ref = "($" + name + "Content | sub(\"\\n+$\"; \"\"))";
6868
}
6969
else
7070
{
@@ -124,7 +124,7 @@ rec {
124124
let
125125
jqPath = "." + lib.concatMapStringsSep "" (k: ''["${k}"]'') ref.path;
126126
in
127-
"${jqPath} = ($" + ref.varName + ''Content | rtrimstr("\n"))''
127+
"${jqPath} = ($" + ref.varName + ''Content | sub("\n+$"; ""))''
128128
) indexedRefs;
129129
in
130130
{

0 commit comments

Comments
 (0)