cleverca22
6/11/2016 - 11:45 AM

enforce-arch.nix

[root@nix1:~/x]# /nix/store/12rqmlsxcff4k1dhpip0k3hp4a7dc2dp-binutils-2.26/bin/readelf -A /nix/store/l6dx0mb19zab4ym1rh4cwdq55592v1qr-openssl-1.0.2h/lib/libcrypto.so.1.0.0
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
[root@router:~]# nix-store --query --deriver /nix/store/l6dx0mb19zab4ym1rh4cwdq55592v1qr-openssl-1.0.2h/
/nix/store/apd8lpq2y3p94l5m67axfr4jqzw6xai9-openssl-1.0.2h.drv

[root@router:~]# cat /nix/store/apd8lpq2y3p94l5m67axfr4jqzw6xai9-openssl-1.0.2h.drv
...."),("system","armv6l-linux")])
{ stdenv, runCommand }:

let
  target = if stdenv.system == "armv6l-linux" then "Tag_CPU_arch: v6" else
    (if stdenv.system == "armv7l-linux" then "Tag_CPU_arch: v7" else "");
in
runCommand "enforce-arch" {} ''
  mkdir -p $out/nix-support
  cat <<EOF > $out/nix-support/setup-hook
function enforceArch() {
  for x in $out/lib/*.so; do
    readelf -A $x | grep ${target}
  done
}
postInstallHooks+=(enforceArch)
EOF
''