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
|
|
|
|
2023-01-07 04:09:35 -06:00
|
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
|
|
|
2023-01-07 13:21:03 -06:00
|
|
|
pre-commit-hooks-nix = {
|
|
|
|
url = "github:cachix/pre-commit-hooks.nix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
inputs.flake-utils.follows = "flake-utils";
|
|
|
|
};
|
|
|
|
|
2023-01-07 04:09:35 -06:00
|
|
|
# We only have this input to pass it to other dependencies and
|
|
|
|
# avoid having mulitple versions in our dependencies.
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
|
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-11-21 04:44:04 -06:00
|
|
|
};
|
|
|
|
|
2023-01-07 04:09:35 -06:00
|
|
|
outputs = inputs@{ self, nixpkgs, nixpkgs-test, crane, rust-overlay, flake-parts, ... }:
|
2023-01-07 04:52:49 -06:00
|
|
|
flake-parts.lib.mkFlake { inherit inputs; } ({ moduleWithSystem, ... }: {
|
|
|
|
imports = [
|
|
|
|
# Derive the output overlay automatically from all packages that we define.
|
|
|
|
inputs.flake-parts.flakeModules.easyOverlay
|
2023-01-07 13:21:03 -06:00
|
|
|
|
|
|
|
# Formatting and quality checks.
|
|
|
|
inputs.pre-commit-hooks-nix.flakeModule
|
2023-01-07 04:52:49 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
flake.nixosModules.lanzaboote = moduleWithSystem (
|
|
|
|
perSystem@{ config }:
|
|
|
|
{ ... }: {
|
|
|
|
imports = [
|
|
|
|
./nix/modules/lanzaboote.nix
|
|
|
|
];
|
|
|
|
|
2023-01-13 15:10:40 -06:00
|
|
|
boot.lanzaboote.package = perSystem.config.packages.tool;
|
2023-01-08 07:42:30 -06:00
|
|
|
}
|
|
|
|
);
|
2023-01-07 04:52:49 -06:00
|
|
|
|
|
|
|
systems = [
|
|
|
|
"x86_64-linux"
|
|
|
|
|
|
|
|
# Not actively tested, but may work:
|
|
|
|
# "aarch64-linux"
|
|
|
|
];
|
|
|
|
|
2023-01-08 07:42:30 -06:00
|
|
|
perSystem = { config, system, pkgs, ... }:
|
|
|
|
let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
system = system;
|
|
|
|
overlays = [
|
|
|
|
rust-overlay.overlays.default
|
|
|
|
];
|
|
|
|
};
|
2022-11-24 05:05:46 -06:00
|
|
|
|
2023-01-08 07:42:30 -06:00
|
|
|
testPkgs = import nixpkgs-test { system = "x86_64-linux"; };
|
|
|
|
|
|
|
|
inherit (pkgs) lib;
|
|
|
|
|
2023-01-13 13:50:50 -06:00
|
|
|
rust-nightly = pkgs.rust-bin.fromRustupToolchainFile ./rust/stub/rust-toolchain.toml;
|
2023-01-08 07:42:30 -06:00
|
|
|
craneLib = crane.lib.x86_64-linux.overrideToolchain rust-nightly;
|
|
|
|
|
|
|
|
# Build attributes for a Rust application.
|
|
|
|
buildRustApp =
|
|
|
|
{ src
|
|
|
|
, target ? null
|
|
|
|
, doCheck ? true
|
|
|
|
, extraArgs ? { }
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
commonArgs = {
|
|
|
|
inherit src;
|
|
|
|
CARGO_BUILD_TARGET = target;
|
|
|
|
inherit doCheck;
|
|
|
|
} // extraArgs;
|
|
|
|
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
|
|
in
|
2023-01-07 04:09:35 -06:00
|
|
|
{
|
|
|
|
package = craneLib.buildPackage (commonArgs // {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
});
|
|
|
|
|
|
|
|
clippy = craneLib.cargoClippy (commonArgs // {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
cargoClippyExtraArgs = "-- --deny warnings";
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-01-13 15:10:40 -06:00
|
|
|
stubCrane = buildRustApp {
|
2023-01-13 13:50:50 -06:00
|
|
|
src = craneLib.cleanCargoSource ./rust/stub;
|
2023-01-08 07:42:30 -06:00
|
|
|
target = "x86_64-unknown-uefi";
|
|
|
|
doCheck = false;
|
2023-01-07 04:09:35 -06:00
|
|
|
};
|
|
|
|
|
2023-01-13 15:10:40 -06:00
|
|
|
stub = stubCrane.package;
|
2023-01-07 04:09:35 -06:00
|
|
|
|
2023-01-13 15:10:40 -06:00
|
|
|
toolCrane = buildRustApp {
|
2023-01-13 13:50:50 -06:00
|
|
|
src = ./rust/tool;
|
2023-01-08 07:42:30 -06:00
|
|
|
extraArgs = {
|
|
|
|
TEST_SYSTEMD = pkgs.systemd;
|
|
|
|
checkInputs = with pkgs; [
|
|
|
|
binutils-unwrapped
|
|
|
|
sbsigntool
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2023-01-07 04:52:49 -06:00
|
|
|
|
2023-01-13 15:10:40 -06:00
|
|
|
tool = toolCrane.package;
|
|
|
|
|
|
|
|
wrappedTool = pkgs.runCommand "lzbt"
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
|
|
} ''
|
|
|
|
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 ${tool}/bin/lzbt $out/bin/lzbt \
|
|
|
|
--set PATH ${lib.makeBinPath [ pkgs.binutils-unwrapped pkgs.sbsigntool ]} \
|
|
|
|
--set RUST_BACKTRACE full \
|
|
|
|
--set LANZABOOTE_STUB ${stub}/bin/lanzaboote_stub.efi
|
|
|
|
'';
|
2023-01-08 07:42:30 -06:00
|
|
|
in
|
|
|
|
{
|
|
|
|
packages = {
|
2023-01-13 15:10:40 -06:00
|
|
|
inherit stub;
|
|
|
|
tool = wrappedTool;
|
|
|
|
lzbt = wrappedTool;
|
2023-01-08 07:42:30 -06:00
|
|
|
};
|
2023-01-08 07:41:01 -06:00
|
|
|
|
2023-01-08 07:42:30 -06:00
|
|
|
overlayAttrs = {
|
2023-01-13 15:10:40 -06:00
|
|
|
inherit (config.packages) tool;
|
2023-01-08 07:41:01 -06:00
|
|
|
};
|
2023-01-07 13:21:03 -06:00
|
|
|
|
2023-01-08 07:42:30 -06:00
|
|
|
checks = {
|
2023-01-13 15:10:40 -06:00
|
|
|
toolClippy = toolCrane.clippy;
|
|
|
|
stubClippy = stubCrane.clippy;
|
2023-01-08 07:42:30 -06:00
|
|
|
} // (import ./nix/tests/lanzaboote.nix {
|
|
|
|
inherit pkgs testPkgs;
|
|
|
|
lanzabooteModule = self.nixosModules.lanzaboote;
|
|
|
|
});
|
|
|
|
|
|
|
|
pre-commit = {
|
|
|
|
check.enable = true;
|
2023-01-07 13:21:03 -06:00
|
|
|
|
2023-01-08 07:42:30 -06:00
|
|
|
settings.hooks = {
|
|
|
|
nixpkgs-fmt.enable = true;
|
2023-01-07 04:52:49 -06:00
|
|
|
};
|
2023-01-08 07:42:30 -06:00
|
|
|
};
|
2023-01-07 04:09:35 -06:00
|
|
|
|
2023-01-08 07:42:30 -06:00
|
|
|
devShells.default = pkgs.mkShell {
|
|
|
|
shellHook = ''
|
|
|
|
${config.pre-commit.installationScript}
|
|
|
|
'';
|
|
|
|
|
|
|
|
packages =
|
|
|
|
let
|
|
|
|
uefi-run = pkgs.callPackage ./nix/packages/uefi-run.nix {
|
|
|
|
inherit craneLib;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
[
|
|
|
|
uefi-run
|
|
|
|
pkgs.openssl
|
|
|
|
(pkgs.sbctl.override {
|
|
|
|
databasePath = "pki";
|
|
|
|
})
|
|
|
|
pkgs.sbsigntool
|
|
|
|
pkgs.efitools
|
|
|
|
pkgs.python39Packages.ovmfvartool
|
|
|
|
pkgs.qemu
|
|
|
|
pkgs.nixpkgs-fmt
|
|
|
|
pkgs.statix
|
|
|
|
];
|
|
|
|
|
|
|
|
inputsFrom = [
|
2023-01-13 15:10:40 -06:00
|
|
|
config.packages.stub
|
|
|
|
config.packages.tool
|
2023-01-08 07:42:30 -06:00
|
|
|
];
|
2023-01-07 04:09:35 -06:00
|
|
|
|
2023-01-08 07:42:30 -06:00
|
|
|
TEST_SYSTEMD = pkgs.systemd;
|
|
|
|
};
|
2023-01-07 04:09:35 -06:00
|
|
|
};
|
2023-01-07 04:52:49 -06:00
|
|
|
});
|
2022-11-21 04:44:04 -06:00
|
|
|
}
|