How to install libraries for a user using home-manager

23.11.4976.79baff8812a0 (Tapir)
system: “x86_64-linux”, multi-user?: yes, version: nix-env (Nix) 2.18.1, channels(root): “”, nixpkgs: /nix/store/q257q32a8xkh45d95di81kvqhi743n21-source

I am having trouble installing libraries for nixos. I don’t want to use nix-shell, as I want all of my config in configuration.nix (including home-manager). I also don’t want to use flakes until they are stable. I am specifically trying to get Tauri to work for my user.

I tried installing the cargo-tauri package, but it didn’t bring in the stuff it needed. It did work to generate a tauri application, but when I tried cargo tauri dev, it failed.

I then turned to ChatGPT (I know, but it helps me think through the problem and has solved issues in the past). ChatGPT suggested I set home.sessionVariables like this:

    home.sessionVariables = with pkgs; {
      LD_LIBRARY_PATH = lib.concatStringsSep ":" [
        (lib.makeLibraryPath [
          webkitgtk
          gtk3
          cairo
          gdk-pixbuf
          glib
          dbus
          openssl
        ])
        "$LD_LIBRARY_PATH"
      ];
      PKG_CONFIG_PATH = lib.concatStringsSep ":" [
        "${glib.dev}/lib/pkgconfig"
        "${gtk3.dev}/lib/pkgconfig"
        "$PKG_CONFIG_PATH"
      ];
      XDG_DATA_DIRS = lib.concatStringsSep ":" [
        "${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
        "${gtk3}/share/gsettings-schemas/${gtk3.name}"
        "$XDG_DATA_DIRS" # Include the default directories
      ];
    };

However, this seems to have no effect:

[me@nixos:~/nixos]$ echo "$LD_LIBRARY_PATH $PKG_CONFIG_PATH"
[no output]

If I echo XDG_DATA_DIRS, it at least has something in it:

[me@nixos:~/nixos]$ echo "$XDG_DATA_DIRS"
/nix/store/kjb6cr1jy4zzzm03qab8lcxqbiskjcbi-vscode-1.85.2/share:/nix/store/09ng7id140s4xrj5lmpjf6j4pp21ylbv-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0:/nix/store/gmwrvdh4vxn3rimbvnm6b8abpaj75lxc-gtk+3-3.24.41/share/gsettings-schemas/gtk+3-3.24.41:/nix/store/0w7id989jjzn1a6ki54fykrfqccidy5q-shared-mime-info-2.4/share:/nix/store/z4wr53w2zzl6c05riism78fdpdsjf87h-gnome-shell-45.4/share:/nix/store/y1rdx5rvhxjrhx6bdw7gn8iv5if0bhqh-gtk4-4.12.5/share/gsettings-schemas/gtk4-4.12.5:/nix/store/3sb6pbr2w9lm1w71fn2b22f2vhg1k3qx-gnome-keyring-42.1/share/gsettings-schemas/gnome-keyring-42.1:/nix/store/d287bjz948wclavbka0inqx4r4dpvpxz-mutter-45.4/share/gsettings-schemas/mutter-45.4:/nix/store/5zldin34ypb6ai4l755khkr9k3wcbx8x-evolution-data-server-3.50.3/share/gsettings-schemas/evolution-data-server-3.50.3:/nix/store/fsb9g5hqv777yaw9rb3hdf09cjcqk120-gdm-45.0.1/share/gsettings-schemas/gdm-45.0.1:/nix/store/v1wak2gqza490mbfkhqcsaz2cf52wsdk-gnome-clocks-45.0/share/gsettings-schemas/gnome-clocks-45.0:/nix/store/vabqdciv7qvid6knxwg7i63s918y70gq-ibus-1.5.28/share/gsettings-schemas/ibus-1.5.28:/nix/store/avyhvw2ajag2blg4dxmsqy07wam5qmgf-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1:/nix/store/1s3wax9zv3r0gpkrqb451535dqi97klm-libgweather-4.4.0/share/gsettings-schemas/libgweather-4.4.0:/nix/store/wqsw5dj0va55bcki7iv1sykfnl1blgc6-libnma-1.10.6/share/gsettings-schemas/libnma-1.10.6:/nix/store/z4wr53w2zzl6c05riism78fdpdsjf87h-gnome-shell-45.4/share/gsettings-schemas/gnome-shell-45.4:/nix/store/gvdg3hafq07i7krirxm0mq3sywkzq0ha-gnome-mimeapps/share:/nix/store/kd1dsd28wmc302290g045h7cawfnja2m-desktops/share:/home/jadelynnmasker/.nix-profile/share:/nix/profile/share:/home/jadelynnmasker/.local/state/nix/profile/share:/etc/profiles/per-user/jadelynnmasker/share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share:/nix/store/z4wr53w2zzl6c05riism78fdpdsjf87h-gnome-shell-45.4/share/gsettings-schemas/gnome-shell-45.4:/nix/store/d6r37yy96105g54mybx4xj5abmwbbpsm-gnome-shell-extensions-45.2/share/gsettings-schemas/gnome-shell-extensions-45.2:/nix/store/5a6d3xi6j49ah5jlxsjg28js064wlkym-gnome-session-45.0/share:/nix/store/09ng7id140s4xrj5lmpjf6j4pp21ylbv-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0:/nix/store/gmwrvdh4vxn3rimbvnm6b8abpaj75lxc-gtk+3-3.24.41/share/gsettings-schemas/gtk+3-3.24.41:/nix/store/avyhvw2ajag2blg4dxmsqy07wam5qmgf-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1:/nix/store/5a6d3xi6j49ah5jlxsjg28js064wlkym-gnome-session-45.0/share/gsettings-schemas/gnome-session-45.0:/nix/store/z4wr53w2zzl6c05riism78fdpdsjf87h-gnome-shell-45.4/share

I am frustrated that a) this isn’t done automatically and b) that this isn’t working anyway. I could be doing something “wrong”, but there are no errors that suggest this. It would be nice if there was a documented way to expose libraries auto-magically for either the whole system or specific users. But I am by no means an expert, so please educate me :smile:

Please don’t do that, it will potentially mess up other programs in your system.

Why not use nix-shell with a shell.nix?

{pkgs ? import <nixpkgs> {}}: pkgs.mkShell {
  packages = with pkgs; [
    gtk3
    webkitgtk
    # blah blah blah...
  ];
}

This should set all the relevant environment variables automatically.

That is fine, but I want to have all my configuration in one file to make it easier to version control. Alternatively, if there is an easier way to version control, I’d be down for that. Currently I have a script copy the files in /home/me/nixos to /etc/nixos after committing the changes and pushing to github. I am using rsync for this. I suppose I could copy a file to my home directory, but it would make things more complicated.

Maybe I am doing this all wrong, I am open to suggestions.