lanzaboote/flake.nix

148 lines
4.0 KiB
Nix
Raw Normal View History

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 = {
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";
inputs.rust-overlay.follows = "rust-overlay";
inputs.flake-utils.follows = "flake-utils";
2022-11-26 09:41:48 -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;
};
flake-utils.url = "github:numtide/flake-utils";
2022-11-21 04:44:04 -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"; };
inherit (pkgs) lib;
2022-11-24 05:05:46 -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
uefi-run = pkgs.callPackage ./nix/packages/uefi-run.nix {
inherit craneLib;
2022-11-21 08:36:39 -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-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
lanzabooteCrane = buildRustApp {
src = ./rust/lanzaboote;
target = "x86_64-unknown-uefi";
doCheck = false;
};
lanzaboote = lanzabooteCrane.package;
2022-11-26 09:41:48 -06:00
lanzatoolCrane = buildRustApp {
src = ./rust/lanzatool;
2022-11-24 04:45:09 -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.
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 ]} \
--set RUST_BACKTRACE full \
--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: {
inherit lanzatool;
2022-11-23 04:59:54 -06:00
};
2022-12-08 14:23:35 -06:00
nixosModules.lanzaboote = { pkgs, lib, ... }: {
imports = [ ./nix/modules/lanzaboote.nix ];
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 = {
inherit lanzaboote lanzatool;
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 {
packages = [
2022-11-21 17:45:18 -06:00
uefi-run
2022-11-21 19:08:35 -06:00
pkgs.openssl
(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
pkgs.nixpkgs-fmt
pkgs.statix
2022-11-21 17:45:18 -06:00
];
inputsFrom = [
lanzaboote
lanzatool
];
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
}