Make global environment available to CGI script?

Hi, I’m trying to get the mighttpd2 CGI server to run my .cgi scripts.

But mighttpd2 already fails at the .cgi script’s first line #!/usr/bin/env bash saying ‘bash: no such file or directory’. For the user under which mighttpd2 runs, bash is available.

Any idea how I can share the global environment with the .cgi scripts?

systemd services run with a restricted environment normally. You can add to the .service file an option to set an environment variable, including PATH, or, for a quick workaround, you could also just use the static absolute path to the system-wide installed version, /run/current-system/sw/bin/bash.

Thanks teying! But I don’t understand how I could change the .service file? NixOS generates the service file from this config:

  services.mighttpd2 = {
    enable = true;
    config = ''
      Port: 1234
    '';
    routing = ''
      [*]
      /cgi-bin/ => /var/www/cgi-bin/
    '';
  };

… and the mighttpd2 only has this 3 and one more keys.

You can see in the module that it’s setting options under systemd.services.mighttpd2 in order to create the service. You can thus set systemd.services.mighttpd2.environment.PATH = "whatever you want the PATH to be"; in order to set the PATH that the service runs with.

You may want to use lib.makeBinPath to create the string.

EDIT: Actually, you should use systemd.services.mighttpd2.path = [ pkgs.foo pkgs.bar ]; instead.

1 Like

Please use systemd.services.mighthttp2.path instead!

2 Likes

Thank you. Right, setting PATH doesn’t work (“error: The option `systemd.services.mighttpd2.environment.PATH’ has conflicting definition values:”).

It works with this line:

systemd.services.mighttpd2.path = [ pkgs.bash ];

Note that if a path as string is given, “/bin” and “/sbin” are appended automatically.

Thank you both!

NO!

Just pass the drvs you really need. This makes your application depend on the state of your system

1 Like