Listing dependencies

Dear Nixers,
Thanks for nix, it helped me install lot of goodies on centos which otherwise was impossible.
I need help in adding dependencies for building a derivation.
I have read the pills and was able to build the basic hello package. Now I am trying to build ‘idesk’ which has below dependencies -

-xft-config //For Xlib anf X11 support (default)
-imlib2-config //For Imlib2 stuff (default)
-pkg-config //For libstartup-notification-1.0

I have added buildInputs = [ xorg.libXft xorg.libX11 xorg.libXScrnSaver xorg.libXcursor xorg.libXext xorg.libXft xorg.libXi xorg.libXrender xorg.libXt xorg.pixman xorg.xorgproto ]; in autotools.nix but no go
I get error - configure: error: Idesk requires the X Window System libraries and headers

pray tell me how to get it working, thanks.

a@a:~$ nix-env --version
nix-env (Nix) 2.3.5

It’s great that you’re trying out nix! Can you please show us the whole derivation you wrote? From my experience as a nix beginner some time ago, there are so many potential misconceptions that there is still much work to do between hello-world and anything non-trivial. But I promise you won’t regret it, the effort pays off - once something works, it will keep working.

1 Like

thanks for the encouragement, I love nix’s concept and how it keeps packages isolated from the system.

the drv -

a@a:~/Downloads/idesk$ nix show-derivation /nix/store/039sy4v9mmgpp74wywa64f4z59lhs36s-idesk.drv
{
  "/nix/store/039sy4v9mmgpp74wywa64f4z59lhs36s-idesk.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/r26qrz0qscvfcygw4pq731iskcyzly6r-idesk"
      }
    },
    "inputSrcs": [
      "/nix/store/lbw7vvi7bv9dif9b7i8bhmv4i9w0gidh-builder.sh",
      "/nix/store/r63iqcq8b76653mc2qr2hl5ncxjp0iqw-idesk-0.7.5.tar.gz",
      "/nix/store/zhzz9w8lakhn2hnrz918mzab8r1kb8dj-setup.sh"
    ],
    "inputDrvs": {
      "/nix/store/420y2cqwnq7s45iy36z66l8bnybzw447-gcc-wrapper-9.3.0.drv": [
        "out"
      ],
      "/nix/store/6qr6120z066dwc7m9n4j5prwl9hlmam9-bash-4.4-p23.drv": [
        "out"
      ],
      "/nix/store/8c6i8las3g72s1sfx96yjfqnan8d6747-patchelf-0.9.drv": [
        "out"
      ],
      "/nix/store/a3jibqsws6d9nd8ir35bcbvw2g8gx52d-gzip-1.10.drv": [
        "out"
      ],
      "/nix/store/ffgiilyjji1xalhdmks4gdl28dv6vmi6-libX11-1.6.8.drv": [
        "out"
      ],
      "/nix/store/gm3w9y12k1qq103qx7077vd4xpd69qgc-libXt-1.2.0.drv": [
        "out"
      ],
      "/nix/store/hsbjg25c767zn5mzkhgmmbnl59mf1mx8-gawk-5.1.0.drv": [
        "out"
      ],
      "/nix/store/j8646kfi9fhzcjcqv7pam13mqxj4awp6-libXrender-0.9.10.drv": [
        "out"
      ],
      "/nix/store/k55gpk5di0ys01rz286sxk55b60wffp4-gnugrep-3.4.drv": [
        "out"
      ],
      "/nix/store/ldh4qrsybxx5wynhcqxakwxjb90vw04w-libXScrnSaver-1.2.3.drv": [
        "out"
      ],
      "/nix/store/lqm560aja494lc7arbp6f98wx72jmnqa-findutils-4.7.0.drv": [
        "out"
      ],
      "/nix/store/mjkfpbshzpg3fwf9pnipls477lvdql9y-gnutar-1.32.drv": [
        "out"
      ],
      "/nix/store/nrvk76dajhy2dg7r9ghxj167x28ylsr3-pixman-0.38.4.drv": [
        "out"
      ],
      "/nix/store/p0gzkkhdd0a0pf3f07mqk5s3kiiv7s0k-libXft-2.3.3.drv": [
        "out"
      ],
      "/nix/store/p31fvg31k1dw2gvfc5b6ik0gb2ixih9i-libXext-1.3.4.drv": [
        "out"
      ],
      "/nix/store/plk5shpgaa2kfw1lvbzxlcq0b1vp7gvw-binutils-2.31.1.drv": [
        "out"
      ],
      "/nix/store/r1p4sh5xivscrlp6nn69cb5lz3hah44l-xorgproto-2019.1.drv": [
        "out"
      ],
      "/nix/store/x83va25phij5fhwayak4aiak9cziz4if-coreutils-8.31.drv": [
        "out"
      ],
      "/nix/store/xa7a9wn0nrzgncz47kfdcsnl3gfw49np-libXcursor-1.2.0.drv": [
        "out"
      ],
      "/nix/store/xkr97n430y8zc3n4ivazp3h4cfdrw36v-gnused-4.8.drv": [
        "out"
      ],
      "/nix/store/zblxn2jnhjqv70da91kg1cg1aq4q0sjh-gnumake-4.2.1.drv": [
        "out"
      ],
      "/nix/store/zhlh9v2nnjnvxlxac2rd23bs1wbhl87v-libXi-1.7.10.drv": [
        "out"
      ]
    },
    "platform": "x86_64-linux",
    "builder": "/nix/store/xfbmj7sl2ikicym9x3yq7cms5qx1w39k-bash-4.4-p23/bin/bash",
    "args": [
      "/nix/store/lbw7vvi7bv9dif9b7i8bhmv4i9w0gidh-builder.sh"
    ],
    "env": {
      "baseInputs": "/nix/store/5mp196fls2rkna26wiglnszhnpjj2glz-gnutar-1.32 /nix/store/lb7zc6jhqvfnanzdhkbmd0j8cjx4ikyb-gzip-1.10 /nix/store/a1zrj63h9xzchkh11fjqrf48500g7fxm-gnumake-4.2.1 /nix/store/fb30zc52va0g99q8qgv7kx4ngq163pii-gcc-wrapper-9.3.0 /nix/store/0x8pbk0578knfpxf9gbl0lhmpynh2947-binutils-2.31.1 /nix/store/id23l2prxafywpps8ssh3gq2wn6p84gi-coreutils-8.31 /nix/store/5r68w89ix106f19i5l796wvq1x1i2942-gawk-5.1.0 /nix/store/m7jn1j5jskzh15cym2bvl365hv7avlfm-gnused-4.8 /nix/store/8nx9701nygg1dxznv7x41bjw0n3ag4bj-gnugrep-3.4 /nix/store/n3lq4ks8jz0gbnk89fwf7f6vklkwlk6v-patchelf-0.9 /nix/store/qh3gmqng0i1hjzs6sl25qaf4k106d9fm-findutils-4.7.0",
      "buildInputs": "/nix/store/94j3xd5q91jap44dsxdsp6l343257cbg-libXft-2.3.3 /nix/store/8gz6py1q8yhhg7pr4gnsfr2rps03rd6c-libX11-1.6.8 /nix/store/6fzkh9vifp4m00cd67aas9kkmnpajvfv-libXScrnSaver-1.2.3 /nix/store/4dkily84c23rjy0wh2klgrwy5l8mr15p-libXcursor-1.2.0 /nix/store/h7z3dq09wmhgvmgrfw15w4y1wbdp6gy1-libXext-1.3.4 /nix/store/94j3xd5q91jap44dsxdsp6l343257cbg-libXft-2.3.3 /nix/store/4gpj77acgrg48py0x8riinn2n3h0c1c9-libXi-1.7.10 /nix/store/gk89f5sx0ldw3mbjipwspcnm8g2k5v7y-libXrender-0.9.10 /nix/store/xv8v0qkgxnpb8zaggh24q0rsmb3al5z1-libXt-1.2.0 /nix/store/wii8v4qd6f8qz0yy1f1sx8q314yhchi8-pixman-0.38.4 /nix/store/bbjm2gxdn2cvkiig1k43qq4prsvprinm-xorgproto-2019.1",
      "builder": "/nix/store/xfbmj7sl2ikicym9x3yq7cms5qx1w39k-bash-4.4-p23/bin/bash",
      "name": "idesk",
      "out": "/nix/store/r26qrz0qscvfcygw4pq731iskcyzly6r-idesk",
      "setup": "/nix/store/zhzz9w8lakhn2hnrz918mzab8r1kb8dj-setup.sh",
      "src": "/nix/store/r63iqcq8b76653mc2qr2hl5ncxjp0iqw-idesk-0.7.5.tar.gz",
      "system": "x86_64-linux"
    }
  }
}

error-

checking for X... no
configure: error: Idesk requires the X Window System libraries and headers.

the package I am trying to build viz. idesk.nix

let
  pkgs = import <nixpkgs> {};
  mkDerivation = import ./autotools.nix pkgs;
in mkDerivation {
  name = "idesk";
  src = ./idesk-0.7.5.tar.gz;
  buildInputs = with pkgs; [ xorg.libXft xorg.libX11 xorg.libXScrnSaver xorg.libXcursor xorg.libXext xorg.libXft xorg.libXi  xorg.libXrender xorg.libXt xorg.pixman xorg.xorgproto ];
}

its autotools.nix


pkgs: attrs:
  with pkgs;
  let defaultAttrs = {
    builder = "${bash}/bin/bash";
    args = [ ./builder.sh ];
    setup = ./setup.sh;
    baseInputs = [ gnutar gzip gnumake gcc binutils-unwrapped coreutils gawk gnused gnugrep patchelf findutils ];
    system = builtins.currentSystem;
  };
  in
derivation (defaultAttrs // attrs)

builder.sh -

set -e
source $setup
genericBuild

setup.sh

I see that you’re using autotools, you may want to include autoreconfHook in nativeBuildInputs. This should work well with the autotools toolchain.

Thanks jonringer, my modified autotools.nix now is -

pkgs: attrs:
  with pkgs;
  let defaultAttrs = {
    builder = "${bash}/bin/bash";
    args = [ ./builder.sh ];
    setup = ./setup.sh;
    baseInputs = [ gnutar gzip gnumake gcc binutils-unwrapped coreutils gawk gnused gnugrep patchelf findutils ];
    buildInputs = with pkgs; [ imlib2 xorg.libXinerama xorg.libXrender xorg.libSM xorg.libICE zlib xorg.libXrender xorg.libXrandr xorg.libXpm xorg.libXinerama xlibsWrapper xorg.xorgserver pkgconfig xorg.libXft xorg.libX11 xorg.libXScrnSaver xorg.libXcursor xorg.libXext xorg.libXft xorg.libXi  xorg.libXrender xorg.libXt xorg.pixman xorg.xorgproto ];
    nativeBuildInputs = [ autoreconfHook xorg.xorgserver pkgconfig xorg.libXft xorg.libX11 xorg.libXScrnSaver xorg.libXcursor xorg.libXext xorg.libXft xorg.libXi  xorg.libXrender xorg.libXt xorg.pixman xorg.xorgproto ];
    system = builtins.currentSystem;
  };
  in
derivation (defaultAttrs // attrs)

no joy yet, still met with the below error -

configure: error: Idesk requires the X Window System libraries and headers

edit-
corrected file name and content

generally you can look at the configure script to see what command was run to assert that the X Window System Libraries weren’t found. Unfortunately, I don’t have too much experience messing around with X11, so I can’t help you any further :frowning: .

although, it’s unusual that you’re using derivation over mkDerivation

Appreciate your help. I poked in configure but could not identify whats missing.
I followed generic builder pill and my understanding was that package.nix has the mkDerivation function and imports autotools.nix which has the derivation function in it. Please advise if any change is needed in my input files. Thanks for your input so far.

I guess I will wait to see if anyone who encountered similar error is able to help.

I haven’t tried writing package with bare derivation, but as you are already using nixpkgs, stdenv.mkDerivation would probably be easier.

Starting with your derivation it could look like this:

with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "idesk-0.7.5";
  src = ./idesk-0.7.5.tar.bz2;
  buildInputs = with pkgs; [ pkg-config autoreconfHook
    xorg.libXft xorg.libX11 xorg.libXScrnSaver xorg.libXcursor
    xorg.libXext xorg.libXft xorg.libXi xorg.libXrender xorg.libXt
    xorg.pixman xorg.xorgproto imlib2 ];
}

Unfortunately the package doesn’t compile:

DesktopConfig.cpp:134:40: error: no matching function for call to 'stat::stat(const char*, stat*)'
  134 |        if( stat( directory.c_str(), &b ) < 0 ){

but at least configure works.

1 Like

Thanks maxxk, quite helpful.
I am analyzing other packages’ nix files which use libX11 as a dependency and it seems they can add it without any errors. However when I add libX11 as a dependency I get error error: undefined variable 'libX11'. Will continue reading (re-reading) the manual and other help materials.

I think, libX11 is passed as an argument to packages in nixpkgs via pkgs.callPackage in pkgs/top-level/all-packages.nix. But “canonical” path to libX11 is pkgs.xorg.libX11. If you want to write just libX11, you need to add with pkgs.xorg; as a prefix to the list in buildInputs to import the attributes from the set pkgs.xorg to the current namespace for the expression after “;”:

with pkgs; with pkgs.xorg; [ pkg-config libX11 ]

However, it is easier to use callPackage. I usually put my local packages into the overlay ~/.config/nixpkgs/overlays/my-packages.nix which looks like this:

self: super: {
    code-server = super.callPackage ./packages/code-server.nix { nodejs = super.nodejs-12_x; };
    # etc.
}

and packages/code-server.nix looks like any regular package definition in nixpkgs (in this case I copied it from a PR to nixpkgs repository).

You can see an example of overlay in manual here:
https://nixos.org/nixpkgs/manual/#sec-overlays-definition

1 Like

Thanks maxxk, I will get back to it per your advise. Appreciate you taking the time out to help. Nix promises to be a great tool once you get the hang of it.

After analyzing packages in nixpkgs I created a separate repo to list my custom packages named default.nix -

let
  nixpkgs = import <nixpkgs> {};
  allPkgs = nixpkgs // pkgs;
  callPackage = path: overrides:
    let f = import path;
    in f ((builtins.intersectAttrs (builtins.functionArgs f) allPkgs) // overrides);
  pkgs = with nixpkgs; {
    idesk = callPackage ./idesk.nix {inherit (xorg) libX11;};
  };
in pkgs

and the corresponding idesk.nix is -

with import <nixpkgs> {};
{ stdenv, pkgconfig, imlib2, libX11 }:

stdenv.mkDerivation {
  name = "idesk";
  src = ./idesk-0.7.5.tar.gz;
  buildInputs = [ libX11 xorg.libXft imlib2 ];
  nativeBuildInputs = [ pkgconfig ];

}

nix-build default.nix -A idesk proceeds as expected.

One difference I have noticed is that with import <nixpkgs> {}; has to be present in idesk.nix, if I remove the import then I get error error: undefined variable 'xorg' at ...
I thought that call package would fill in the required definitions for the listed variables.
The packages in nixpkgs do not have with import <nixpkgs> {}; in them.
What could I be doing wrong?
Thanks.
But I am much relieved with my progress as opposed to when I started with Nix. Steep learning curve but rewarding nonetheless :slight_smile:

edit
typos

Your idesk.nix declares a function with arguments - the build inputs that are passed automagically by callPackage - but you’re trying to use xorg without having it in the arguments list. This is why importing nixpkgs seems to solve the missing definition, and now you’ve introduced yourself a potentially confusing impurity.

I suggest you add a libXft argument in that function and also in default.nix:

idesk = callPackage ./idesk.nix {inherit (xorg) libX11 libXft;};

Other than that it might be more idiomatic to add your package to whatever collection through an overlay, but let’s get it built first.

1 Like

Thanks fricklerhandwerk and rest of the gang for patient explanations. The instructions imparted much clarity and helped clear confusion on my part. I am learning scheme to get better at writing expressions and understanding the intricacies. Please share if you have any useful resources. Thanks.