mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-12-15 19:23:01 +03:00
f40c8c1f08
types.string having been formally deprecated, and having a likely unwanted behaviour.
71 lines
1.6 KiB
Nix
71 lines
1.6 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
with import ./initrd-order.nix;
|
|
|
|
let
|
|
cfg = config.mobile.boot.stage-1.networking;
|
|
IP = cfg.IP;
|
|
hostIP = cfg.hostIP;
|
|
in
|
|
{
|
|
# FIXME : this is probably incomplete.
|
|
options.mobile.boot.stage-1.networking = {
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Enables networking.
|
|
'';
|
|
};
|
|
IP = mkOption {
|
|
type = types.str;
|
|
default = "172.16.42.1";
|
|
description = ''
|
|
IP address for the USB networking gadget.
|
|
'';
|
|
};
|
|
hostIP = mkOption {
|
|
type = types.str;
|
|
default = "172.16.42.2";
|
|
description = ''
|
|
IP address for the USB networking gadget.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config.mobile.boot.stage-1 = lib.mkIf cfg.enable {
|
|
init = lib.mkOrder NETWORK_INIT ''
|
|
start_udhcpd() {
|
|
# Only run once
|
|
[ -e /etc/udhcpd.conf ] && return
|
|
|
|
# Get usb interface
|
|
INTERFACE=""
|
|
ifconfig rndis0 "${IP}" && INTERFACE=rndis0
|
|
if [ -z $INTERFACE ]; then
|
|
ifconfig usb0 "${IP}" && INTERFACE=usb0
|
|
fi
|
|
if [ -z $INTERFACE ]; then
|
|
ifconfig eth0 "${IP}" && INTERFACE=eth0
|
|
fi
|
|
# Create /etc/udhcpd.conf
|
|
{
|
|
echo "start ${hostIP}"
|
|
echo "end ${hostIP}"
|
|
echo "auto_time 0"
|
|
echo "decline_time 0"
|
|
echo "conflict_time 0"
|
|
echo "lease_file /var/udhcpd.leases"
|
|
echo "interface $INTERFACE"
|
|
echo "option subnet 255.255.255.0"
|
|
} >/etc/udhcpd.conf
|
|
echo "Start the dhcpcd daemon (forks into background)"
|
|
udhcpd
|
|
}
|
|
|
|
start_udhcpd
|
|
'';
|
|
};
|
|
}
|