diff options
Diffstat (limited to 'pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix')
-rw-r--r-- | pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix | 194 |
1 files changed, 123 insertions, 71 deletions
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix b/pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix index 82e8889f6cf4d..8605bfbfcebe2 100644 --- a/pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix +++ b/pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix @@ -1,82 +1,134 @@ -{ lib -, stdenvNoCC, stdenv -, fetchNetBSD -, bsdSetupHook, netbsdSetupHook -, makeMinimal -, install, tsort, lorder -, mandoc, groff, statHook, rsync -, compatIfNeeded -, defaultMakeFlags +{ + lib, + stdenv, + stdenvNoCC, + crossLibcStdenv, + stdenvLibcMinimal, + runCommand, + rsync, + source, + bsdSetupHook, + netbsdSetupHook, + makeMinimal, + install, + tsort, + lorder, + mandoc, + groff, + statHook, + compatIfNeeded, + defaultMakeFlags, + version, }: -lib.makeOverridable (attrs: let - stdenv' = if attrs.noCC or false then stdenvNoCC else stdenv; -in stdenv'.mkDerivation ({ - pname = "${attrs.pname or (baseNameOf attrs.path)}-netbsd"; - inherit (attrs) version; - src = fetchNetBSD attrs.path attrs.version attrs.sha256; +lib.makeOverridable ( + attrs: + let + stdenv' = + if attrs.noCC or false then + stdenvNoCC + else if attrs.noLibc or false then + crossLibcStdenv + else if attrs.libcMinimal or false then + stdenvLibcMinimal + else + stdenv; + in + stdenv'.mkDerivation ( + rec { + pname = "${attrs.pname or (baseNameOf attrs.path)}-netbsd"; + inherit version; + src = runCommand "${pname}-filtered-src" { nativeBuildInputs = [ rsync ]; } '' + for p in ${lib.concatStringsSep " " ([ attrs.path ] ++ attrs.extraPaths or [ ])}; do + set -x + path="$out/$p" + mkdir -p "$(dirname "$path")" + src_path="${source}/$p" + if [[ -d "$src_path" ]]; then src_path+=/; fi + rsync --chmod="+w" -r "$src_path" "$path" + set +x + done + ''; - extraPaths = [ ]; + extraPaths = [ ]; - nativeBuildInputs = [ - bsdSetupHook netbsdSetupHook - makeMinimal - install tsort lorder mandoc groff statHook rsync - ]; - buildInputs = compatIfNeeded; + nativeBuildInputs = [ + bsdSetupHook + netbsdSetupHook + makeMinimal + install + tsort + lorder + mandoc + groff + statHook + ]; + buildInputs = compatIfNeeded; - HOST_SH = stdenv'.shell; + HOST_SH = stdenv'.shell; - MACHINE_ARCH = { - i486 = "i386"; - i586 = "i386"; - i686 = "i386"; - }.${stdenv'.hostPlatform.parsed.cpu.name} - or stdenv'.hostPlatform.parsed.cpu.name; + MACHINE_ARCH = + { + i486 = "i386"; + i586 = "i386"; + i686 = "i386"; + } + .${stdenv'.hostPlatform.parsed.cpu.name} or stdenv'.hostPlatform.parsed.cpu.name; - MACHINE = { - x86_64 = "amd64"; - aarch64 = "evbarm64"; - i486 = "i386"; - i586 = "i386"; - i686 = "i386"; - }.${stdenv'.hostPlatform.parsed.cpu.name} - or stdenv'.hostPlatform.parsed.cpu.name; + MACHINE = + { + x86_64 = "amd64"; + aarch64 = "evbarm64"; + i486 = "i386"; + i586 = "i386"; + i686 = "i386"; + } + .${stdenv'.hostPlatform.parsed.cpu.name} or stdenv'.hostPlatform.parsed.cpu.name; - COMPONENT_PATH = attrs.path; + COMPONENT_PATH = attrs.path; - makeFlags = defaultMakeFlags; + makeFlags = defaultMakeFlags; - strictDeps = true; + strictDeps = true; - meta = with lib; { - maintainers = with maintainers; [ matthewbauer qyliss ]; - platforms = platforms.unix; - license = licenses.bsd2; - }; - -} // lib.optionalAttrs stdenv'.hasCC { - # TODO should CC wrapper set this? - CPP = "${stdenv'.cc.targetPrefix}cpp"; -} // lib.optionalAttrs stdenv'.isDarwin { - MKRELRO = "no"; -} // lib.optionalAttrs (stdenv'.cc.isClang or false) { - HAVE_LLVM = lib.versions.major (lib.getVersion stdenv'.cc.cc); -} // lib.optionalAttrs (stdenv'.cc.isGNU or false) { - HAVE_GCC = lib.versions.major (lib.getVersion stdenv'.cc.cc); -} // lib.optionalAttrs (stdenv'.isx86_32) { - USE_SSP = "no"; -} // lib.optionalAttrs (attrs.headersOnly or false) { - installPhase = "includesPhase"; - dontBuild = true; -} // attrs // { - # Files that use NetBSD-specific macros need to have nbtool_config.h - # included ahead of them on non-NetBSD platforms. - postPatch = lib.optionalString (!stdenv'.hostPlatform.isNetBSD) '' - set +e - grep -Zlr "^__RCSID - ^__BEGIN_DECLS" $COMPONENT_PATH | xargs -0r grep -FLZ nbtool_config.h | - xargs -0tr sed -i '0,/^#/s//#include <nbtool_config.h>\n\0/' - set -e - '' + attrs.postPatch or ""; -})) + meta = with lib; { + maintainers = with maintainers; [ + matthewbauer + qyliss + ]; + platforms = platforms.unix; + license = licenses.bsd2; + }; + } + // lib.optionalAttrs stdenv'.hasCC { + # TODO should CC wrapper set this? + CPP = "${stdenv'.cc.targetPrefix}cpp"; + } + // lib.optionalAttrs stdenv'.isDarwin { MKRELRO = "no"; } + // lib.optionalAttrs (stdenv'.cc.isClang or false) { + HAVE_LLVM = lib.versions.major (lib.getVersion stdenv'.cc.cc); + } + // lib.optionalAttrs (stdenv'.cc.isGNU or false) { + HAVE_GCC = lib.versions.major (lib.getVersion stdenv'.cc.cc); + } + // lib.optionalAttrs (stdenv'.isx86_32) { USE_SSP = "no"; } + // lib.optionalAttrs (attrs.headersOnly or false) { + installPhase = "includesPhase"; + dontBuild = true; + } + // attrs + // { + # Files that use NetBSD-specific macros need to have nbtool_config.h + # included ahead of them on non-NetBSD platforms. + postPatch = + lib.optionalString (!stdenv'.hostPlatform.isNetBSD) '' + set +e + grep -Zlr "^__RCSID + ^__BEGIN_DECLS" $COMPONENT_PATH | xargs -0r grep -FLZ nbtool_config.h | + xargs -0tr sed -i '0,/^#/s//#include <nbtool_config.h>\n\0/' + set -e + '' + + attrs.postPatch or ""; + } + ) +) |