NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.32k stars 14.29k forks source link

steampipe doesn't start #215945

Open jkozak opened 1 year ago

jkozak commented 1 year ago

Describe the bug

I may be doing something wrong, but the out-of-box experience is disappointing,

Steps To Reproduce

~$ nix-shell -p steampipe

[nix-shell:~]$ steampipe plugin list

+-------------------------------------------------------------------+
|                                                                   |
| A new version of Steampipe is available! 0.16.4 → 0.18.5          |
| You can update by downloading from https://steampipe.io/downloads |
|                                                                   |
+-------------------------------------------------------------------+

Error: Plugin Listing failed - Initializing database... FAILED!

Expected behavior

list installed plugins

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[nix-shell:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.89, NixOS, 22.11 (Raccoon), 22.11.2301.cff83d5032a`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(jk): `""`
 - channels(root): `"nixos-22.11, nixos-unstable"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
kolpav commented 1 year ago

The steampipe makes assumptions about filesystem and tries to install packages on its own

https://github.com/turbot/steampipe/blob/e88d75a692ed6f7fb131bd153d1375a6036d53ef/pkg/db/db_local/install.go#L194-L203

maybe there is some obvious patch on nix side so steampipe can install its embeded postgre binnary somehow.

vielmetti commented 1 year ago

When I do this installation now, it seems to work, with this version reported:

[nix-shell:~/steampipe-environment]$ steampipe --version
Steampipe v0.18.6
DewaldV commented 1 year ago

I'm quite new to NixOS myself but digging into these issues a bit helps me get to grips with it a bit better. :smile:

I tried v0.18.6 but I'm still seeing the same Error: Plugin Listing failed - Initializing database... FAILED! error.

A bit of spelunking turns up the following:

➜  ~ STEAMPIPE_LOG=trace steampipe query
2023-03-04 20:38:14.274 UTC [TRACE] steampipe: parse complete after 1 decode passes
2023-03-04 20:38:14.274 UTC [TRACE] steampipe: ensureInstallDir /home/dewaldv/.steampipe
2023-03-04 20:38:14.275 UTC [TRACE] steampipe: No memory limit set
2023-03-04 20:38:14.275 UTC [TRACE] steampipe: no modfile exists in workspace folder - NOT creating pseudoresources and only loading resource files from top level folder
2023-03-04 20:38:14.275 UTC [TRACE] steampipe: parse complete after 1 decode passes
2023-03-04 20:38:14.275 UTC [TRACE] steampipe: parse complete after 1 decode passes
2023-03-04 20:38:14.275 UTC [TRACE] steampipe: Workspace load took 0ms
Welcome to Steampipe v0.18.6
For more information, type .help
2023-03-04 20:38:14.275 UTC [TRACE] steampipe: telemetry.Init service 'steampipe', tracingEnabled: false, metricsEnabled: false
2023-03-04 20:38:14.275 UTC [TRACE] steampipe: metrics and tracing disabled' - returning
                                    > 2023-03-04 20:38:14.292 UTC [TRACE] steampipe: initdb start: /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/initdb --auth=trust --username=root --pgdata=/home/dewaldv/.steampipe/db/14.2.0/data --encoding=UTF-8
2023-03-04 20:38:14.292 UTC [TRACE] steampipe: initdb failed:
2023-03-04 20:38:14.292 UTC [TRACE] steampipe: initDatabase failed: fork/exec /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/initdb: no such file or directory

Error: Initializing database... FAILED!

That path does exist

➜  ~ ls -l /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/initdb
-rwxr-xr-x 1 dewaldv users 132402 May  5  2022 /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/initd

So it might be something's linked incorrectly?

➜  ~ ldd /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/initdb
        linux-vdso.so.1 (0x00007ffc476e6000)
        libpq.so.5 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libpq.so.5 (0x00007f6224400000)
        libpthread.so.0 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libpthread.so.0 (0x00007f622475f000)
        librt.so.1 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/librt.so.1 (0x00007f622475a000)
        libc.so.6 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libc.so.6 (0x00007f6224000000)
        libssl.so.1.0.0 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libssl.so.1.0.0 (0x00007f6223c00000)
        libcrypto.so.1.0.0 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libcrypto.so.1.0.0 (0x00007f6223800000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib64/ld-linux-x86-64.so.2 (0x00007f6224766000)
        libdl.so.2 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libdl.so.2 (0x00007f6224753000)

I followed the rabbit hole and all of those libraries to seem to exist where they are expected to with the exception of the linker /lib64/ld-linux-x86-64.so.2. It's pointing to something that does exist there though: /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib64/ld-linux-x86-64.so.2

If I, quite hackily, create a symlink at /lib64/ld-linux-x86-64.so.2 to /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib64/ld-linux-x86-64.so.2 to get around that I get one step farther but then postgres itself dies with:

/home/dewaldv/.steampipe/db/14.2.0/postgres/bin/postgres: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
➜  ~ ldd /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/postgres
        linux-vdso.so.1 (0x00007ffe80571000)
        libxml2.so.2 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libxml2.so.2 (0x00007f3834200000)
        libssl.so.1.0.0 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libssl.so.1.0.0 (0x00007f3833e00000)
        libcrypto.so.1.0.0 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libcrypto.so.1.0.0 (0x00007f3833a00000)
        libpthread.so.0 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libpthread.so.0 (0x00007f38345f3000)
        librt.so.1 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/librt.so.1 (0x00007f38345ee000)
        libdl.so.2 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libdl.so.2 (0x00007f38345e7000)
        libm.so.6 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libm.so.6 (0x00007f3834120000)
        libicui18n.so.52 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libicui18n.so.52 (0x00007f3833400000)
        libicuuc.so.52 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libicuuc.so.52 (0x00007f3833000000)
        libc.so.6 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libc.so.6 (0x00007f3832c00000)
        libz.so.1 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libz.so.1 (0x00007f3832800000)
        liblzma.so.5 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/liblzma.so.5 (0x00007f3832400000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib64/ld-linux-x86-64.so.2 (0x00007f38345fa000)
        libstdc++.so.6 => not found
        libgcc_s.so.1 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libgcc_s.so.1 (0x00007f38345cb000)
        libicudata.so.52 => /home/dewaldv/.steampipe/db/14.2.0/postgres/bin/../lib/libicudata.so.52 (0x00007f3830a00000)
        libstdc++.so.6 => not found

So if I completely hack it and just add libstdc++.so.6 to LD_LIBRARY_PATH to test:

export LD_LIBRARY_PATH=/nix/store/v8481v3a686aa0pa4d016c0lnz2j0wwb-gcc-11.3.0-lib/lib/

Then, we're in business!

➜  ~ steampipe query
Welcome to Steampipe v0.18.6
For more information, type .help
>

Obviously symlinking random versions of ld-linux.so and libstdc++.so.6 is not the solution so I'm guessing the postgres that steampipe pulls needs to be patched somehow?

I'm still learning about derivations and patching so not sure I can help more than this but I'm happy to test or learn more Nix-y things! :smile:

nix-info for my system below:

➜  ~ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.14, NixOS, 22.11 (Raccoon), 22.11.20230302.96e1871`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(root): `"nixos-22.11, nixos-hardware"`
 - channels(dewaldv): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
sashkachan commented 1 year ago

@DewaldV As you found out, steampipe pulls postgres binaries to embed the database. This means that it's not build by Nix, and without some out-of-band patching, the binaries do not work.

There are a few ways I found to resolve this:

This last method seemed like the least effort, and worked out of the box for me.

perestro1ka commented 11 months ago

For anyone that comes across this at a later date, for me at least ive found the most simple way to do this is with their docker container:

You could easily translate all this to a layered docker image extended with even more options etc within the nix flake itself if you wanted to