Skip to content

Commit

Permalink
vfkit: init at 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marsam committed Apr 22, 2024
1 parent 39ccb95 commit 85c9003
Show file tree
Hide file tree
Showing 3 changed files with 933 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkgs/by-name/vf/vfkit/darwin-os-version.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--- vendor/github.com/Code-Hex/vz/v3/osversion.go
+++ 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)
55 changes: 55 additions & 0 deletions pkgs/by-name/vf/vfkit/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ lib, buildGoModule, darwin, fetchFromGitHub }:

buildGoModule rec {
pname = "vfkit";
version = "0.5.0";

src = fetchFromGitHub {
owner = "crc-org";
repo = "vfkit";
rev = "v${version}";
hash = "sha256-NoaJ60bCmhI1S9pPyHYTmYdqWm17eF/CsTBBwkOwT1I=";
};

overrideModAttrs = _: {
postBuild = ''
patch -p0 < ${./darwin-os-version.patch}
patch -p0 < ${./support-apple-11-sdk.patch}
'';
};

vendorHash = "sha256-TX+vm4FhBaM0WNXA+m7rmaWZR+Lk9f2Z8UJXMd2yzDw=";

subPackages = [ "cmd/vfkit" ];

ldflags = [
"-s"
"-w"
"-X github.com/crc-org/vfkit/pkg/cmdline.gitVersion=${src.rev}"
];

nativeBuildInputs = [
darwin.sigtool
];

buildInputs = [
darwin.apple_sdk_11_0.frameworks.Cocoa
darwin.apple_sdk_11_0.frameworks.Virtualization
];

postFixup = ''
codesign --entitlements vf.entitlements -f -s - $out/bin/vfkit
'';

# has no tests
doCheck = false;

meta = with lib; {
description = "Simple command line tool to start VMs through virtualization framework";
homepage = "https://github.com/crc-org/vfkit";
license = licenses.asl20;
maintainers = [ maintainers.marsam ];
platforms = platforms.darwin;
mainProgram = "vfkit";
};
}
Loading

0 comments on commit 85c9003

Please sign in to comment.