-
-
Notifications
You must be signed in to change notification settings - Fork 54
feat/lower squashfs size unpearl #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
blaggacao
wants to merge
6
commits into
nix-community:main
from
blaggacao:feat/lower-squashfs-size-unpearl
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5fa86c7
refactor: bash+jq instead of python closure
blaggacao be435b1
chore: anticipate expected delay in tests
blaggacao 87f8fb0
feat: free caches and log free mem before kexec
blaggacao dcbc47c
remove some extra weight
blaggacao 9bd468e
chore: iterate systemd slim
blaggacao ced3ac0
wip: unpearl
blaggacao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#!/usr/bin/env bash | ||
|
||
# filter_interfaces function | ||
filter_interfaces() { | ||
# This function takes a list of network interfaces as input and filters | ||
# out loopback interfaces, interfaces without a MAC address, and addresses | ||
# with a "link" scope or marked as dynamic (from DHCP or router | ||
# advertisements). The filtered interfaces are returned as an array. | ||
local network=("$@") | ||
|
||
for net in "${network[@]}"; do | ||
local link_type="$(jq -r '.link_type' <<< "$net")" | ||
local address="$(jq -r '.address // ""' <<< "$net")" | ||
local addr_info="$(jq -r '.addr_info | map(select(.scope != "link" and (.dynamic | not)))' <<< "$net")" | ||
local has_dynamic_address=$(jq -r '.addr_info | any(.dynamic)' <<< "$net") | ||
|
||
# echo "Link Type: $link_type -- Address: $address -- Has Dynamic Address: $has_dynamic_address -- Addr Info: $addr_info" | ||
|
||
if [[ "$link_type" != "loopback" && -n "$address" && ("$addr_info" != "[]" || "$has_dynamic_address" == "true") ]]; then | ||
net=$(jq -c --argjson addr_info "$addr_info" '.addr_info = $addr_info' <<< "$net") | ||
echo "$net" # "return" | ||
fi | ||
done | ||
} | ||
|
||
# filter_routes function | ||
filter_routes() { | ||
# This function takes a list of routes as input and filters out routes | ||
# with protocols "dhcp", "kernel", or "ra". The filtered routes are | ||
# returned as an array. | ||
local routes=("$@") | ||
|
||
for route in "${routes[@]}"; do | ||
local protocol=$(jq -r '.protocol' <<< "$route") | ||
if [[ $protocol != "dhcp" && $protocol != "kernel" && $protocol != "ra" ]]; then | ||
echo "$route" # "return" | ||
fi | ||
done | ||
} | ||
|
||
# generate_networkd_units function | ||
generate_networkd_units() { | ||
# This function takes the filtered interfaces and routes, along with a | ||
# directory path. It generates systemd-networkd unit files for each interface, | ||
# including the configured addresses and routes. The unit files are written | ||
# to the specified directory with the naming convention 00-<ifname>.network. | ||
local -n interfaces=$1 | ||
local -n routes=$2 | ||
local directory="$3" | ||
|
||
mkdir -p "$directory" | ||
|
||
for interface in "${interfaces[@]}"; do | ||
local ifname=$(jq -r '.ifname' <<< "$interface") | ||
local address=$(jq -r '.address' <<< "$interface") | ||
local addresses=$(jq -r '.addr_info | map("Address = \(.local)/\(.prefixlen)") | join("\n")' <<< "$interface") | ||
local route_sections=() | ||
|
||
for route in "${routes[@]}"; do | ||
local dev=$(jq -r '.dev' <<< "$route") | ||
if [[ $dev == $ifname ]]; then | ||
local route_section="[Route]" | ||
local dst=$(jq -r '.dst' <<< "$route") | ||
if [[ $dst != "default" ]]; then | ||
route_section+="\nDestination = $dst" | ||
fi | ||
local gateway=$(jq -r '.gateway // ""' <<< "$route") | ||
if [[ -n $gateway ]]; then | ||
route_section+="\nGateway = $gateway" | ||
fi | ||
route_sections+=("$route_section") | ||
fi | ||
done | ||
|
||
local unit=$(cat <<-EOF | ||
[Match] | ||
MACAddress = $address | ||
|
||
[Network] | ||
DHCP = yes | ||
LLDP = yes | ||
IPv6AcceptRA = yes | ||
MulticastDNS = yes | ||
|
||
$addresses | ||
$(printf '%s\n' "${route_sections[@]}") | ||
EOF | ||
) | ||
echo -e "$unit" > "$directory/00-$ifname.network" | ||
done | ||
} | ||
|
||
# main function | ||
main() { | ||
if [[ $# -lt 4 ]]; then | ||
echo "USAGE: $0 addresses routes-v4 routes-v6 networkd-directory" >&2 | ||
# exit 1 | ||
return 1 | ||
fi | ||
|
||
local addresses | ||
readarray -t addresses < <(jq -c '.[]' "$1") # Read JSON data into array | ||
|
||
local v4_routes | ||
readarray -t v4_routes < <(jq -c '.[]' "$2") | ||
|
||
local v6_routes | ||
readarray -t v6_routes < <(jq -c '.[]' "$3") | ||
|
||
local networkd_directory="$4" | ||
|
||
local relevant_interfaces | ||
readarray -t relevant_interfaces < <(filter_interfaces "${addresses[@]}") | ||
|
||
local relevant_routes | ||
readarray -t relevant_routes < <(filter_routes "${v4_routes[@]}" "${v6_routes[@]}") | ||
|
||
generate_networkd_units relevant_interfaces relevant_routes "$networkd_directory" | ||
} | ||
|
||
main "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{lib, ...}:{ | ||
# when grub ends up being bloat: kexec & netboot | ||
nixpkgs.overlays = [ | ||
(final: prev: { | ||
# we don't need grub: save ~ 60MB | ||
grub2 = prev.coreutils; | ||
grub2_efi = prev.coreutils; | ||
}) | ||
]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have switch-to-configuration.pl after that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true.
Maybe I did ingest that wrongly, however my current understanding was that
nixos-anywhere
at "most" requiresnixos-install
which depends onnixos-enter
and if that depends onswitch-to-...
, then it indeed escaped my attention.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I mean. There is also a switch-to-configuration that the system itself has independent on those nixos tools.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess that was weeded out by
system.switch.enable = false;
down below