ryantm / agenix

age-encrypted secrets for NixOS and Home manager
https://matrix.to/#/#agenix:nixos.org
Creative Commons Zero v1.0 Universal
1.55k stars 119 forks source link

sedBin vs jq #147

Closed n8henrie closed 1 year ago

n8henrie commented 1 year ago

Currently you're using sed in several piped steps that seem a fair amount more complex and less readable than just using the --json flag to nix-instantiate and jq -r .[] to spit out the lines. Is this on purpose?

If not, would you consider a PR to this effect? Seems to work in my prelim testing, looks like you could completely replace the sedBin dependency with e.g. jqBin.

ryantm commented 1 year ago

I'm somewhat worried about the closure-size impact of bringing in jq. I haven't investigated it though.

n8henrie commented 1 year ago

Fair enough.

Pre:

$ nix path-info -Sh .
/nix/store/ls0sndy28y5iphp9xk0l284nzr5r914d-agenix       106.2M

Post:

$ nix path-info -Sh .
/nix/store/lpm8p1mngxhik7lk38khwbqbm93qsa9x-agenix       106.9M

Not totally sure that's the right way to measure that.

ryantm commented 1 year ago

I think it's more like this:

nix path-info -rsS . | cut - -f 3 | awk '{s+=$1} END {print s}' | numfmt --to=iec

current

1.8G

vs with jq

1.9G

So not that big of a difference. I wonder how many of those packages are commonly on people's systems anyway though.

n8henrie commented 1 year ago

Hmmm. Answers from https://unix.stackexchange.com/questions/665718/how-to-get-the-size-of-a-nix-derivation give me results more like the 106M:

$ git fetch upstream main
$ git checkout upstream/main
$ nix-store -q --requisites $(nix build --print-out-paths . ) | sort -u | xargs du -bc | tail -1
110898532       total
$ numfmt --to=iec 110898532
106M
$ git checkout sed_vs_jq
$ git rebase upstream/main
$ nix-store -q --requisites $(nix build --print-out-paths . ) | sort -u | xargs du -bc | tail -1
111625108       total
$ numfmt --to=iec $(( 111625108 - 110898532 ))
710K

This seems pretty consistent:

$ nix store diff-closures /nix/store/iqgvxqz16lpxqd2yg4n5lxgiya7qw7ry-agenix-0.13.0 /nix/store/fh73af13pm9yhzd6rnalvps08zqh16mv-agenix-0.13.0
gnused: 4.9 → ∅, -252.7 KiB
jq: ∅ → 1.6, +373.0 KiB
oniguruma: ∅ → 6.9.8, +590.4 KiB
As a tangentially related aside: Of course I always confuse base 1000 and base 1024 sizes, and apparently my Mac has a 4096 byte block size which is maybe confusing du? ```console $ diskutil info /nix | grep "Block Size" Device Block Size: 4096 Bytes Allocation Block Size: 4096 Bytes ``` BSD du and coreutils du (my default) giving very confusing results with the `-A` / `--apparent-size` and specifying blocksize=1. ¯\\\_(ツ)_/¯ ```console $ dd if=/dev/random of=./foo bs=1 count=1024 1024+0 records in 1024+0 records out 1024 bytes (1.0 kB, 1.0 KiB) copied, 0.003456 s, 296 kB/s $ stat foo File: foo Size: 1024 Blocks: 8 IO Block: 4096 regular file Device: 1,24 Inode: 228876650 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 501/n8henrie) Gid: ( 20/ staff) Access: 2023-02-13 09:29:04.507251424 -0700 Modify: 2023-02-13 09:52:32.910367958 -0700 Change: 2023-02-13 09:52:32.910367958 -0700 Birth: 2023-02-13 09:29:04.507251424 -0700 $ du --apparent-size -B1 ./foo 1024 ./foo $ /usr/bin/du -A -B1 ./foo 2 ./foo ``` Gah I'm so confused.