2022-10-21 02:32:02 +00:00
{
2024-05-02 18:57:05 +00:00
description = " O p t i m i z e d h e a d s f l a k e f o r D o c k e r i m a g e w i t h g a r b a g e c o l l e c t i o n p r o t e c t i o n " ;
2022-10-21 02:32:02 +00:00
2024-05-02 18:57:05 +00:00
# Inputs define external dependencies and their sources.
2022-10-21 02:32:02 +00:00
inputs = {
2024-05-02 18:57:05 +00:00
nixpkgs . url = " g i t h u b : n i x o s / n i x p k g s / n i x o s - u n s t a b l e " ; # Using the unstable channel for the latest packages, while flake.lock fixates the commit reused until changed.
flake-utils . url = " g i t h u b : n u m t i d e / f l a k e - u t i l s " ; # Utilities for flake functionality.
2022-10-21 02:32:02 +00:00
} ;
2024-05-02 18:57:05 +00:00
# Outputs are the result of the flake, including the development environment and Docker image.
outputs = { self , nixpkgs , flake-utils , . . . }:
2022-10-21 02:32:02 +00:00
flake-utils . lib . eachDefaultSystem ( system : let
2024-05-02 18:57:05 +00:00
pkgs = nixpkgs . legacyPackages . ${ system } ; # Accessing the legacy package set.
lib = pkgs . lib ; # The standard Nix packages library.
# Dependencies are the packages required for the Heads project.
# Organized into subsets for clarity and maintainability.
deps = with pkgs ; [
# Core build utilities
autoconf
automake
bashInteractive
coreutils
bc
2024-05-03 14:13:09 +00:00
bison # Generate flashmap descriptor parser
2024-05-02 18:57:05 +00:00
bzip2
cacert
ccache
cmake
cpio
curl
diffutils
dtc
e2fsprogs
elfutils
findutils
flex
gawk
git
gnat
gnugrep
gnumake
gnused
gnutar
gzip
imagemagick # For bootsplash manipulation.
innoextract # ROM extraction for dGPU.
libtool
m4
2024-05-03 14:13:09 +00:00
ncurses5 # make menuconfig and slang
openssl #needed for talos-2 kernel build
2024-05-02 18:57:05 +00:00
parted
patch
perl
pkg-config
python3 # me_cleaner, coreboot.
rsync # coreboot.
sharutils
texinfo
unzip
wget
which
xz
zip
zlib
zlib . dev
] ++ [
# Packages for qemu support with Canokey integration.
qemu # To test make BOARD=qemu-coreboot-* boards and then call make BOARD=qemu-coreboot-* with inject_gpg statement, and then run statement (RTFM).
2024-05-03 14:13:09 +00:00
#canokey doesn;t work still even if compiled in, so no reason to add 1Gb of stuff in the image
#canokey-qemu # Canokey lib for qemu build-time compilation.
#(qemu.override {
# canokeySupport = true; # This override enables Canokey support in QEMU, resulting in -device canokey being available.
#})
2024-05-02 18:57:05 +00:00
] ++ [
2024-05-03 14:13:09 +00:00
# Additional tools for debugging/editing/testing.
2024-05-02 18:57:05 +00:00
vim # Mostly used amongst us, sorry if you'd like something else, open issue.
swtpm # QEMU requirement to emulate tpm1/tpm2.
dosfstools # QEMU requirement to produce valid fs to store exported public key to be fused through inject_key on qemu (so qemu flashrom emulated SPI support).
] ++ [
2024-05-03 14:13:09 +00:00
# Tools for handling binary blobs in their compressed state. (blobs/xx30/vbios_[tw]530.sh)
2024-05-02 18:57:05 +00:00
bundler
p7zip
ruby
2024-05-03 14:13:09 +00:00
sudo # ( °-° )
2024-05-02 18:57:05 +00:00
upx
] ;
# Stripping binaries to reduce size, while ensuring functionality is not affected.
stripBinaries = map ( pkg : if pkg ? isDerivation then pkg . overrideAttrs ( oldAttrs : {
postInstall = oldAttrs . postInstall or " " + ''
strip $ out/bin /* | | t r u e
'' ;
} ) else pkg ) deps ;
2022-10-21 02:32:02 +00:00
in {
2024-05-02 18:57:05 +00:00
# The development shell includes all the dependencies.
2022-10-21 02:32:02 +00:00
devShell = pkgs . mkShellNoCC {
2024-05-02 18:57:05 +00:00
buildInputs = stripBinaries ++ [ pkgs . nix ] ; # Include the Nix package to provide nix-collect-garbage.
shellHook = ''
# Create a garbage collection root for the Nix profile
mkdir - p /nix/var/nix/gcroots/per-user / $ ( whoami )
echo $ ( readlink - f $ HOME/.nix-profile ) > /nix/var/nix/gcroots/per-user / $ ( whoami ) /profile
# Perform garbage collection to clean up any unnecessary files.
nix-collect-garbage - d
'' ;
2022-10-21 02:32:02 +00:00
} ;
2024-05-02 18:57:05 +00:00
# myDevShell outputs environment variables necessary for development.
2022-10-21 02:32:02 +00:00
packages . myDevShell =
pkgs . runCommand " m y - d e v - s h e l l " { }
#bash
''
grep \
- e CMAKE_PREFIX_PATH \
- e NIX_CC_WRAPPER_TARGET_TARGET \
- e NIX_CFLAGS_COMPILE_FOR_TARGET \
- e NIX_LDFLAGS_FOR_TARGET \
- e PKG_CONFIG_PATH_FOR_TARGET \
2024-05-02 13:54:14 +00:00
- e ACLOCAL_PATH \
2022-10-21 02:32:02 +00:00
$ { self . devShell . ${ system } } > $ out
'' ;
2024-05-02 18:57:05 +00:00
# Docker image configuration for the Heads project.
2022-10-21 02:32:02 +00:00
packages . dockerImage = pkgs . dockerTools . buildLayeredImage {
2024-05-02 18:57:05 +00:00
name = " l i n u x b o o t / h e a d s " ; # Image name.
tag = " d e v - e n v " ; # Image tag.
2024-05-03 14:13:09 +00:00
config . Entrypoint = [ " b a s h " " - c " '' s o u r c e / d e v e n v . s h ; i f ( ( $# = = 0 ) ) ; t h e n e x e c b a s h ; e l s e e x e c " $0 " " $@ " ; f i '' ] ; # Entrypoint configuration.
2024-05-02 18:57:05 +00:00
# Contents of the Docker image, including stripped binaries for size optimization.
contents = stripBinaries ++ [
pkgs . dockerTools . binSh
pkgs . dockerTools . caCertificates
pkgs . dockerTools . usrBinEnv
] ;
enableFakechroot = true ; # Enable fakechroot for compatibility.
# Fake root commands to set up the environment inside the Docker image.
2022-10-21 02:32:02 +00:00
fakeRootCommands =
#bash
''
2024-05-02 18:57:05 +00:00
set - e
2022-10-21 02:32:02 +00:00
2024-05-02 18:57:05 +00:00
# Environment setup for the development shell.
grep \
- e NIX_CC_WRAPPER_TARGET_TARGET \
- e NIX_CFLAGS_COMPILE_FOR_TARGET \
- e NIX_LDFLAGS_FOR_TARGET \
- e NIX_PKG_CONFIG_WRAPPER_TARGET \
- e PKG_CONFIG_PATH_FOR_TARGET \
- e ACLOCAL_PATH \
$ { self . devShell . ${ system } } > /devenv.sh
2022-10-21 02:32:02 +00:00
2024-05-03 14:13:09 +00:00
# Git configuration for safe directory access.
2024-05-02 18:57:05 +00:00
printf ' [ safe ] \ n \ tdirectory = * \ n' > /.gitconfig
2024-05-03 14:13:09 +00:00
mkdir /tmp ; # Temporary directory for various operations.
2024-05-02 18:57:05 +00:00
'' ;
2022-10-21 02:32:02 +00:00
} ;
} ) ;
}
2024-05-02 18:57:05 +00:00