Skip to content
archix is being rescoped. Don't install it yet.The released archix-git is the old model, which replaced packages and boot entries itself and broke a real install. The new design leaves packages to pacman and libalpm and rollback to snapper, and adds a diff that shows exactly what a switch will change. These docs describe the old model until the new one ships.Read the new scope.

Environment and firewall

Two things most machines need, declared like everything else: the environment every user starts with, and a firewall.

environment.variables sets variables for every user:

lua/modules/common.lua
return {
environment = {
variables = {
EDITOR = "nvim",
MOZ_ENABLE_WAYLAND = 1,
XDG_DATA_DIRS = { "/usr/local/share", "/usr/share", "/var/lib/flatpak/exports/share" },
PATH = "$HOME/.local/bin:$PATH",
},
},
}

A list is joined with :, so it works for path-like variables; numbers and other values are written as text. archix writes each variable twice, because nothing on Linux reads one file for every program:

  • /etc/profile.d/archix-environment.sh, for login shells. Arch’s bash and zsh read /etc/profile, which sources it:

    /etc/profile.d/archix-environment.sh
    export EDITOR="nvim"
    export MOZ_ENABLE_WAYLAND="1"
    export PATH="$HOME/.local/bin:$PATH"
    export XDG_DATA_DIRS="/usr/local/share:/usr/share:/var/lib/flatpak/exports/share"
  • /etc/environment.d/90-archix.conf, for systemd user services and graphical sessions started by them:

    /etc/environment.d/90-archix.conf
    EDITOR=nvim
    MOZ_ENABLE_WAYLAND=1
    PATH=$HOME/.local/bin:$PATH
    XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/flatpak/exports/share

Both files expand $VAR and ${VAR}: the shell file puts each value in double quotes, escaping ", \ and backticks, and environment.d expands references itself. So PATH = "$HOME/.local/bin:$PATH" adds to the existing PATH in a login shell and in a user service alike. New values reach a session the next time you log in.

environment.shell_aliases gives every user’s login shells the same aliases, from /etc/profile.d/archix-aliases.sh:

lua/modules/common.lua
return {
environment = {
shell_aliases = { ll = "ls -l", gs = "git status" },
},
}
/etc/profile.d/archix-aliases.sh
alias gs='git status'
alias ll='ls -l'

Only login shells read /etc/profile.d. A terminal emulator usually starts a shell that isn’t a login shell, so for aliases in every interactive zsh, use programs.zsh.shell_aliases, which goes into ~/.zshrc.

firewall.enable = true turns on an nftables firewall. Incoming traffic is dropped unless it answers something the machine sent, or you allow it. Outgoing traffic isn’t filtered.

lua/hosts/server/init.lua
return {
firewall = {
enable = true,
allowed_tcp_ports = { 22, 80, 443 },
allowed_udp_ports = { 443 },
},
}

The switch adds the nftables package, writes the rules to /etc/nftables-archix.conf, and writes and enables archix-firewall.service, which loads them before the network comes up at every boot. The switch applies in place, so it starts the service right away:

Terminal window
$ sudo archix switch
install nftables 1:1.1.5-1
create /etc/nftables-archix.conf
create /etc/systemd/system/archix-firewall.service
enable archix-firewall.service
apply 5 changes? [Y/n]

The rules are an inet archix table, for IPv4 and IPv6 alike:

/etc/nftables-archix.conf
#!/usr/bin/nft -f
# Written by archix from the firewall options.
table inet archix
delete table inet archix
table inet archix {
chain rpfilter {
type filter hook prerouting priority mangle + 10; policy accept;
meta nfproto ipv4 udp sport . udp dport { 68 . 67, 67 . 68 } accept
fib saddr . iif oif missing drop
}
chain input {
type filter hook input priority filter; policy drop;
ct state vmap { established : accept, related : accept, invalid : drop }
iifname "lo" accept
meta l4proto ipv6-icmp accept
ip6 saddr fe80::/10 udp dport 546 accept
icmp type echo-request accept
tcp dport { 22, 80, 443 } accept
udp dport { 443 } accept
}
}

In order, the input chain accepts replies to connections the machine made, everything on loopback, your trusted interfaces, all ICMPv6, which IPv6 needs to work at all, DHCPv6 replies from link-local addresses, ping unless allow_ping = false, your ports, and finally your extra rules. Everything else is dropped.

The rpfilter chain checks reverse paths: a packet whose source address wouldn’t be routed back out the interface it arrived on is dropped, which stops spoofed traffic. DHCPv4 is let through it, since a client asking for an address has none yet. check_reverse_path = "loose" only requires a route back out of any interface, and "off" leaves the chain out.

When you change the firewall options, the next switch rewrites /etc/nftables-archix.conf and reloads archix-firewall.service on the running system, which loads the new rules at once. Setting enable = false, or removing the options, disables the service and stops it, which deletes the archix table.

lua/hosts/desktop/init.lua
return {
firewall = {
enable = true,
allowed_tcp_ports = { 22 },
allowed_udp_port_ranges = { { from = 60000, to = 61000 } },
trusted_interfaces = { "tailscale0" },
check_reverse_path = "loose",
},
}

Everything arriving on tailscale0 is accepted, so your tailnet reaches every service while the internet only reaches SSH and mosh’s UDP range:

iifname { "tailscale0" } accept
tcp dport { 22 } accept
udp dport { 60000-61000 } accept

VPNs that route asymmetrically, such as Tailscale with an exit node or subnet routes, need check_reverse_path = "loose"; with "strict", their replies can look spoofed. Ports have to be 1 to 65535, and a range needs from no greater than to; otherwise diff and switch stop with firewall ports must be 1-65535, not 70000 or firewall port ranges need from <= to, both 1-65535.

For anything the options don’t cover, write nftables rules. extra_input_rules are added to the end of the input chain, after everything above:

lua/hosts/server/init.lua
return {
firewall = {
enable = true,
allowed_tcp_ports = { 22 },
extra_input_rules = [[
ip saddr 192.168.1.0/24 tcp dport 8080 accept
ip6 saddr fd00::/8 tcp dport 8080 accept
]],
extra_rules = [[
set blocked {
type ipv4_addr; flags interval;
elements = { 203.0.113.0/24 }
}
chain blocklist {
type filter hook input priority filter - 10; policy accept;
ip saddr @blocked drop
}
]],
},
}

Here port 8080 is open to the local network only. extra_rules adds more sets and chains inside the archix table; this blocklist chain runs before the input chain, so the blocked range is dropped even on port 22. Before every switch, including one that turns out to have nothing to do, archix checks the whole ruleset with nft -c -f, so a typo stops it with nothing changed, followed by nft’s own error:

Terminal window
error: the firewall rules don't load (check extra_input_rules and extra_rules); nothing was changed:

That needs nft on the running system, so the very first switch that turns the firewall on, before nftables is installed, can’t check. A bad rule then makes the service fail to load the file at boot, and the machine starts without the archix table; fix it and switch again, and from then on it’s checked first. A rollback doesn’t check again: the generation’s rules already passed when you switched to it.

Docker, Tailscale, libvirt and others manage their own nftables tables. archix never touches them: it doesn’t use nftables.service, whose stop flushes every table on the machine, and its own service only ever deletes the archix table.

Each table’s input chain still applies to every packet, though, so a packet another table accepts can still be dropped by archix’s. Docker’s published ports are forwarded to containers rather than delivered to the host’s input chain, so they keep working; a service on the host itself needs its port in allowed_tcp_ports. If nftables.service is also enabled, the rules in /etc/nftables.conf apply too, and Arch’s default file drops everything but SSH. Every switch with the firewall on says so, including one with nothing to do:

Terminal window
warning: nftables.service is enabled too, so /etc/nftables.conf (on Arch: drop everything but SSH) still applies on top of the archix firewall; set services["nftables.service"] = false

Setting it in your config disables and stops nftables.service at the next switch, and the warning goes away:

services = { ["nftables.service"] = false },