summaryrefslogtreecommitdiff
path: root/pkgs/applications/virtualization/krunvm/default.nix
blob: cfc28c1e8bc05c152e6bb7f77074844e280b7daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
  lib,
  stdenv,
  rustPlatform,
  fetchFromGitHub,
  asciidoctor,
  buildah,
  buildah-unwrapped,
  cargo,
  libiconv,
  libkrun,
  makeWrapper,
  rustc,
  sigtool,
}:

stdenv.mkDerivation rec {
  pname = "krunvm";
  version = "0.2.4";

  src = fetchFromGitHub {
    owner = "containers";
    repo = "krunvm";
    rev = "v${version}";
    hash = "sha256-YbK4DKw0nh9IO1F7QsJcbOMlHekEdeUBbDHwuQ2x1Ww=";
  };

  cargoDeps = rustPlatform.fetchCargoVendor {
    inherit src;
    hash = "sha256-TMV9xCcqBQgPsUSzsTJAi4qsplTOSm3ilaUmtmdaGnE=";
  };

  nativeBuildInputs = [
    rustPlatform.cargoSetupHook
    cargo
    rustc
    asciidoctor
    makeWrapper
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [ sigtool ];

  buildInputs = [
    libkrun
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    libiconv
  ];

  makeFlags = [ "PREFIX=${placeholder "out"}" ];

  postPatch = ''
    # do not pollute etc
    substituteInPlace src/utils.rs \
      --replace "etc/containers" "share/krunvm/containers"
  '';

  postInstall = ''
    mkdir -p $out/share/krunvm/containers
    install -D -m755 ${buildah-unwrapped.src}/docs/samples/registries.conf $out/share/krunvm/containers/registries.conf
    install -D -m755 ${buildah-unwrapped.src}/tests/policy.json $out/share/krunvm/containers/policy.json
  '';

  # It attaches entitlements with codesign and strip removes those,
  # voiding the entitlements and making it non-operational.
  dontStrip = stdenv.hostPlatform.isDarwin;

  postFixup = ''
    wrapProgram $out/bin/krunvm \
      --prefix PATH : ${lib.makeBinPath [ buildah ]}
  '';

  meta = {
    description = "CLI-based utility for creating microVMs from OCI images";
    homepage = "https://github.com/containers/krunvm";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ nickcao ];
    platforms = libkrun.meta.platforms;
    mainProgram = "krunvm";
  };
}