Compile OpenSSL with nix-pkgs

Hello everyone,

This is my first topic here. I tried to search for answers but was not able to find any.

I quickly tried to compile OpenSSL 3.1.4 on Ubuntu 20.04 arm64, but got an error below.

What am I doing wrong?

/nix/store/08wcfajdgcs02ivzwsl0bgg2x5jjf0vp-stdenv-linux/setup: line 1595: ./Configure: cannot execute: required file not found
error: builder for ‘/nix/store/cvbs6hrfz4139j7jjbyv1qfycl93m7m1-openssl.drv’ failed with exit code 127

here are the commands I have been using:

export NIX_PATH=nixpkgs=https://github.com/nixOS/nixpkgs/archive/23.05.tar.gz

{ pkgs ? import { system = builtins.currentSystem; }
, stdenv ? pkgs.stdenv
, fetchFromGitHub ? pkgs.fetchFromGitHub
}:

stdenv.mkDerivation rec {
name = “openssl”;

src = fetchFromGitHub {
owner = “openssl”;
repo = “openssl”;
rev = “refs/tags/openssl-3.1.4”;
sha256 = “sha256-Vvf1wiNb4ikg1lIS9U137aodZ2JzM711tSWMJFYWtWI=”;
};

nativeBuildInputs = with pkgs;[ cmake autoconf automake libtool ];

buildInputs = with pkgs; [ gcc ];

configurePhase = ‘’
ls -lart
./Configure
‘’;

installPhase = ‘’
make install DESTDIR=$out
‘’;
}

and the full output:

ubuntu@instance-20230320-2251:/var/jenkins/workspace/neodix-pipleline$ nix-build openssl.nix
this derivation will be built:
/nix/store/cvbs6hrfz4139j7jjbyv1qfycl93m7m1-openssl.drv
building ‘/nix/store/cvbs6hrfz4139j7jjbyv1qfycl93m7m1-openssl.drv’…
unpacking sources
unpacking source archive /nix/store/90c92vs1nbrppbs8g28rd5g8iv3d1caf-source
source root is source
patching sources
updateAutotoolsGnuConfigScriptsPhase
configuring
total 1300
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 wycheproof
drwxr-xr-x 3 nixbld nixbld 4096 Jan 1 1970 util
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 tools
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 tlslite-ng
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 tlsfuzzer
drwxr-xr-x 12 nixbld nixbld 12288 Jan 1 1970 test
drwxr-xr-x 4 nixbld nixbld 4096 Jan 1 1970 ssl
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 python-ecdsa
drwxr-xr-x 5 nixbld nixbld 4096 Jan 1 1970 providers
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 os-dep
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 oqs-provider
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 ms
drwxr-xr-x 5 nixbld nixbld 4096 Jan 1 1970 include
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 fuzz
drwxr-xr-x 3 nixbld nixbld 4096 Jan 1 1970 external
drwxr-xr-x 3 nixbld nixbld 4096 Jan 1 1970 engines
drwxr-xr-x 10 nixbld nixbld 4096 Jan 1 1970 doc
drwxr-xr-x 17 nixbld nixbld 4096 Jan 1 1970 demos
drwxr-xr-x 69 nixbld nixbld 4096 Jan 1 1970 crypto
-rw-r–r-- 1 nixbld nixbld 16740 Jan 1 1970 configdata.pm.in
-rw-r–r-- 1 nixbld nixbld 2516 Jan 1 1970 config.com
-rwxr-xr-x 1 nixbld nixbld 378 Jan 1 1970 config
-rw-r–r-- 1 nixbld nixbld 3825 Jan 1 1970 build.info
drwxr-xr-x 5 nixbld nixbld 4096 Jan 1 1970 apps
drwxr-xr-x 2 nixbld nixbld 4096 Jan 1 1970 VMS
-rw-r–r-- 1 nixbld nixbld 100 Jan 1 1970 VERSION.dat
-rw-r–r-- 1 nixbld nixbld 3897 Jan 1 1970 SUPPORT.md
-rw-r–r-- 1 nixbld nixbld 6635 Jan 1 1970 README.md
-rw-r–r-- 1 nixbld nixbld 5477 Jan 1 1970 README-PROVIDERS.md
-rw-r–r-- 1 nixbld nixbld 6857 Jan 1 1970 README-FIPS.md
-rw-r–r-- 1 nixbld nixbld 15636 Jan 1 1970 README-ENGINES.md
-rw-r–r-- 1 nixbld nixbld 9224 Jan 1 1970 NOTES-WINDOWS.md
-rw-r–r-- 1 nixbld nixbld 4832 Jan 1 1970 NOTES-VMS.md
-rw-r–r-- 1 nixbld nixbld 2740 Jan 1 1970 NOTES-VALGRIND.md
-rw-r–r-- 1 nixbld nixbld 5685 Jan 1 1970 NOTES-UNIX.md
-rw-r–r-- 1 nixbld nixbld 4995 Jan 1 1970 NOTES-PERL.md
-rw-r–r-- 1 nixbld nixbld 10822 Jan 1 1970 NOTES-NONSTOP.md
-rw-r–r-- 1 nixbld nixbld 2112 Jan 1 1970 NOTES-DJGPP.md
-rw-r–r-- 1 nixbld nixbld 4600 Jan 1 1970 NOTES-ANDROID.md
-rw-r–r-- 1 nixbld nixbld 75206 Jan 1 1970 NEWS.md
-rw-r–r-- 1 nixbld nixbld 10175 Jan 1 1970 LICENSE.txt
-rw-r–r-- 1 nixbld nixbld 63443 Jan 1 1970 INSTALL.md
-rw-r–r-- 1 nixbld nixbld 1231 Jan 1 1970 HACKING.md
-rw-r–r-- 1 nixbld nixbld 197 Jan 1 1970 FAQ.md
-rwxr-xr-x 1 nixbld nixbld 135045 Jan 1 1970 Configure
drwxr-xr-x 3 nixbld nixbld 4096 Jan 1 1970 Configurations
-rw-r–r-- 1 nixbld nixbld 4362 Jan 1 1970 CONTRIBUTING.md
-rw-r–r-- 1 nixbld nixbld 169 Jan 1 1970 CODE-OF-CONDUCT.md
-rw-r–r-- 1 nixbld nixbld 755431 Jan 1 1970 CHANGES.md
-rw-r–r-- 1 nixbld nixbld 990 Jan 1 1970 AUTHORS.md
-rw-r–r-- 1 nixbld nixbld 159 Jan 1 1970 ACKNOWLEDGEMENTS.md
drwxr-xr-x 24 nixbld nixbld 4096 Jan 1 1970 .
drwx------ 3 nixbld nixbld 4096 Dec 24 11:12 …
/nix/store/08wcfajdgcs02ivzwsl0bgg2x5jjf0vp-stdenv-linux/setup: line 1595: ./Configure: cannot execute: required file not found
error: builder for ‘/nix/store/cvbs6hrfz4139j7jjbyv1qfycl93m7m1-openssl.drv’ failed with exit code 127

PS. I know I can use OpenSSL from nix-pkgs by simply referring to it as pkgs.openssl_3_1, but in my case when I compiling one big project I get lots of errors like:

binutils-2.40/bin/ld: (.text+0x634): undefined reference to `__aarch64_ldadd4_relax’

I may open another topic for that later, since the same script works on Ubuntu with x86-64 architecture.

This is probably because shebang is referring file that will not exist in the sandbox. You will need to patch the file. patchShebangs is useful for this, as you can see in the Nixpkgs package:

The shebang refers to perl so you will need to add it to nativeBuildInputs.

gcc is brought by default with stdenv.mkDerivation on Linux so you should add it manually. And build tools would go to nativeBuildInputs too, buildInputs is for dependencies that will be executed on the host platform.

You should not use DESTDIR, see Do not set DESTDIR in makeFlags · Issue #65718 · NixOS/nixpkgs · GitHub.

1 Like

Wow, I didn’t expect the answer so quickly on Dec 24th )
Thank you very much for the tips. Yes, patchShebangs did the trick. Now it compiles!
Sad, I was reading the docu and saw patchShebangs, but haven’t figured out that I need it in my case.