Skip to content

lanzaboote-stub: init at 0.3.0 - #231951

Closed
RaitoBezarius wants to merge 4 commits into
stagingfrom
lanzaboote
Closed

RaitoBezarius wants to merge 4 commits into
stagingfrom
lanzaboote

Conversation

@RaitoBezarius

@RaitoBezarius RaitoBezarius commented May 14, 2023

Copy link
Copy Markdown
Member
Description of changes

This brings https://github.com/nix-community/lanzaboote UEFI stub in-tree.

Dependents:

Dependencies:

Related:

Current design

Stub and tool are packaged in the global hierarchy as: lanzaboote-tool and lanzaboote-uefi-stub, no assumption on the system are encoded inside their package respectively.

It is expected to build the UEFI stub using a UEFI system with a UEFI compiler.

The linker is a flavored linker which will propagate adequately the lld Windows-style driver for arguments.

lanzaboote-tool is supposed to be wrapped to know about its lanzaboote-stub, unfortunately, this is impossible to achieve inside of nixpkgs, multiple attempts were proposed to the reviewers in the next section and were all rejected. Therefore, the only solution is to give up on having a wrapped lanzaboote-tool and propose a semi-wrapped lanzaboote-tool and expect the user to understand they have to export the LANZABOOTE_STUB environment variable to know about the stub itself.

This is what we do in the systemd-boot NixOS module ourselves and we expect to work in many cases, either case, author would like to move this PR forward ideally and not concern themselves further with the semi wrapping issue stemming from the impossibility to build a package as a data via cross-compilation inside of nixpkgs, alas.

What has been tried?
  • Trivial implementation using nixpkgs reimport inside of pkgs/ hierarchy: NACK because it reimports nixpkgs inside nixpkgs.
  • Introduction of a UEFI system example: NACK because there is divergence on the system data, see discussion on MinGW style vs MSVC and GNU-Config as a general.
  • Complicated implementation by locally rebooting nixpkgs inside the package definition of the tool to compile the stub using a hacked stdenv: NACK because it's too complicated.
  • Complicated implementation by locally rebooting a new package scope called uefiPkgs for cross compilation inside nixpkgs without a direct reimport: NACK because it's too complicated and does not compose well.
Some funny questions

It seems like this PR tries to move to make UEFI a proper target in nixpkgs, but there's already plenty of "data as UEFI binaries" inside of nixpkgs without any cross compilation involved per se:

  • EDK2/OVMF firmware
  • systemd-boot
  • GRUB EFI

Ideally, we should treat the same way as in this PR, I suppose this will be very hard given their build system.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@ofborg ofborg Bot added 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels May 15, 2023
@github-actions github-actions Bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jun 13, 2023
@RaitoBezarius RaitoBezarius changed the title lanzaboote: init at 0.3.0 lanzaboote-tool, lanzaboote-stub: init at 0.3.0, nixos/systemd-boot: init secureboot with lanzaboote Jun 13, 2023
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread pkgs/top-level/all-packages.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
@RaitoBezarius

This comment was marked as duplicate.

Comment thread pkgs/tools/system/lanzaboote/stub.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/stub.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/stub.nix Outdated
@pasqui23
pasqui23 requested review from a user, ElvishJerricco and Kranzes June 17, 2023 12:36
@ghost

ghost commented Jun 19, 2023

Copy link
Copy Markdown

#235230 is done; reviewing this PR is next on my list.

Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/tool.nix Outdated
Comment thread pkgs/tools/system/lanzaboote/stub.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
Comment thread nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix Outdated
@RaitoBezarius
RaitoBezarius force-pushed the lanzaboote branch 3 times, most recently from 5586367 to e2723f0 Compare July 8, 2023 17:11
@ghost

ghost commented Oct 30, 2023

Copy link
Copy Markdown

will wait for him to go into staging

It's only on staging because it needs d474c87. That commit is in staging-next, so at the next merge of staging to master I will be able to switch the base branch of #235230 back to master.

I will rebase on @amjoseph-nixpkgs PR for testing the triples for gnu-config,

Oh you don't need to wait for #235230 and in fact you shouldn't, since it causes a mass-rebuild.

Just please check that the CI it adds still passes with (the final version of) this PR. If it doesn't pass either it found a bug in your PR, or your PR found a bug in the new tests -- either way let me know so we're aware.

I'm thinking ahead to a scenario where this PR merges ahead of the 23.11 branch-off but #235230 doesn't.

@ghost

ghost commented Oct 30, 2023

Copy link
Copy Markdown

And… it's clear that even with this patch, this is insufficient. Everything else is unfinished, it explodes at compiler-rt:

Github needs a 😭 reaction/vote

@ghost

ghost commented Oct 30, 2023

Copy link
Copy Markdown

And… it's clear that even with this patch, this is insufficient. Everything else is unfinished, it explodes at compiler-rt:

What about the following? It's gross, but as long as LLVM has merged the change into LLVM17 it's effectively just a different way of backporting that change:

diff --git a/pkgs/development/compilers/llvm/16/llvm/default.nix b/pkgs/development/compilers/llvm/16/llvm/default.nix
index 9475b5c99485..c5bcfd35c5bf 100644
--- a/pkgs/development/compilers/llvm/16/llvm/default.nix
+++ b/pkgs/development/compilers/llvm/16/llvm/default.nix
@@ -36,6 +36,10 @@
 let
   inherit (lib) optional optionals optionalString;

+  hackThemTriplesForGreatJustice = triple: {
+    "aarch64-unknown-uefi" = "aarch64-windows";
+  }.${triple} or triple;
+
   # Used when creating a version-suffixed symlink of libLLVM.dylib
   shortVersion = with lib;
     concatStringsSep "." (take 1 (splitString "." release_version));
@@ -308,8 +312,8 @@ in
     "-DLLVM_INSTALL_UTILS=ON"  # Needed by rustc
     "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}"
     "-DLLVM_ENABLE_FFI=ON"
-    "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
-    "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
+    "-DLLVM_HOST_TRIPLE=${hackThemTriplesForGreatJustice stdenv.hostPlatform.config}"
+    "-DLLVM_DEFAULT_TARGET_TRIPLE=${hackThemTriplesForGreatJustice stdenv.hostPlatform.config}"
     "-DLLVM_ENABLE_DUMP=ON"
   ] ++ optionals stdenv.hostPlatform.isStatic [
     # Disables building of shared libs, -fPIC is still injected by cc-wrapper

@alyssais

Copy link
Copy Markdown
Member

I think backporting the Triple commit seems fair, but I don't mind waiting for LLVM17 though it's tiring.

Last I remember, LLVM 17 was basically ready I think? Can we push it over the line?

@RaitoBezarius

RaitoBezarius commented Oct 30, 2023 via email

Copy link
Copy Markdown
Member Author

Comment on lines +26 to +29
patches = [
./support-uefi-triples.patch
];

@ghost ghost Nov 1, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm flattered that you included my patch but since it hasn't been merged upstream I don't think we should do this yet.

Instead I've added *-*-uefi to the exception-list: 54ddd6e 20a384e in #235230

If gnu-config merges the patch then we can just drop the exception. If they don't, then the fallout is limited to having an extra exception rather than having to back out the patch (which causes a total rebuild of the entire packageset).

@ghost ghost Nov 1, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a17e894 to this branch to drop the patch. Speeds up CI since gnu-config is part of stdenv.

@ghost

ghost commented Nov 1, 2023

Copy link
Copy Markdown

Edited top comment to get github to display the merged/open/draft icon, and note that #264297 can be used instead of #263711

@ghost
ghost requested review from edolstra and infinisil as code owners November 1, 2023 07:53
@ghost

ghost commented Nov 1, 2023

Copy link
Copy Markdown

Pushed to this branch:

When I run CI locally it passes. Let's see what ofborg says.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got CI to pass.

My opinion remains unchanged: UEFI is a boondoggle.

But if the boon must be doggled, at least it will be done using Nix and Rust. 🤷‍♂️

homepage = "https://github.com/nix-community/lanzaboote";
license = licenses.gpl3Only;
mainProgram = "lanzaboote_stub.efi";
platforms = [ "x86_64-uefi" "i686-uefi" "aarch64-uefi" ];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
platforms = [ "x86_64-uefi" "i686-uefi" "aarch64-uefi" ];
hydraPlatforms = [ lib.systems.inspect.platformPatterns.isUefi ];

platforms = [ "x86_64-uefi" "i686-uefi" "aarch64-uefi" ];
# i686: Builtins errors
# aarch64: compile fine but...
broken = stdenv.isi686 || stdenv.isAarch64;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
broken = stdenv.isi686 || stdenv.isAarch64;
broken = with stdenv.hostPlatform; isi686 || isAarch64;

Comment thread lib/systems/examples.nix
linker = "lld";
};


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment thread lib/systems/doubles.nix
redox = filterDoubles predicates.isRedox;
windows = filterDoubles predicates.isWindows;
genode = filterDoubles predicates.isGenode;
uefi = filterDoubles predicates.isEfiEnvironment;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uefi = filterDoubles predicates.isEfiEnvironment;
uefi = filterDoubles predicates.isUefi;

Comment thread lib/systems/inspect.nix
isMusl = with abis; map (a: { abi = a; }) [ musl musleabi musleabihf muslabin32 muslabi64 ];
isUClibc = with abis; map (a: { abi = a; }) [ uclibc uclibceabi uclibceabihf ];

isEfiEnvironment = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isEfiEnvironment = [
isUefi = [

mainProgram = "lanzaboote_stub.efi";
platforms = [ "x86_64-uefi" "i686-uefi" "aarch64-uefi" ];
# i686: Builtins errors
# aarch64: compile fine but...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# aarch64: compile fine but...
# aarch64: compile fine but unable to test on real hardware

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be # aarch64: compiles fine but unable to test on real hardware?

@ofborg ofborg Bot added 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. labels Nov 1, 2023
@ghost

ghost commented Nov 1, 2023

Copy link
Copy Markdown

If you rebase this to a more recent staging (or switch branch to master) I think the ofborg rebuild tags will go away.

@RaitoBezarius

Copy link
Copy Markdown
Member Author

If you rebase this to a more recent staging (or switch branch to master) I think the ofborg rebuild tags will go away.

I just need to do it when I don't feel like I will fuck up :D.

@ghost ghost mentioned this pull request Nov 4, 2023
12 tasks
@TobiPeterG

Copy link
Copy Markdown

Is there any progress on this? :)

@baloo

baloo commented Nov 3, 2024

Copy link
Copy Markdown
Member

Got CI to pass.

@ghost

I'm a bit late to the party, but I'm trying to revive it in #353050, but I'm getting compilation errors on compiler-rt and I'm not sure which derivation you tried to build. None of the options I tried worked.

@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/installation-medium-has-invalid-secure-boot-signature/58952/6

@Mic92

Mic92 commented Jan 19, 2025

Copy link
Copy Markdown
Member

This pull requests is stalled.

@RaitoBezarius

Copy link
Copy Markdown
Member Author

This pull requests is stalled.

Can I ask you the courtesy to ping the author of PR whom you close PRs? (Or put the documentation of that new nixpkgs process in your closing messages?)

Thank you.

@Mic92

Mic92 commented Jan 20, 2025

Copy link
Copy Markdown
Member

Well, do you want to work on this? You said me in several occasions that you don't want to contribute to nixpkgs anymore and working on your NixOS fork. I do not think we should add too many processes to nixpkgs because it will make it too hard to understand how to make changes, so please just re-open the pull request again if you want to work on this. Otherwise just delete the branch.

@RaitoBezarius

Copy link
Copy Markdown
Member Author

Well, do you want to work on this? You said me in several occasions that you don't want to contribute to nixpkgs anymore and working on your NixOS fork. I do not think we should add too many processes to nixpkgs because it will make it too hard to understand how to make changes, so please just re-open the pull request again if you want to work on this. Otherwise just delete the branch.

Again, all of this has nothing to do with my request. Simply ask before doing what when it comes to other people's work is what I would like you to do. Thank you.

@Mic92

Mic92 commented Jan 20, 2025

Copy link
Copy Markdown
Member

Well, usually I ask them to re-open their pull request if they want to continue to work on the pull request. But I was 95% sure you would want not do that, so I kept it at that.

@RaitoBezarius

Copy link
Copy Markdown
Member Author

Well, usually I ask them to re-open their pull request if they want to continue to work on the pull request. But I was 95% sure you would want not do that, so I kept it at that.

If you want to make up your own rules, please consider discussing it with others before applying them out of the blue, especially when it comes to the work of others. "Closing then asking to re-open" is not courtesy, it's just you doing whatever you think is acceptable to do at any time, and you are continuing to shove your view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: lib The Nixpkgs function library 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.