Loading pkgs/development/tools/misc/linuxkit/darwin-os-version.patch 0 → 100644 +53 −0 Original line number Diff line number Diff line diff --git a/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go b/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go index d72a7856d..b186d3aff 100644 --- a/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go +++ b/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go @@ -9,6 +9,7 @@ import "C" import ( "errors" "fmt" + "os/exec" "strconv" "strings" "sync" @@ -48,6 +49,40 @@ func fetchMajorMinorVersion() (float64, error) { if err != nil { return 0, err } + + // For backward compatibility reasons, if code compiled against an SDK + // earlier than macOS 11 is run on macOS 11 or later, and then tries to read + // value of kern.osproductversion, the OS will return the value "10.16" + // instead of the real OS version string. By contrast, the command `sw_vers + // -productVersion` will return the real OS version string unless the + // environment variable SYSTEM_VERSION_COMPAT is set to 1 or 2, in which + // case it will respectively return "10.16" and "15.7" (the latter is for + // some iOS compatibility reason). + // + // The only (currently) sure way to get the real OS version string + // regardless of SYSTEM_VERSION_COMPAT or the SDK compiled against is + // apparently to parse + // /System/Library/CoreServices/.SystemVersionPlatform.plist if it exists, + // and /System/Library/CoreServices/SystemVersion.plist otherwise. Doing + // so, however, requires parsing XML plist files. + // + // Given what this library does, it doesn't seem likely that there would be + // a good reason to run its code with SYSTEM_VERSION_COMPAT set, so using + // `sw_vers` should be adequate until a proper parsing of plist files is + // added. + // + // See https://github.com/ziglang/zig/issues/7569, + // https://github.com/ziglang/zig/pull/7714 and + // https://eclecticlight.co/2020/08/13/macos-version-numbering-isnt-so-simple/ + // for more information. + if osver == "10.16" { + out, err := exec.Command("sw_vers", "-productVersion").Output() + if err != nil { + return 0, err + } + osver = strings.TrimRight(string(out), "\r\n") + } + prefix := "v" majorMinor := strings.TrimPrefix(semver.MajorMinor(prefix+osver), prefix) version, err := strconv.ParseFloat(majorMinor, 64) pkgs/development/tools/misc/linuxkit/default.nix +23 −2 Original line number Diff line number Diff line { lib, stdenv, buildGoModule, fetchFromGitHub, git, Virtualization, testers, linuxkit }: { lib, stdenv, buildGoModule, fetchFromGitHub, git, Cocoa, Virtualization, sigtool, testers, linuxkit }: buildGoModule rec { pname = "linuxkit"; Loading @@ -15,7 +15,17 @@ buildGoModule rec { modRoot = "./src/cmd/linuxkit"; buildInputs = lib.optionals stdenv.isDarwin [ Virtualization ]; patches = [ ./darwin-os-version.patch ./support-apple-11-sdk.patch ]; # - On macOS, an executable must be signed with the right entitlement(s) to be # able to use the Virtualization framework at runtime. # - sigtool is allows us to validly sign such executables with a dummy # authority. nativeBuildInputs = lib.optionals stdenv.isDarwin [ sigtool ]; buildInputs = lib.optionals stdenv.isDarwin [ Cocoa Virtualization ]; ldflags = [ "-s" Loading @@ -25,6 +35,17 @@ buildGoModule rec { nativeCheckInputs = [ git ]; # - Because this package definition doesn't build using the source's Makefile, # we must manually call the sign target. # - The binary stripping that nixpkgs does by default in the # fixup phase removes such signing and entitlements, so we have to sign # after stripping. # - Finally, at the start of the fixup phase, the working directory is # $sourceRoot/src/cmd/linuxkit, so it's simpler to use the sign target from # the Makefile in that directory rather than $sourceRoot/Makefile. postFixup = lib.optionalString stdenv.isDarwin '' make sign LOCAL_TARGET=$out/bin/linuxkit ''; passthru.tests.version = testers.testVersion { package = linuxkit; command = "linuxkit version"; Loading pkgs/development/tools/misc/linuxkit/support-apple-11-sdk.patch 0 → 100644 +811 −0 File added.Preview size limit exceeded, changes collapsed. Show changes pkgs/top-level/all-packages.nix +2 −1 Original line number Diff line number Diff line Loading @@ -18715,7 +18715,8 @@ with pkgs; libwtk-sdl2 = callPackage ../development/libraries/libwtk-sdl2 { }; linuxkit = callPackage ../development/tools/misc/linuxkit { inherit (darwin.apple_sdk_11_0.frameworks) Virtualization; inherit (darwin.apple_sdk_11_0.frameworks) Cocoa Virtualization; inherit (darwin) sigtool; }; listenbrainz-mpd = callPackage ../applications/audio/listenbrainz-mpd { Loading
pkgs/development/tools/misc/linuxkit/darwin-os-version.patch 0 → 100644 +53 −0 Original line number Diff line number Diff line diff --git a/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go b/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go index d72a7856d..b186d3aff 100644 --- a/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go +++ b/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go @@ -9,6 +9,7 @@ import "C" import ( "errors" "fmt" + "os/exec" "strconv" "strings" "sync" @@ -48,6 +49,40 @@ func fetchMajorMinorVersion() (float64, error) { if err != nil { return 0, err } + + // For backward compatibility reasons, if code compiled against an SDK + // earlier than macOS 11 is run on macOS 11 or later, and then tries to read + // value of kern.osproductversion, the OS will return the value "10.16" + // instead of the real OS version string. By contrast, the command `sw_vers + // -productVersion` will return the real OS version string unless the + // environment variable SYSTEM_VERSION_COMPAT is set to 1 or 2, in which + // case it will respectively return "10.16" and "15.7" (the latter is for + // some iOS compatibility reason). + // + // The only (currently) sure way to get the real OS version string + // regardless of SYSTEM_VERSION_COMPAT or the SDK compiled against is + // apparently to parse + // /System/Library/CoreServices/.SystemVersionPlatform.plist if it exists, + // and /System/Library/CoreServices/SystemVersion.plist otherwise. Doing + // so, however, requires parsing XML plist files. + // + // Given what this library does, it doesn't seem likely that there would be + // a good reason to run its code with SYSTEM_VERSION_COMPAT set, so using + // `sw_vers` should be adequate until a proper parsing of plist files is + // added. + // + // See https://github.com/ziglang/zig/issues/7569, + // https://github.com/ziglang/zig/pull/7714 and + // https://eclecticlight.co/2020/08/13/macos-version-numbering-isnt-so-simple/ + // for more information. + if osver == "10.16" { + out, err := exec.Command("sw_vers", "-productVersion").Output() + if err != nil { + return 0, err + } + osver = strings.TrimRight(string(out), "\r\n") + } + prefix := "v" majorMinor := strings.TrimPrefix(semver.MajorMinor(prefix+osver), prefix) version, err := strconv.ParseFloat(majorMinor, 64)
pkgs/development/tools/misc/linuxkit/default.nix +23 −2 Original line number Diff line number Diff line { lib, stdenv, buildGoModule, fetchFromGitHub, git, Virtualization, testers, linuxkit }: { lib, stdenv, buildGoModule, fetchFromGitHub, git, Cocoa, Virtualization, sigtool, testers, linuxkit }: buildGoModule rec { pname = "linuxkit"; Loading @@ -15,7 +15,17 @@ buildGoModule rec { modRoot = "./src/cmd/linuxkit"; buildInputs = lib.optionals stdenv.isDarwin [ Virtualization ]; patches = [ ./darwin-os-version.patch ./support-apple-11-sdk.patch ]; # - On macOS, an executable must be signed with the right entitlement(s) to be # able to use the Virtualization framework at runtime. # - sigtool is allows us to validly sign such executables with a dummy # authority. nativeBuildInputs = lib.optionals stdenv.isDarwin [ sigtool ]; buildInputs = lib.optionals stdenv.isDarwin [ Cocoa Virtualization ]; ldflags = [ "-s" Loading @@ -25,6 +35,17 @@ buildGoModule rec { nativeCheckInputs = [ git ]; # - Because this package definition doesn't build using the source's Makefile, # we must manually call the sign target. # - The binary stripping that nixpkgs does by default in the # fixup phase removes such signing and entitlements, so we have to sign # after stripping. # - Finally, at the start of the fixup phase, the working directory is # $sourceRoot/src/cmd/linuxkit, so it's simpler to use the sign target from # the Makefile in that directory rather than $sourceRoot/Makefile. postFixup = lib.optionalString stdenv.isDarwin '' make sign LOCAL_TARGET=$out/bin/linuxkit ''; passthru.tests.version = testers.testVersion { package = linuxkit; command = "linuxkit version"; Loading
pkgs/development/tools/misc/linuxkit/support-apple-11-sdk.patch 0 → 100644 +811 −0 File added.Preview size limit exceeded, changes collapsed. Show changes
pkgs/top-level/all-packages.nix +2 −1 Original line number Diff line number Diff line Loading @@ -18715,7 +18715,8 @@ with pkgs; libwtk-sdl2 = callPackage ../development/libraries/libwtk-sdl2 { }; linuxkit = callPackage ../development/tools/misc/linuxkit { inherit (darwin.apple_sdk_11_0.frameworks) Virtualization; inherit (darwin.apple_sdk_11_0.frameworks) Cocoa Virtualization; inherit (darwin) sigtool; }; listenbrainz-mpd = callPackage ../applications/audio/listenbrainz-mpd {