Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem running Ultorg on NixOS #34

Closed
alf opened this issue Sep 4, 2022 · 14 comments
Closed

Problem running Ultorg on NixOS #34

alf opened this issue Sep 4, 2022 · 14 comments

Comments

@alf
Copy link

alf commented Sep 4, 2022

NixOS is a different Linux. I won't go into detail here, instead I refer to the documentation: How NixOS works.

Suffice to say is that the bundled Postgres-server won't work here. It can be made to work by patching the ELF-binary, however I would prefer to provide my own installation of Postgres.

I've changed my ultorg.conf to the following:

default_userdir="${DEFAULT_USERDIR_ROOT}/prod1"
default_mac_userdir="${DEFAULT_USERDIR_ROOT}/prod1"
default_cachedir="${DEFAULT_CACHEDIR_ROOT}/prod1"
default_options="--branding ultorg -J-Xms512m -J-Xmx3072m -J-Dnetbeans.ps.noHelpButton=true -J-Dpolyglot.engine.WarnInterpreterOnly=false -J-Djdk.gtk.version=2.2 -J-Dultorg.pgbin=/nix/store/h99i948qzkhwlwk9rv1szcg50235ki29-postgresql-and-plugins-13.7/bin -J--add-opens=java.base/java.net=ALL-UNNAMED -J--add-opens=java.base/java.lang.ref=ALL-UNNAMED -J--add-opens=java.base/java.lang=ALL-UNNAMED -J--add-opens=java.base/java.security=ALL-UNNAMED -J--add-opens=java.base/java.util=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing.text=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing=ALL-UNNAMED -J--add-opens=java.desktop/java.awt=ALL-UNNAMED -J--add-opens=java.desktop/java.awt.event=ALL-UNNAMED -J--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED -J--add-exports=java.desktop/sun.awt=ALL-UNNAMED -J--add-exports=java.desktop/java.awt.peer=ALL-UNNAMED -J--add-exports=java.desktop/com.sun.beans.editors=ALL-UNNAMED -J--add-exports=java.desktop/sun.swing=ALL-UNNAMED -J--add-exports=java.desktop/sun.awt.im=ALL-UNNAMED -J--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED -J--add-exports=java.management/sun.management=ALL-UNNAMED -J--add-exports=java.base/sun.reflect.annotation=ALL-UNNAMED -J--add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED"
jdkhome="/nix/store/6jxg5lqsw6w6dh6an8cpqrc1ykgwxz9k-openjdk-17.0.3+7/"

In theory this should work, however I'm still stuck. Here's the Application.log, hopefully there is something more that can be done?

My diagnosis is that I need to provide some extra arguments to postgres to make it use a different database from the system wide which is owned by the postgres user. I don't see how to do that.

@eirikbakke
Copy link
Contributor

Hi, Alf. Thank you for your help debugging this! I think you're close to getting Ultorg running...

You can try adding the line

unix_socket_directories = ''

to the end of the file

~/.ultorg/prod1/UltorgLocal/pgbundledata/postgresql.conf

(If this works I might make this adjustment myself in future Ultorg versions.)

@eirikbakke
Copy link
Contributor

Hmm, or perhaps that folder won't end up having been created yet, since the initial run failed...

Perhaps try giving the current user temporary write/create access to the folder /run/postgresql (which you may have to temporarily create), then run Ultorg once, and once that works, you can go in and change postgresql.conf as described above, and then finally restore the original permissions on the /run/postgresql folder.

@alf
Copy link
Author

alf commented Sep 4, 2022

Excellent, I got it working now.

The ~/.ultorg/prod1/UltorgLocal/pgbundledata/postgresql.conf file did not exist, so I made myself owner of the /run/postgresql folder and started ultorg. This time it started successfully. Then I exited and reverted the owner.

I tried starting ultorg again and it failed. This time the ~/.ultorg/prod1/UltorgLocal/pgbundledata/postgresql.conf existed so I made the change you suggested. Voila.

We can close this issue now if you wish. I’m up and running.

@eirikbakke
Copy link
Contributor

Great, thank you! I will make a change to future Ultorg versions to avoid the unix_socket_directories problem.

@eirikbakke
Copy link
Contributor

Oh, and I'd still love to see what errors you might get from the following command:

ultorg/pg/13.3-linux_x64/bin/initdb -D testdir

(The bundled PostgreSQL binaries are meant to include their own dependencies, with ELF patching already done, so I was curious to see which remaining problems there might be on NixOS.)

Thanks for your help!

@alf
Copy link
Author

alf commented Sep 4, 2022

Trying to run initdb on NixOS:

[alf@powerpad:~/.local/ultorg]$ ./pg/13.3-linux_x64/bin/initdb 
bash: ./pg/13.3-linux_x64/bin/initdb: No such file or directory

[alf@powerpad:~/.local/ultorg]$ patchelf --print-interpreter pg/13.3-linux_x64/bin/initdb
/lib64/ld-linux-x86-64.so.2

[alf@powerpad:~/.local/ultorg]$ ls /lib64
ls: cannot access '/lib64': No such file or directory

[alf@powerpad:~/.local/ultorg]$ patchelf --print-interpreter /nix/store/h99i948qzkhwlwk9rv1szcg50235ki29-postgresql-and-plugins-13.7/bin/.initdb-wrapped 
/nix/store/qjgj2642srlbr59wwdihnn66sw97ming-glibc-2.33-123/lib/ld-linux-x86-64.so.2

[alf@powerpad:~/.local/ultorg]$ patchelf --set-interpreter /nix/store/qjgj2642srlbr59wwdihnn66sw97ming-glibc-2.33-123/lib/ld-linux-x86-64.so.2 pg/13.3-linux_x64/bin/initdb

[alf@powerpad:~/.local/ultorg]$ ./pg/13.3-linux_x64/bin/initdb 
initdb: error: no data directory specified
You must identify the directory where the data for this database system
will reside.  Do this with either the invocation option -D or the
environment variable PGDATA.

@eirikbakke
Copy link
Contributor

Thank you for that! I'm learning new things about how dynamic libraries work on various Linux distros :-)

Do you get similar problems running the bundled Java distro? E.g. the following command:

jre/17.34.19-ca-jdk17.0.3-linux_x64/bin/java --version

I guess the "right" way to fix this in Ultorg is to provide a distro-specific package... but sometimes there are tweaks I can make in the builds that make it work on more systems out-of-the-box.

@alf
Copy link
Author

alf commented Sep 4, 2022

The bundled Java has additional issues. It assumes some extra OS-level libraries that must also be patched by changing the rpath of the binary.

I gave up on getting that working, opting for an external jdk instead. I can give you some more details here later, I’ve put my computer down for the evening. ;)

@alf
Copy link
Author

alf commented Sep 4, 2022

I wouldn’t spend much time on this if I were you. The existence of this issue should be enough to cover Nix for now IMHO. Focus on the larger audience. :)

@eirikbakke
Copy link
Contributor

OK, good, if OpenJDK can't get it working out-of-the-box either, then I won't feel so bad about it :-)

But good to know there are workarounds! Thank you for working this out!

@eirikbakke
Copy link
Contributor

I've put up another Ultorg release now, with the unix_socket_directories setting disabled by default from now on. It's good to avoid potential permissions issues on other Linux distros as well. And in any case I want the Ultorg-managed PostgreSQL instance to be as compartmentalized as possible, not interfering with other database instances that might be running on the same machine, and not accepting connections from anywhere else.

Thanks again for the report!

@DrRuhe
Copy link

DrRuhe commented Oct 4, 2022

I wouldn’t spend much time on this if I were you. The existence of this issue should be enough to cover Nix for now IMHO. Focus on the larger audience. :)

Hi, could you maybe share how you got it to work? I'm trying to build a derivation that provides ultorg but I am bashing my head against the whole mkDerivation thing without making any significant progress. Currently I have this flake.nix:

{
  description = "";

  inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
        ultorg-src ={
            url="https://ultorgbeta.s3.us-west-004.backblazeb2.com/u1.2.2/ultorg-1.2.2-linux_x64.zip?<USER-SPECIFIC-TOKENS>";
            flake = false;
        };
    };

  outputs = { self, nixpkgs,ultorg-src,... }:

  let
    system="x86_64-linux";

    ultorg = with import nixpkgs { inherit system; };
      stdenv.mkDerivation rec {
      pname = "ultorg";
      version = "1.2.2";

      src = ultorg-src;

      nativeBuildInputs = [
        autoPatchelfHook
      ];

      buildInputs = [
      ];

      sourceRoot = ".";

      installPhase = ''
        install -m755 -D bin/ultorg $out/bin/ultorg
      '';

      meta = {
        homepage = "https://www.ultorg.com/#top";
        description = "DB Tool";
        platforms = nixpkgs.lib.platforms.linux;
      };
    };
  in
  {
    packages.x86_64-linux.ultorg = ultorg;
    defaultPackage.x86_64-linux = self.packages.x86_64-linux.ultorg;
  };
}

But this does not work.

Before I tried to run the extracted bin/ultorg directly, but that threw:

Detected KDE; adding awt.useSystemAAFontSettings=on
/<directory>/ultorg/bin/../platform/lib/nbexec: Zeile 430:/<directory>/ultorg/jre/17.34.19-ca-jdk17.0.3-linux_x64/bin/java: No such file or directory

so I wanted to pack it up in a flake that just works TM. I guess I have to have an openjdk in PATH, but admittedly I haven't gotten to that part yet :/

@alf
Copy link
Author

alf commented Oct 4, 2022

You need to patch the bundled jre in Ultorg, or you must bring your own. I opted for the latter approach. I’ve yet to work with flakes, but I suspect you can add a jre to buildinputs and patch the ultorg startup script or default configuration so that it uses this jre instead of the bundled one.

That should be the jdkhome-option if I remember correctly.

@eirikbakke
Copy link
Contributor

For NixOS I think Alf's successful approach was to install OpenJDK 17 and PostgreSQL 13 separately (rather than trying to patch the bundled binaries). Then edit ultorg/etc/ultorg.conf to change the path after "ultorg.pgbin=" (on a very long line) and the path after "jdkhome=" to point directly to the directories containing the local distro-specific binaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants