Script in configuration.nix not executed completely, no error message

I tried this for several days now but i can’t find the reason for it:

In configuration.nix i’ve defined:

  nix.settings.experimental-features = [ "nix-command" ];
  system.activationScripts.diff = ''
    if [[ -e /run/current-system ]]; then
      ${pkgs.nix}/bin/nix store diff-closures /run/current-system "$systemConfig" | grep -w "→" | grep -w "KiB" | column --table --separator " ,:" | ${pkgs.choose}/bin/choose 0:1 -4:-1 | column --table | sort -k5,5gr
    fi
  '';

It works but it doesn’t sort the output regarding column 5:

accounts-qt               ∅  →        1.16              +1737.6    KiB
avidemux                  ∅  →        2.8.1             +38853.4   KiB
cjson                     ∅  →        1.7.15            +67.6      KiB
ebook-tools               ∅  →        0.2.2             +88.7      KiB
eigen                     ∅  →        3.4.0             +8592.6    KiB
ffmpeg-full               ∅  →        4.4.2             +37349.5   KiB
fftw-double               ∅  →        3.3.10            +1839.7    KiB
frei0r-plugins            ∅  →        1.7.0             +3212.2    KiB
gcc-wrapper               ∅  →        11.3.0            +55.2      KiB
id3lib                    ∅  →        3.8.3             +523.9     KiB
intel-media-sdk           ∅  →        22.5.4            +29852.5   KiB
kaccounts-integration     ∅  →        22.08.3           +743.9     KiB
kdenlive                  ∅  22.08.3  22.08.3_fish      +70344.4   KiB
kfilemetadata             ∅  →        5.100.0           +1373.2    KiB
kinit                     ∅  →        5.100.0           +836.7     KiB
knotifyconfig             ∅  →        5.100.0           +432.1     KiB
kparts                    ∅  →        5.100.0           +912.7     KiB
kplotting                 ∅  →        5.100.0           +133.5     KiB
kwave                     ∅  →        22.08.3           +18058.5   KiB
libaccounts-glib          ∅  →        1.24              +504.8     KiB
libdvbpsi                 ∅  →        1.3.3             +586.3     KiB
libebml                   ∅  →        1.4.4             +321.7     KiB
libmatroska               ∅  →        1.7.1             +1102.2    KiB
libmysofa                 ∅  →        1.3.1             +1363.2    KiB
librist                   ∅  →        0.2.7             +374.1     KiB
libupnp                   ∅  →        1.14.14           +1166.9    KiB
libvlc                    ∅  →        3.0.18            +58809.7   KiB
libzip                    ∅  →        1.9.2             +232.8     KiB
luajit                    ∅  →        2.1.0-2022-10-04  +2062.3    KiB
mbedtls                   ∅  →        2.28.2            +7334.4    KiB
mlt                       ∅  →        7.8.0             +2878.9    KiB
movit                     ∅  →        1.6.3             +735.1     KiB
obs-studio                ∅  →        28.1.2            +368237.0  KiB
phonon-backend-gstreamer  ∅  →        4.10.0            +700.2     KiB
poppler-qt5               ∅  →        22.11.0           +5604.3    KiB
purpose                   ∅  →        5.100.0           +2193.2    KiB
qtmultimedia              ∅  →        5.15.7            +2868.7    KiB
qtnetworkauth             ∅  →        5.15.7            +219.7     KiB
schroedinger              ∅  →        1.0.11            +843.0     KiB
SDL_image                 ∅  →        1.2.12            +74.5      KiB
signond                   ∅  →        8.61              +4800.1    KiB
svt-av1                   ∅  →        1.2.1             +9513.5    KiB
swh-plugins               ∅  →        0.4.17            +2520.2    KiB
vid.stab-unstable         ∅  →        2022-05-30        +160.8     KiB
vo-amrwbenc               ∅  →        0.1.3             +120.7     KiB
xavs                      ∅  →        55                +1492.6    KiB
zeromq                    ∅  →        4.3.4             +5277.5    KiB

However, when i save the output to a file and run the same sort command on it again, it works fine:

~ ❯ cat file | sort -k5,5gr                                                                                                       10s
obs-studio                ∅  →        28.1.2            +368237.0  KiB
kdenlive                  ∅  22.08.3  22.08.3_fish      +70344.4   KiB
libvlc                    ∅  →        3.0.18            +58809.7   KiB
avidemux                  ∅  →        2.8.1             +38853.4   KiB
ffmpeg-full               ∅  →        4.4.2             +37349.5   KiB
intel-media-sdk           ∅  →        22.5.4            +29852.5   KiB
kwave                     ∅  →        22.08.3           +18058.5   KiB
svt-av1                   ∅  →        1.2.1             +9513.5    KiB
eigen                     ∅  →        3.4.0             +8592.6    KiB
mbedtls                   ∅  →        2.28.2            +7334.4    KiB
poppler-qt5               ∅  →        22.11.0           +5604.3    KiB
zeromq                    ∅  →        4.3.4             +5277.5    KiB
signond                   ∅  →        8.61              +4800.1    KiB
frei0r-plugins            ∅  →        1.7.0             +3212.2    KiB
mlt                       ∅  →        7.8.0             +2878.9    KiB
qtmultimedia              ∅  →        5.15.7            +2868.7    KiB
swh-plugins               ∅  →        0.4.17            +2520.2    KiB
purpose                   ∅  →        5.100.0           +2193.2    KiB
luajit                    ∅  →        2.1.0-2022-10-04  +2062.3    KiB
fftw-double               ∅  →        3.3.10            +1839.7    KiB
accounts-qt               ∅  →        1.16              +1737.6    KiB
xavs                      ∅  →        55                +1492.6    KiB
kfilemetadata             ∅  →        5.100.0           +1373.2    KiB
libmysofa                 ∅  →        1.3.1             +1363.2    KiB
libupnp                   ∅  →        1.14.14           +1166.9    KiB
libmatroska               ∅  →        1.7.1             +1102.2    KiB
kparts                    ∅  →        5.100.0           +912.7     KiB
schroedinger              ∅  →        1.0.11            +843.0     KiB
kinit                     ∅  →        5.100.0           +836.7     KiB
kaccounts-integration     ∅  →        22.08.3           +743.9     KiB
movit                     ∅  →        1.6.3             +735.1     KiB
phonon-backend-gstreamer  ∅  →        4.10.0            +700.2     KiB
libdvbpsi                 ∅  →        1.3.3             +586.3     KiB
id3lib                    ∅  →        3.8.3             +523.9     KiB
libaccounts-glib          ∅  →        1.24              +504.8     KiB
knotifyconfig             ∅  →        5.100.0           +432.1     KiB
librist                   ∅  →        0.2.7             +374.1     KiB
libebml                   ∅  →        1.4.4             +321.7     KiB
libzip                    ∅  →        1.9.2             +232.8     KiB
qtnetworkauth             ∅  →        5.15.7            +219.7     KiB
vid.stab-unstable         ∅  →        2022-05-30        +160.8     KiB
kplotting                 ∅  →        5.100.0           +133.5     KiB
vo-amrwbenc               ∅  →        0.1.3             +120.7     KiB
ebook-tools               ∅  →        0.2.2             +88.7      KiB
SDL_image                 ∅  →        1.2.12            +74.5      KiB
cjson                     ∅  →        1.7.15            +67.6      KiB
gcc-wrapper               ∅  →        11.3.0            +55.2      KiB

How is this possible? What am i missing?

There is no error output and sort is in coreutils just as grep and column which work fine.

I gave that pipeline a try myself, and tried piping the output into hexdump -C. It looks like sort is getting caught on the ansi color sequences in the output. I’m not sure at what stage the escape sequences are being introduced, but they contain numbers, and so they all end up sorting the same by the argument you set. I’m not sure how you’re going about saving the output to a file, but I assume it isn’t with >, or you’d get the same behavior.

1 Like

This thread may give you joy.

However , it may not.

1 Like

Ah, that makes sense. I wasn’t aware that sort “sees” the color code and is led astray by it.

@tejing I copied the output the noob’s way: selecting it in the terminal and copying it to a file. This way the color wasn’t preserved and that’s why sort worked.

Using ansifilter works as a stopgap. When i’ve got time, i’ll maybe look into a way to sort while preserving the color or reintroducing the color after sorting. I haven’t found a reimplementation of sort so far, that is smart enough not to fall for that.

Thank you both for your help! :slightly_smiling_face:

1 Like

“nailed it” :slightly_smiling_face:

${pkgs.nix}/bin/nix store diff-closures /run/current-system "$systemConfig" | grep -w "→" | grep -w "KiB" | column --table --separator " ,:" | ${pkgs.choose}/bin/choose 0:1 -4:-1 | ${pkgs.gawk}/bin/awk '{s=$0; gsub(/\033\[[ -?]*[@-~]/,"",s); print s "\t" $0}' | sort -k5,5gr | ${pkgs.choose}/bin/choose 6:-1 | column --table

Thanks for pointing out the ANSI code, i guess i would have never found the reason for my problem.