about summary refs log tree commit diff
path: root/pkgs/by-name/in/incus/package.nix
blob: 2958ab036ac9f72b96a7b58b1a3f4c2f8812102d (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{
  lts ? false,

  lib,
  callPackage,
  linkFarm,
  makeWrapper,
  stdenv,
  symlinkJoin,
  writeShellScriptBin,
  acl,
  apparmor-parser,
  apparmor-profiles,
  attr,
  bash,
  btrfs-progs,
  cdrkit,
  criu,
  dnsmasq,
  e2fsprogs,
  getent,
  gnutar,
  gptfdisk,
  gzip,
  iproute2,
  iptables,
  kmod,
  lvm2,
  minio,
  nftables,
  OVMF,
  qemu_kvm,
  qemu-utils,
  rsync,
  spice-gtk,
  squashfsTools,
  thin-provisioning-tools,
  util-linux,
  virtiofsd,
  xz,
}:
let
  unwrapped = callPackage ./unwrapped.nix { inherit lts; };
  client = callPackage ./client.nix { inherit lts; };
  name = "incus${lib.optionalString lts "-lts"}";

  binPath = lib.makeBinPath [
    acl
    attr
    bash
    btrfs-progs
    cdrkit
    criu
    dnsmasq
    e2fsprogs
    getent
    gnutar
    gptfdisk
    gzip
    iproute2
    iptables
    kmod
    lvm2
    minio
    nftables
    qemu_kvm
    qemu-utils
    rsync
    squashfsTools
    thin-provisioning-tools
    util-linux
    virtiofsd
    xz

    (writeShellScriptBin "apparmor_parser" ''
      exec '${apparmor-parser}/bin/apparmor_parser' -I '${apparmor-profiles}/etc/apparmor.d' "$@"
    '')
  ];

  clientBinPath = [ spice-gtk ];

  ovmf-2mb = OVMF.override {
    secureBoot = true;
    fdSize2MB = true;
  };

  ovmf-4mb = OVMF.override {
    secureBoot = true;
    fdSize4MB = true;
  };

  ovmf-prefix = if stdenv.hostPlatform.isAarch64 then "AAVMF" else "OVMF";

  # mimic ovmf from https://github.com/canonical/incus-pkg-snap/blob/3abebe1dfeb20f9b7729556960c7e9fe6ad5e17c/snapcraft.yaml#L378
  # also found in /snap/incus/current/share/qemu/ on a snap install
  ovmf = linkFarm "incus-ovmf" [
    {
      name = "OVMF_CODE.2MB.fd";
      path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd";
    }
    {
      name = "OVMF_CODE.4MB.fd";
      path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_CODE.fd";
    }
    {
      name = "OVMF_CODE.fd";
      path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd";
    }

    {
      name = "OVMF_VARS.2MB.fd";
      path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
    }
    {
      name = "OVMF_VARS.2MB.ms.fd";
      path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
    }
    {
      name = "OVMF_VARS.4MB.fd";
      path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd";
    }
    {
      name = "OVMF_VARS.4MB.ms.fd";
      path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd";
    }
    {
      name = "OVMF_VARS.fd";
      path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
    }
    {
      name = "OVMF_VARS.ms.fd";
      path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
    }
  ];
in
symlinkJoin {
  name = "${name}-${unwrapped.version}";

  paths = [ unwrapped ];

  nativeBuildInputs = [ makeWrapper ];

  postBuild = ''
    wrapProgram $out/bin/incusd --prefix PATH : ${lib.escapeShellArg binPath}:${qemu_kvm}/libexec:$out/bin --set INCUS_OVMF_PATH ${ovmf}

    wrapProgram $out/bin/incus --prefix PATH : ${lib.makeBinPath clientBinPath}
  '';

  passthru = {
    inherit client unwrapped;
    ui = callPackage ./ui.nix {};

    inherit (unwrapped) tests;
  };

  inherit (unwrapped) meta pname version;
}