commit 225fc6fe51940da23103d4136e490913953d3994
parent 8b2fcb5336ea8ef99582a7615a348b496d5c5f7e
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 10 Mar 2023 18:40:45 +0000
configurable busybox
allows modules to add to the busybox applets and change config
Diffstat:
10 files changed, 101 insertions(+), 20 deletions(-)
diff --git a/default.nix b/default.nix
@@ -22,6 +22,7 @@ let
{ _module.args = { inherit pkgs; lib = pkgs.lib; }; }
./modules/hardware.nix
./modules/base.nix
+ ./modules/busybox.nix
./modules/hostname.nix
device.module
liminix-config
diff --git a/modules/base.nix b/modules/base.nix
@@ -2,7 +2,7 @@
let
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr ;
inherit (pkgs.pseudofile) dir symlink;
- inherit (pkgs) busybox;
+# inherit (pkgs) busybox;
inherit (pkgs.liminix.networking) address interface;
inherit (pkgs.liminix.services) bundle;
@@ -46,7 +46,7 @@ in {
};
config = {
defaultProfile.packages = with pkgs;
- [ s6 s6-init-bin busybox execline s6-linux-init s6-rc ];
+ [ s6 s6-init-bin execline s6-linux-init s6-rc ];
hardware.networkInterfaces = {
lo =
@@ -113,10 +113,6 @@ in {
};
filesystem = dir {
- bin = dir {
- sh = symlink "${busybox}/bin/sh";
- busybox = symlink "${busybox}/bin/busybox";
- };
dev =
let node = type: major: minor: mode : { inherit type major minor mode; };
in dir {
@@ -129,7 +125,7 @@ in {
etc = dir {
profile = symlink
(pkgs.writeScript ".profile" ''
- PATH=${lib.makeBinPath config.defaultProfile.packages}
+ PATH=${lib.makeBinPath config.defaultProfile.packages}:/bin
export PATH
'');
};
diff --git a/modules/busybox.nix b/modules/busybox.nix
@@ -0,0 +1,85 @@
+{ lib, pkgs, config, ...}:
+let
+ inherit (lib) mkOption mkEnableOption types mapAttrsToList;
+ inherit (pkgs.pseudofile) dir symlink;
+ inherit (lib.strings) toUpper;
+
+ attrs = { options, applets } :
+ let
+ extraOptions = builtins.concatStringsSep "\n"
+ (mapAttrsToList (n: v: "CONFIG_${toUpper n} ${toString v}") options);
+ appletOptions = builtins.concatStringsSep "\n"
+ (map (n: "CONFIG_${toUpper n} y") applets);
+ in {
+ enableMinimal = true;
+ extraConfig = ''
+ ${extraOptions}
+ ${appletOptions}
+ '';
+ };
+ cfg = config.programs.busybox;
+ busybox = pkgs.busybox.override (attrs { inherit (cfg) applets options; });
+ makeLinks = lib.attrsets.genAttrs
+ cfg.applets
+ (a: symlink "${busybox}/bin/busybox");
+ minimalApplets = [
+ # this is probably less minimal than it could be "arch" "ash"
+ "base64" "basename" "bc" "brctl" "bunzip2"
+ "bzcat" "bzip2" "cal" "cat" "chattr" "chgrp" "chmod" "chown"
+ "chpst" "chroot" "clear" "cmp" "comm" "cp" "cpio" "cut" "date"
+ "dd" "df" "dirname" "dmesg" "du" "echo" "egrep" "env" "expand"
+ "expr" "false" "fdisk" "fgrep" "find" "free" "fuser" "grep"
+ "gunzip" "gzip" "head" "hexdump" "hostname" "hwclock" "ifconfig"
+ "ip" "iplink" "ipneigh" "iproute" "iprule" "kill" "killall"
+ "killall5" "less" "ln" "ls" "lsattr" "lsof" "md5sum" "mkdir"
+ "mknod" "mktemp" "mount" "mv" "nc" "netstat" "nohup" "od" "pgrep"
+ "pidof" "ping" "ping6" "pkill" "pmap" "printenv" "printf" "ps"
+ "pwd" "readlink" "realpath" "reset" "rm" "rmdir" "route" "sed"
+ "seq" "setsid" "sha1sum" "sha256sum" "sha512sum" "sleep" "sort"
+ "stat" "strings" "stty" "su" "sum" "swapoff" "swapon" "sync"
+ "tail" "tee" "test" "time" "touch" "tr" "traceroute"
+ "traceroute6" "true" "truncate" "tty" "udhcpc" "udhcpc6" "umount"
+ "uname" "unexpand" "uniq" "unlink" "unlzma" "unxz" "unzip"
+ "uptime" "watch" "wc" "whoami" "xargs" "xxd" "xz" "xzcat" "yes"
+ "zcat"
+ ];
+in {
+ options = {
+ programs.busybox = {
+ applets = mkOption {
+ type = types.listOf types.str;
+ default = [];
+ example = ["sh" "getty" "login"];
+ };
+ options = mkOption {
+ # mostly the values are y n or m, but sometimes
+ # other strings are also used
+ type = types.attrsOf types.nonEmptyStr;
+ default = { };
+ };
+ };
+ };
+ config = {
+ programs.busybox = {
+ applets = minimalApplets;
+ options = {
+ ASH_ECHO = "y";
+ # ASH_OPTIMIZE_FOR_SIZE = "y";
+ BASH_IS_NONE = "y";
+ SH_IS_ASH = "y";
+ ASH_BASH_COMPAT = "y";
+ FEATURE_EDITING = "y"; # readline-ish command editing
+ FEATURE_EDITING_HISTORY = "128";
+ FEATURE_EDITING_MAX_LEN = "1024";
+ FEATURE_TAB_COMPLETION = "y";
+ FEATURE_EDITING_WINCH = "y";
+ };
+ };
+ filesystem = dir {
+ bin = dir ({
+ busybox = symlink "${busybox}/bin/busybox";
+ sh = symlink "${busybox}/bin/busybox";
+ } // makeLinks);
+ };
+ };
+}
diff --git a/modules/s6/default.nix b/modules/s6/default.nix
@@ -73,7 +73,7 @@ let
run = {
file = ''
#!${execline}/bin/execlineb -P
- ${busybox}/bin/getty -l ${busybox}/bin/login 115200 /dev/console
+ /bin/getty -l /bin/login 115200 /dev/console
'';
mode = "0755";
};
@@ -134,6 +134,7 @@ let
};
in {
config = {
+ programs.busybox.applets = [ "login" "getty" ];
filesystem = dir {
etc = dir {
s6-rc = dir {
diff --git a/modules/wlan.nix b/modules/wlan.nix
@@ -2,7 +2,7 @@
let
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr ;
inherit (pkgs.pseudofile) dir symlink;
- inherit (pkgs) stdenv busybox wireless-regdb;
+ inherit (pkgs) stdenv wireless-regdb;
regulatory = stdenv.mkDerivation {
name = "regulatory.db";
phases = ["installPhase"];
@@ -20,6 +20,9 @@ in {
};
};
};
+ programs.busybox.applets = [
+ "insmod" "rmmod"
+ ];
kernel = rec {
config = {
# Most of this is necessary infra to allow wireless stack/
diff --git a/pkgs/liminix-tools/networking/pppoe.nix b/pkgs/liminix-tools/networking/pppoe.nix
@@ -1,7 +1,6 @@
{
liminix
, lib
-, busybox
, ppp
, pppoe
, writeAshScript
diff --git a/pkgs/liminix-tools/networking/udhcpc.nix b/pkgs/liminix-tools/networking/udhcpc.nix
@@ -1,6 +1,5 @@
{
liminix
-, busybox
, writeAshScript
, serviceFns
} :
@@ -43,7 +42,7 @@ let
'';
in longrun {
inherit name;
- run = "${busybox}/bin/udhcpc -f -i ${interface.device} -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}";
+ run = "/bin/udhcpc -f -i ${interface.device} -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}";
notification-fd = 10;
dependencies = [ interface ] ++ dependencies;
}
diff --git a/pkgs/liminix-tools/services/default.nix b/pkgs/liminix-tools/services/default.nix
@@ -3,7 +3,6 @@
, s6-rc
, s6
, lib
-, busybox
, callPackage
, writeScript
, serviceFns
@@ -12,7 +11,7 @@ let
inherit (builtins) concatStringsSep;
output = service: name: "/run/service-state/${service.name}/${name}";
serviceScript = commands : ''
- #!${busybox}/bin/sh
+ #!/bin/sh
exec 2>&1
. ${serviceFns}
${commands}
diff --git a/pkgs/s6-init-bin/default.nix b/pkgs/s6-init-bin/default.nix
@@ -4,7 +4,6 @@
, writeScript
, stdenvNoCC
, lib
-, busybox
, s6-rc
}:
let
@@ -14,7 +13,7 @@ let
'';
init = writeScript "init" ''
#!${execline}/bin/execlineb -S0
- ${s6-linux-init}/bin/s6-linux-init -c /etc/s6-linux-init/current -m 0022 -p ${lib.makeBinPath [busybox execline s6-linux-init s6-rc]}:/usr/bin:/bin -d /dev -- "\$@"
+ ${s6-linux-init}/bin/s6-linux-init -c /etc/s6-linux-init/current -m 0022 -p ${lib.makeBinPath [execline s6-linux-init s6-rc]}:/usr/bin:/bin -d /dev -- "\$@"
'';
in stdenvNoCC.mkDerivation {
name = "s6-init-bin";
diff --git a/pkgs/write-ash-script/default.nix b/pkgs/write-ash-script/default.nix
@@ -1,14 +1,13 @@
{
- busybox
-, writeScript
+ writeScript
, lib
}
: name : { runtimeInputs ? [] } : text : writeScript name ''
-#!${busybox}/bin/sh
+#!/bin/sh
set -o errexit
set -o nounset
set -o pipefail
-export PATH="${lib.makeBinPath ([ busybox ] ++ runtimeInputs)}:$PATH"
+export PATH="${lib.makeBinPath runtimeInputs}:$PATH"
${text}
''