Skip to content

Commit

Permalink
Import necessary overlays to update how flash-script is created
Browse files Browse the repository at this point in the history
Signed-off-by: juliuskoskela <[email protected]>
  • Loading branch information
juliuskoskela committed Sep 9, 2024
1 parent 0a93666 commit d0777dc
Showing 1 changed file with 11 additions and 55 deletions.
66 changes: 11 additions & 55 deletions lib/mk-flash-script/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,20 @@
flash-tools-system,
}:
let
cfg = hostConfiguration.config.hardware.nvidia-jetpack;
inherit (jetpack-nixos.legacyPackages.${flash-tools-system}) flash-tools;

# jetpack-nixos has the cross-compilation set up in a slightly strange way,
# the packages under x86_64-linux are actually cross-compiled packages for
# aarch64-linux. So we will get devicePkgs from x86_64-linux if we are cross
# compiling, otherwise we end up building UEFI firmware etc. binaries used by
# flash-script natively.
isCross =
hostConfiguration.config.nixpkgs.buildPlatform.system
!= hostConfiguration.config.nixpkgs.hostPlatform.system;
devicePkgsSystem = if isCross then "x86_64-linux" else "aarch64-linux";
devicePkgs =
jetpack-nixos.legacyPackages.${devicePkgsSystem}.devicePkgsFromNixosConfig
hostConfiguration.config;

inherit (jetpack-nixos.legacyPackages.${devicePkgsSystem}) l4tVersion;

flashScript = devicePkgs.mkFlashScript {
flash-tools = flash-tools.overrideAttrs (
{
postPatch ? "",
...
}:
{
postPatch = postPatch + cfg.flashScriptOverrides.postPatch;
}
);
preFlashCommands =
nixpkgs.lib.optionalString (flash-tools-system == "aarch64-linux") ''
echo "WARNING! WARNING! WARNING!"
echo "You are trying to run aarch64-linux hosted version of the flash-script."
echo "It runs flashing tools with QEMU using user-mode emulation of x86 cpu."
echo "There are no known reports from anyone who would have gotten this working ever."
echo "If this fails, YOU HAVE BEEN WARNED, and don't open a bug report!"
echo ""
''
+ hostConfiguration.config.ghaf.hardware.nvidia.orin.flashScriptOverrides.preFlashCommands;
flashSystem = "x86_64-linux";
pkgs = import nixpkgs {
system = flashSystem;
overlays = [
jetpack-nixos.overlays.default
(import "${jetpack-nixos}/overlay-with-config.nix" hostConfiguration)
];
};

patchFlashScript =
builtins.replaceStrings
[
"@pzstd@"
"@sed@"
"@patch@"
"@l4tVersion@"
"@isCross@"
]
[
"${nixpkgs.legacyPackages.${flash-tools-system}.zstd}/bin/pzstd"
"${nixpkgs.legacyPackages.${flash-tools-system}.gnused}/bin/sed"
"${nixpkgs.legacyPackages.${flash-tools-system}.patch}/bin/patch"
"${l4tVersion}"
"${if isCross then "true" else "false"}"
];
inherit (pkgs.nvidia-jetpack) flash-tools;

flashScript = pkgs.nvidia-jetpack.mkFlashScript flash-tools { };
in
nixpkgs.legacyPackages.${flash-tools-system}.writeShellApplication {
name = "flash-ghaf";
text = patchFlashScript flashScript;
text = flashScript;
}

0 comments on commit d0777dc

Please sign in to comment.