2022-11-21 04:44:04 -06:00
|
|
|
{
|
2022-11-24 05:29:16 -06:00
|
|
|
description = "Lanzaboot Secure Boot Madness";
|
2022-11-21 04:44:04 -06:00
|
|
|
|
|
|
|
inputs = {
|
2022-12-17 17:31:09 -06:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
|
|
|
|
nixpkgs-test.url = "github:RaitoBezarius/nixpkgs/simplified-qemu-boot-disks";
|
2022-11-26 09:41:48 -06:00
|
|
|
|
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2022-12-08 13:39:35 -06:00
|
|
|
inputs.rust-overlay.follows = "rust-overlay";
|
|
|
|
inputs.flake-utils.follows = "flake-utils";
|
2022-11-26 09:41:48 -06:00
|
|
|
};
|
|
|
|
|
2022-12-08 13:39:35 -06:00
|
|
|
rust-overlay = {
|
|
|
|
url = "github:oxalica/rust-overlay";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
inputs.flake-utils.follows = "flake-utils";
|
|
|
|
};
|
|
|
|
|
2022-12-25 18:22:13 -06:00
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
};
|
2022-12-08 13:39:35 -06:00
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
2022-11-21 04:44:04 -06:00
|
|
|
};
|
|
|
|
|
2022-12-17 17:31:09 -06:00
|
|
|
outputs = { self, nixpkgs, nixpkgs-test, crane, rust-overlay, ... }:
|
2022-11-21 04:44:04 -06:00
|
|
|
let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
overlays = [
|
|
|
|
rust-overlay.overlays.default
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-12-25 09:18:53 -06:00
|
|
|
testPkgs = import nixpkgs-test { system = "x86_64-linux"; };
|
|
|
|
|
2022-12-25 08:46:41 -06:00
|
|
|
inherit (pkgs) lib;
|
2022-11-24 05:05:46 -06:00
|
|
|
|
2022-11-21 18:53:40 -06:00
|
|
|
rust-nightly = pkgs.rust-bin.fromRustupToolchainFile ./rust/lanzaboote/rust-toolchain.toml;
|
2022-11-26 09:41:48 -06:00
|
|
|
craneLib = crane.lib.x86_64-linux.overrideToolchain rust-nightly;
|
2022-11-21 04:44:04 -06:00
|
|
|
|
2022-12-25 08:49:49 -06:00
|
|
|
uefi-run = pkgs.callPackage ./nix/packages/uefi-run.nix {
|
2022-11-28 06:48:25 -06:00
|
|
|
inherit craneLib;
|
2022-11-21 08:36:39 -06:00
|
|
|
};
|
|
|
|
|
2022-11-28 06:48:25 -06:00
|
|
|
# Build attributes for a Rust application.
|
2022-12-25 08:43:52 -06:00
|
|
|
buildRustApp =
|
|
|
|
{ src
|
|
|
|
, target ? null
|
|
|
|
, doCheck ? true
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cleanedSrc = craneLib.cleanCargoSource src;
|
|
|
|
commonArgs = {
|
|
|
|
src = cleanedSrc;
|
|
|
|
CARGO_BUILD_TARGET = target;
|
|
|
|
inherit doCheck;
|
|
|
|
};
|
2022-11-28 06:48:25 -06:00
|
|
|
|
2022-12-25 08:43:52 -06:00
|
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
package = craneLib.buildPackage (commonArgs // {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
});
|
|
|
|
|
|
|
|
clippy = craneLib.cargoClippy (commonArgs // {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
cargoClippyExtraArgs = "-- --deny warnings";
|
|
|
|
});
|
|
|
|
};
|
2022-11-21 18:29:16 -06:00
|
|
|
|
2022-11-28 06:48:25 -06:00
|
|
|
lanzabooteCrane = buildRustApp {
|
|
|
|
src = ./rust/lanzaboote;
|
|
|
|
target = "x86_64-unknown-uefi";
|
|
|
|
doCheck = false;
|
|
|
|
};
|
2022-11-23 06:00:55 -06:00
|
|
|
|
2022-11-28 06:48:25 -06:00
|
|
|
lanzaboote = lanzabooteCrane.package;
|
2022-11-26 09:41:48 -06:00
|
|
|
|
2022-11-28 06:48:25 -06:00
|
|
|
lanzatoolCrane = buildRustApp {
|
|
|
|
src = ./rust/lanzatool;
|
2022-11-24 04:45:09 -06:00
|
|
|
};
|
|
|
|
|
2022-11-28 06:48:25 -06:00
|
|
|
lanzatool-unwrapped = lanzatoolCrane.package;
|
|
|
|
|
2022-12-25 08:43:52 -06:00
|
|
|
lanzatool = pkgs.runCommand "lanzatool"
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
|
|
} ''
|
2022-11-24 05:05:46 -06:00
|
|
|
mkdir -p $out/bin
|
|
|
|
|
|
|
|
# Clean PATH to only contain what we need to do objcopy. Also
|
|
|
|
# tell lanzatool where to find our UEFI binaries.
|
2022-11-25 19:16:12 -06:00
|
|
|
makeWrapper ${lanzatool-unwrapped}/bin/lanzatool $out/bin/lanzatool \
|
2022-11-25 06:07:04 -06:00
|
|
|
--set PATH ${lib.makeBinPath [ pkgs.binutils-unwrapped pkgs.sbsigntool ]} \
|
2022-11-23 04:59:54 -06:00
|
|
|
--set RUST_BACKTRACE full \
|
2022-11-27 19:59:21 -06:00
|
|
|
--set LANZABOOTE_STUB ${lanzaboote}/bin/lanzaboote.efi
|
2022-11-24 04:45:09 -06:00
|
|
|
'';
|
2022-12-25 08:43:52 -06:00
|
|
|
in
|
|
|
|
{
|
2022-11-23 04:59:54 -06:00
|
|
|
overlays.default = final: prev: {
|
2022-11-25 16:42:34 -06:00
|
|
|
inherit lanzatool;
|
2022-11-23 04:59:54 -06:00
|
|
|
};
|
|
|
|
|
2022-12-08 14:23:35 -06:00
|
|
|
nixosModules.lanzaboote = { pkgs, lib, ... }: {
|
2022-12-25 08:49:49 -06:00
|
|
|
imports = [ ./nix/modules/lanzaboote.nix ];
|
2022-12-10 11:26:47 -06:00
|
|
|
boot.lanzaboote.package = lib.mkDefault self.packages.${pkgs.system}.lanzatool;
|
2022-12-08 14:23:35 -06:00
|
|
|
};
|
2022-11-23 04:59:54 -06:00
|
|
|
|
2022-11-21 17:45:18 -06:00
|
|
|
packages.x86_64-linux = {
|
2022-11-27 19:59:21 -06:00
|
|
|
inherit lanzaboote lanzatool;
|
2022-11-25 19:26:39 -06:00
|
|
|
default = lanzatool;
|
2022-11-21 17:45:18 -06:00
|
|
|
};
|
2022-11-21 08:36:39 -06:00
|
|
|
|
2022-11-21 17:45:18 -06:00
|
|
|
devShells.x86_64-linux.default = pkgs.mkShell {
|
2022-11-22 17:26:00 -06:00
|
|
|
packages = [
|
2022-11-21 17:45:18 -06:00
|
|
|
uefi-run
|
2022-11-21 19:08:35 -06:00
|
|
|
pkgs.openssl
|
2022-11-23 04:59:54 -06:00
|
|
|
(pkgs.sbctl.override {
|
|
|
|
databasePath = "pki";
|
|
|
|
})
|
|
|
|
pkgs.sbsigntool
|
2022-11-24 09:59:16 -06:00
|
|
|
pkgs.efitools
|
2022-11-24 20:04:44 -06:00
|
|
|
pkgs.python39Packages.ovmfvartool
|
|
|
|
pkgs.qemu
|
2022-12-25 09:25:14 -06:00
|
|
|
pkgs.nixpkgs-fmt
|
|
|
|
pkgs.statix
|
2022-11-21 17:45:18 -06:00
|
|
|
];
|
2022-11-22 17:26:00 -06:00
|
|
|
|
|
|
|
inputsFrom = [
|
|
|
|
lanzaboote
|
2022-12-26 09:33:19 -06:00
|
|
|
lanzatool
|
2022-11-22 17:26:00 -06:00
|
|
|
];
|
2022-11-21 04:44:04 -06:00
|
|
|
};
|
2022-11-23 04:59:54 -06:00
|
|
|
|
2022-12-25 09:18:53 -06:00
|
|
|
checks.x86_64-linux = {
|
|
|
|
lanzatool-clippy = lanzatoolCrane.clippy;
|
|
|
|
lanzaboote-clippy = lanzabooteCrane.clippy;
|
|
|
|
} // (import ./nix/tests/lanzaboote.nix {
|
|
|
|
inherit pkgs testPkgs;
|
|
|
|
lanzabooteModule = self.nixosModules.lanzaboote;
|
|
|
|
});
|
2022-11-21 17:45:18 -06:00
|
|
|
};
|
2022-11-21 04:44:04 -06:00
|
|
|
}
|