Help Understanding the Nix Flake and OS Env


I have been working with Nix for a few weeks and I love it, but there are a couple of things I don’t understand.

I have a package for a C program that can spawn processes and run programs written in other languages.

Now, I integrated a Python script with a preamble, but the program aborted because it couldn’t find python3. Here’s the

error starting plugin '/nix/store/kqdyymv40kk0ml85ji5j3kxwnvk6348b-clightning-v23.08/libexec/c-lightning/plugins/clnrest/clnrest.py': opening pipe: No such file or directory

The python file starts with

#!/usr/bin/env python3

The nix package is defined as https://raw.githubusercontent.com/NixOS/nixpkgs/nixos-23.05/pkgs/applications/blockchains/clightning/default.nix


Why isn’t the Python file starting correctly? What’s the trick here?

I understand that Nix has its own environment and that the binary runs under a custom path. However, I feel I’m missing something. I’d be really grateful if someone could help me fix this issue and also help me understand what’s going on.

Can you connect the dots between this error message and your assertion that the failure is due to a failure to find python3?

Hey, sorry I did not paste much, this is the crash that show that the script is not able to
find python3

Aug 29 16:53:40 citrine lightningd[1193376]: /usr/bin/env: 'python3': No such file or directory
Aug 29 16:53:40 citrine lightningd[1193356]: lightningd: lightningd/plugin.c:1912: plugins_init: Assertion `ret == plugins' failed.
Aug 29 16:53:40 citrine lightningd[1193356]: lightningd: FATAL SIGNAL 6 (version v23.08)
Aug 29 16:53:40 citrine lightningd[1193356]: 0x47e3f9 send_backtrace

Generally speaking, shebangs for interpreted executables in a nix package should get rewritten with patchShebangs (it’ll replace something like /usr/bin/env python3 with an absolute path), but the clightning package doesn’t include this plugin in the list of files it patches:

So, narrowly, I guess there’s a packaging problem here that needs to get fixed in nixpkgs.

Looking upstream at the plugins (https://github.com/ElementsProject/lightning/tree/master/plugins) it looks like all of the others are compiled, and the one you’re trying to use might be the only python/interpreted plugin:

You could fix the narrow problem by adding it to the list of inputs to patchShebangs.

Unfortunately, fixing this alone isn’t enough to make this just work. If you look at the plugin upstream (https://github.com/ElementsProject/lightning/tree/master/plugins/clnrest), you’ll see that it has several additional Python dependencies that aren’t declared in clightning’s Nix expression.

I’m not sure if @jb55 or @prusnak will see this, but maybe they’ll have ideas on the best way to fix this plugin.

1 Like

Thanks I will take it from there now that I know what it is going on :slight_smile:

1 Like