2023-08-22 20:05:09 +00:00
|
|
|
{ lib
|
|
|
|
, fetchFromGitHub
|
2023-10-09 19:29:22 +00:00
|
|
|
, fetchpatch
|
|
|
|
, stdenv
|
|
|
|
, python3
|
|
|
|
, bubblewrap
|
|
|
|
, systemd
|
|
|
|
|
|
|
|
# Python packages
|
2023-08-22 20:05:09 +00:00
|
|
|
, setuptools
|
2023-10-09 19:29:22 +00:00
|
|
|
, setuptools-scm
|
|
|
|
, wheel
|
2023-08-22 20:05:09 +00:00
|
|
|
, buildPythonApplication
|
|
|
|
, pytestCheckHook
|
2023-10-09 19:29:22 +00:00
|
|
|
, pefile
|
|
|
|
|
|
|
|
# Optional dependencies
|
|
|
|
, withQemu ? false
|
|
|
|
, qemu
|
|
|
|
, OVMF
|
2023-08-22 20:05:09 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
# For systemd features used by mkosi, see
|
|
|
|
# https://github.com/systemd/mkosi/blob/19bb5e274d9a9c23891905c4bcbb8f68955a701d/action.yaml#L64-L72
|
2023-10-09 19:29:22 +00:00
|
|
|
systemdForMkosi = (systemd.overrideAttrs (oldAttrs: {
|
|
|
|
patches = oldAttrs.patches ++ [
|
|
|
|
# Enable setting a deterministic verity seed for systemd-repart. Remove when upgrading to systemd 255.
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/systemd/systemd/commit/81e04781106e3db24e9cf63c1d5fdd8215dc3f42.patch";
|
|
|
|
hash = "sha256-KO3poIsvdeepPmXWQXNaJJCPpmBb4sVmO+ur4om9f5k=";
|
|
|
|
})
|
|
|
|
# Propagate SOURCE_DATE_EPOCH to mcopy. Remove when upgrading to systemd 255.
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/systemd/systemd/commit/4947de275a5553399854cc748f4f13e4ae2ba069.patch";
|
|
|
|
hash = "sha256-YIZZyc3f8pQO9fMAxiNhDdV8TtL4pXoh+hwHBzRWtfo=";
|
|
|
|
})
|
2023-11-16 04:20:00 +00:00
|
|
|
# repart: make sure rewinddir() is called before readdir() when performing rm -rf. Remove when upgrading to systemd 255.
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/systemd/systemd/commit/6bbb893b90e2dcb05fb310ba4608f9c9dc587845.patch";
|
|
|
|
hash = "sha256-A6cF2QAeYHGc0u0V1JMxIcV5shzf5x3Q6K+blZOWSn4=";
|
|
|
|
})
|
|
|
|
# Set timezone to UTC when invoking mcopy. Remove when upgrading to systemd 255.
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/systemd/systemd/commit/b2942c76adc5bb6a3e073aa5cee57834ee3a9813.patch";
|
|
|
|
hash = "sha256-phGln3Gs9p8CsEe+1laGrm9xcUJWVbNBW0W8oR9/7YU=";
|
|
|
|
})
|
2023-10-09 19:29:22 +00:00
|
|
|
];
|
|
|
|
})).override {
|
|
|
|
withRepart = true;
|
|
|
|
withBootloader = true;
|
|
|
|
withSysusers = true;
|
|
|
|
withFirstboot = true;
|
2023-08-22 20:05:09 +00:00
|
|
|
withEfi = true;
|
|
|
|
withUkify = true;
|
|
|
|
};
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
python3pefile = python3.withPackages (ps: with ps; [
|
|
|
|
pefile
|
|
|
|
]);
|
2023-08-22 20:05:09 +00:00
|
|
|
in
|
|
|
|
buildPythonApplication rec {
|
|
|
|
pname = "mkosi";
|
2023-10-09 19:29:22 +00:00
|
|
|
version = "18";
|
2023-08-22 20:05:09 +00:00
|
|
|
format = "pyproject";
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "systemd";
|
|
|
|
repo = "mkosi";
|
2023-10-09 19:29:22 +00:00
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-bnd2P6lq1XqKed3m4hDYrR9IcdrPaJxNBL2Z6jCruV4=";
|
2023-08-22 20:05:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Fix ctypes finding library
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/7307
|
2023-10-09 19:29:22 +00:00
|
|
|
postPatch = lib.optionalString stdenv.isLinux ''
|
|
|
|
substituteInPlace mkosi/run.py \
|
|
|
|
--replace 'ctypes.util.find_library("c")' "'${stdenv.cc.libc}/lib/libc.so.6'"
|
|
|
|
substituteInPlace mkosi/__init__.py \
|
|
|
|
--replace '/usr/lib/systemd/ukify' "${systemdForMkosi}/lib/systemd/ukify"
|
|
|
|
'' + lib.optionalString withQemu ''
|
|
|
|
substituteInPlace mkosi/qemu.py \
|
|
|
|
--replace '/usr/share/ovmf/x64/OVMF_VARS.fd' "${OVMF.variables}" \
|
|
|
|
--replace '/usr/share/ovmf/x64/OVMF_CODE.fd' "${OVMF.firmware}"
|
2023-08-22 20:05:09 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
setuptools
|
2023-10-09 19:29:22 +00:00
|
|
|
setuptools-scm
|
|
|
|
wheel
|
2023-08-22 20:05:09 +00:00
|
|
|
];
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
makeWrapperArgs = [
|
|
|
|
"--set MKOSI_INTERPRETER ${python3pefile}/bin/python3"
|
|
|
|
];
|
2023-08-22 20:05:09 +00:00
|
|
|
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
systemdForMkosi
|
|
|
|
bubblewrap
|
2023-10-09 19:29:22 +00:00
|
|
|
] ++ lib.optional withQemu [
|
|
|
|
qemu
|
2023-08-22 20:05:09 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
wrapProgram $out/bin/mkosi \
|
|
|
|
--prefix PYTHONPATH : "$PYTHONPATH"
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkInputs = [
|
|
|
|
pytestCheckHook
|
|
|
|
];
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Build legacy-free OS images";
|
|
|
|
homepage = "https://github.com/systemd/mkosi";
|
2023-10-09 19:29:22 +00:00
|
|
|
changelog = "https://github.com/systemd/mkosi/releases/tag/v${version}";
|
2023-08-22 20:05:09 +00:00
|
|
|
license = licenses.lgpl21Only;
|
|
|
|
mainProgram = "mkosi";
|
|
|
|
maintainers = with maintainers; [ malt3 katexochen ];
|
|
|
|
platforms = platforms.linux;
|
|
|
|
};
|
|
|
|
}
|