From b98ad8de37f5c0d5438afd4f894ebf6d1df625ab Mon Sep 17 00:00:00 2001 From: Tethys Svensson Date: Tue, 7 Jul 2020 15:01:49 +0200 Subject: busybox: Add a default udhcpc dispatcher script The udhcpc binary which currently ships as part of the busybox derivation will by default search for a dispatcher script at the location /usr/share/udhcpc/default.script. This commit includes a working default script with udhcpc and updates the location where udhcpc searches for this script. The script was taken the script from the udhcpc package in debian buster. The only changes from that script is to make it use paths from the nix store and remove the run-time check for /sbin/resolvconf. --- pkgs/os-specific/linux/busybox/default.nix | 9 ++++ pkgs/os-specific/linux/busybox/default.script | 66 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100755 pkgs/os-specific/linux/busybox/default.script (limited to 'pkgs/os-specific/linux/busybox') diff --git a/pkgs/os-specific/linux/busybox/default.nix b/pkgs/os-specific/linux/busybox/default.nix index 430066831b8..a63ea958b61 100644 --- a/pkgs/os-specific/linux/busybox/default.nix +++ b/pkgs/os-specific/linux/busybox/default.nix @@ -80,6 +80,9 @@ stdenv.mkDerivation rec { # Bump from 4KB, much faster I/O CONFIG_FEATURE_COPYBUF_KB 64 + # Set the path for the udhcpc script + CONFIG_UDHCPC_DEFAULT_SCRIPT "$out/share/default.script" + ${extraConfig} CONFIG_CROSS_COMPILER_PREFIX "${stdenv.cc.targetPrefix}" ${libcConfig} @@ -94,6 +97,12 @@ stdenv.mkDerivation rec { makeFlagsArray+=("CC=${stdenv.cc.targetPrefix}cc -isystem ${musl.dev}/include -B${musl}/lib -L${musl}/lib") ''; + postInstall = '' + mkdir $out/share + substituteAll ${./default.script} $out/share/default.script + chmod +x $out/share/default.script + ''; + depsBuildBuild = [ buildPackages.stdenv.cc ]; buildInputs = lib.optionals (enableStatic && !useMusl && stdenv.cc.libc ? static) [ stdenv.cc.libc stdenv.cc.libc.static ]; diff --git a/pkgs/os-specific/linux/busybox/default.script b/pkgs/os-specific/linux/busybox/default.script new file mode 100755 index 00000000000..298616e6527 --- /dev/null +++ b/pkgs/os-specific/linux/busybox/default.script @@ -0,0 +1,66 @@ +#!@bash@/bin/sh +# Busybox udhcpc dispatcher script. +# Copyright (C) 2009 by Axel Beckert. +# Copyright (C) 2014 by Michael Tokarev. +# +# Based on the busybox example scripts and the old udhcp source +# package default.* scripts. + +RESOLV_CONF="/etc/resolv.conf" + +log() { + @out@/bin/logger -t "udhcpc[$PPID]" -p daemon.$1 "$interface: $2" +} + +case $1 in + bound|renew) + + # Configure new IP address. + # Do it unconditionally even if the address hasn't changed, + # to also set subnet, broadcast, mtu, ... + @out@/bin/ifconfig $interface ${mtu:+mtu $mtu} \ + $ip netmask $subnet ${broadcast:+broadcast $broadcast} + + # get current ("old") routes (after setting new IP) + crouter=$(@out@/bin/ip -4 route show dev $interface | + @out@/bin/awk '$1 == "default" { print $3; }') + router="${router%% *}" # linux kernel supports only one (default) route + if [ ".$router" != ".$crouter" ]; then + # reset just default routes + @out@/bin/ip -4 route flush exact 0.0.0.0/0 dev $interface + fi + if [ -n "$router" ]; then + # special case for /32 subnets: use onlink keyword + [ ".$subnet" = .255.255.255.255 ] \ + && onlink=onlink || onlink= + @out@/bin/ip -4 route add default via $router dev $interface $onlink + fi + + # Update resolver configuration file + [ -n "$domain" ] && R="domain $domain" || R="" + for i in $dns; do + R="$R +nameserver $i" + done + + echo "$R" > "$RESOLV_CONF" + + log info "$1: IP=$ip/$subnet router=$router domain=\"$domain\" dns=\"$dns\" lease=$lease" + ;; + + deconfig) + @out@/bin/ip link set $interface up + @out@/bin/ip -4 addr flush dev $interface + @out@/bin/ip -4 route flush dev $interface + log notice "deconfigured" + ;; + + leasefail | nak) + log err "configuration failed: $1: $message" + ;; + + *) + echo "$0: Unknown udhcpc command: $1" >&2 + exit 1 + ;; +esac -- cgit 1.4.1 From 179b74c2167fee8cbd70977dc746179db735ac41 Mon Sep 17 00:00:00 2001 From: Tethys Svensson Date: Tue, 28 Jul 2020 22:59:51 +0200 Subject: maintainers: add TethysSvensson --- maintainers/maintainer-list.nix | 6 ++++++ pkgs/os-specific/linux/busybox/default.nix | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'pkgs/os-specific/linux/busybox') diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 726478fc747..e2a89e176e2 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -7868,6 +7868,12 @@ githubId = 26417242; name = "Mikolaj Galkowski"; }; + TethysSvensson = { + email = "freaken@freaken.dk"; + github = "TethysSvensson"; + githubId = 4294434; + name = "Tethys Svensson"; + }; teto = { email = "mcoudron@hotmail.com"; github = "teto"; diff --git a/pkgs/os-specific/linux/busybox/default.nix b/pkgs/os-specific/linux/busybox/default.nix index a63ea958b61..67d5ab18e2f 100644 --- a/pkgs/os-specific/linux/busybox/default.nix +++ b/pkgs/os-specific/linux/busybox/default.nix @@ -115,7 +115,7 @@ stdenv.mkDerivation rec { description = "Tiny versions of common UNIX utilities in a single small executable"; homepage = "https://busybox.net/"; license = licenses.gpl2; - maintainers = with maintainers; [ ]; + maintainers = with maintainers; [ TethysSvensson ]; platforms = platforms.linux; priority = 10; }; -- cgit 1.4.1 From dcc963bd2d13a02b1f86d811a1835748aec49cbd Mon Sep 17 00:00:00 2001 From: Tethys Svensson Date: Wed, 29 Jul 2020 00:24:19 +0200 Subject: busybox: Download and patch the dispatcher script from upstream --- pkgs/os-specific/linux/busybox/default.nix | 19 ++++++-- pkgs/os-specific/linux/busybox/default.script | 66 --------------------------- 2 files changed, 15 insertions(+), 70 deletions(-) delete mode 100755 pkgs/os-specific/linux/busybox/default.script (limited to 'pkgs/os-specific/linux/busybox') diff --git a/pkgs/os-specific/linux/busybox/default.nix b/pkgs/os-specific/linux/busybox/default.nix index 67d5ab18e2f..f1b008b2103 100644 --- a/pkgs/os-specific/linux/busybox/default.nix +++ b/pkgs/os-specific/linux/busybox/default.nix @@ -31,6 +31,14 @@ let CONFIG_FEATURE_UTMP n CONFIG_FEATURE_WTMP n ''; + + debianName = "busybox_1.30.1-5"; + debianTarball = fetchTarball { + url = "http://deb.debian.org/debian/pool/main/b/busybox/${debianName}.debian.tar.xz"; + sha256 = "03m4rvs2pd0hj0mdkdm3r4m1gh0bgwr0cvnqds297xnkfi5s01nx"; + }; + debianDispatcherScript = "${debianTarball}/tree/udhcpc/etc/udhcpc/default.script"; + outDispatchPath = "$out/default.script"; in stdenv.mkDerivation rec { @@ -81,7 +89,7 @@ stdenv.mkDerivation rec { CONFIG_FEATURE_COPYBUF_KB 64 # Set the path for the udhcpc script - CONFIG_UDHCPC_DEFAULT_SCRIPT "$out/share/default.script" + CONFIG_UDHCPC_DEFAULT_SCRIPT "${outDispatchPath}" ${extraConfig} CONFIG_CROSS_COMPILER_PREFIX "${stdenv.cc.targetPrefix}" @@ -98,9 +106,12 @@ stdenv.mkDerivation rec { ''; postInstall = '' - mkdir $out/share - substituteAll ${./default.script} $out/share/default.script - chmod +x $out/share/default.script + sed -e ' + 1 a busybox() { '$out'/bin/busybox "$@"; }\ + logger() { '$out'/bin/logger "$@"; }\ + ' ${debianDispatcherScript} > ${outDispatchPath} + chmod 555 ${outDispatchPath} + PATH=$out/bin patchShebangs ${outDispatchPath} ''; depsBuildBuild = [ buildPackages.stdenv.cc ]; diff --git a/pkgs/os-specific/linux/busybox/default.script b/pkgs/os-specific/linux/busybox/default.script deleted file mode 100755 index 298616e6527..00000000000 --- a/pkgs/os-specific/linux/busybox/default.script +++ /dev/null @@ -1,66 +0,0 @@ -#!@bash@/bin/sh -# Busybox udhcpc dispatcher script. -# Copyright (C) 2009 by Axel Beckert. -# Copyright (C) 2014 by Michael Tokarev. -# -# Based on the busybox example scripts and the old udhcp source -# package default.* scripts. - -RESOLV_CONF="/etc/resolv.conf" - -log() { - @out@/bin/logger -t "udhcpc[$PPID]" -p daemon.$1 "$interface: $2" -} - -case $1 in - bound|renew) - - # Configure new IP address. - # Do it unconditionally even if the address hasn't changed, - # to also set subnet, broadcast, mtu, ... - @out@/bin/ifconfig $interface ${mtu:+mtu $mtu} \ - $ip netmask $subnet ${broadcast:+broadcast $broadcast} - - # get current ("old") routes (after setting new IP) - crouter=$(@out@/bin/ip -4 route show dev $interface | - @out@/bin/awk '$1 == "default" { print $3; }') - router="${router%% *}" # linux kernel supports only one (default) route - if [ ".$router" != ".$crouter" ]; then - # reset just default routes - @out@/bin/ip -4 route flush exact 0.0.0.0/0 dev $interface - fi - if [ -n "$router" ]; then - # special case for /32 subnets: use onlink keyword - [ ".$subnet" = .255.255.255.255 ] \ - && onlink=onlink || onlink= - @out@/bin/ip -4 route add default via $router dev $interface $onlink - fi - - # Update resolver configuration file - [ -n "$domain" ] && R="domain $domain" || R="" - for i in $dns; do - R="$R -nameserver $i" - done - - echo "$R" > "$RESOLV_CONF" - - log info "$1: IP=$ip/$subnet router=$router domain=\"$domain\" dns=\"$dns\" lease=$lease" - ;; - - deconfig) - @out@/bin/ip link set $interface up - @out@/bin/ip -4 addr flush dev $interface - @out@/bin/ip -4 route flush dev $interface - log notice "deconfigured" - ;; - - leasefail | nak) - log err "configuration failed: $1: $message" - ;; - - *) - echo "$0: Unknown udhcpc command: $1" >&2 - exit 1 - ;; -esac -- cgit 1.4.1 From b657c899d6fd5a09c3619302a20b63683a66f0f2 Mon Sep 17 00:00:00 2001 From: Tethys Svensson Date: Wed, 29 Jul 2020 10:33:58 +0200 Subject: busybox: Use fetchzip instead of fetchTarball to get the dispatcher script --- pkgs/os-specific/linux/busybox/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkgs/os-specific/linux/busybox') diff --git a/pkgs/os-specific/linux/busybox/default.nix b/pkgs/os-specific/linux/busybox/default.nix index f1b008b2103..60b4a582d52 100644 --- a/pkgs/os-specific/linux/busybox/default.nix +++ b/pkgs/os-specific/linux/busybox/default.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, buildPackages, fetchurl +{ stdenv, lib, buildPackages, fetchurl, fetchzip , enableStatic ? false , enableMinimal ? false # Allow forcing musl without switching stdenv itself, e.g. for our bootstrapping: @@ -33,7 +33,7 @@ let ''; debianName = "busybox_1.30.1-5"; - debianTarball = fetchTarball { + debianTarball = fetchzip { url = "http://deb.debian.org/debian/pool/main/b/busybox/${debianName}.debian.tar.xz"; sha256 = "03m4rvs2pd0hj0mdkdm3r4m1gh0bgwr0cvnqds297xnkfi5s01nx"; }; -- cgit 1.4.1