lanzaboote/flake.nix

148 lines
4.0 KiB
Nix
Raw Normal View History

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