Compare commits

...

35 commits
usteer ... main

Author SHA1 Message Date
b11e752c02
fix: added missing imports 2024-09-18 15:03:59 +02:00
876909959c
fix: added toplevel configuration 2024-09-18 13:13:52 +02:00
Raito Bezarius
013e4c396c feat: repair CI and cleanup cross-compilation mechanism
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-16 18:14:39 +02:00
Raito Bezarius
036f91d2f0 feat(ubus): support for Lua 5.3
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-08 01:08:59 +02:00
Raito Bezarius
54db2ad006 feat(libubox): support for Lua 5.3
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-08 01:08:54 +02:00
Raito Bezarius
8ac3e32b8b fix(modules/hostname): hash the hostname to avoid duplicate services in the db
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-08 00:31:15 +02:00
Raito Bezarius
6970d811e8 chore(min-copy-closure): improve liminix-rebuild for maintenance
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 23:59:29 +02:00
Raito Bezarius
b468275f53 fix(tftpboot): revert squashfs use and go back to JFFS2
squashfs doesn't copy all the files we need.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 23:48:13 +02:00
Raito Bezarius
3ed1564235 feat(recovery): bump to 20MB the TFTP phram size
Otherwise, this will fail to boot on a modern closure.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 23:39:22 +02:00
Raito Bezarius
9fcfae3eae feat(recovery): strengthen debugging capabilities of preinit
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 23:30:05 +02:00
Raito Bezarius
73ea02b982 feat(modules/nixpkgs): introduce source parameter
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 23:05:03 +02:00
Raito Bezarius
c942b2be09 feat(initramfs): enable zstd compression
Busybox is still 3MB.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 22:49:25 +02:00
Raito Bezarius
95850a44c2 feat(recovery): implement failsafe boot
for TFTP or anything, really.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 22:49:25 +02:00
Raito Bezarius
bc1f54e701 Merge branch 'bridgeability' into 'main' 2024-09-07 21:53:20 +02:00
Raito Bezarius
0ee2ce4183 fix(overlay): adopt upstream fix for Lua readline
9f58e7b926
("maybe fix nixpkgs-unstable lua")

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 21:52:48 +02:00
Raito Bezarius
94a5b19c77 fix(evalConfig): fix pkgs relation with nixpkgs
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 21:52:48 +02:00
Raito Bezarius
13069415fd feat(modules/hostapd): offer readiness oneshot
WLAN oper wait until the WLAN interface is ready.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 21:15:31 +02:00
Raito Bezarius
5590fea16e feat(ifwait): add ifbridgeable script
This enable to wait for bridgeability of a WLAN interface via
`iwinfo`.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 21:09:17 +02:00
Raito Bezarius
c39bfc2bb5 fix(write-fennel): escape binary path for PATH
otherwise, escapeShellArg might just do nothing!

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 21:03:57 +02:00
Raito Bezarius
0c363be423 fennelrepl: add iwinfo to it
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 20:03:02 +02:00
Raito Bezarius
26d2812aa4 fennerepl: remove readline
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 20:03:02 +02:00
Raito Bezarius
b57df3f288 iwinfo: use Lua 5.3 port
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 20:03:02 +02:00
Raito Bezarius
4cf10c2e75 iwinfo: init at unstable-07-09-2024
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 19:26:14 +02:00
Raito Bezarius
0d36000d9f overlay: update hostapd with readiness support
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 18:31:57 +02:00
ce17fea337 Merge pull request 'feat(hostapd): ubus support' (#16) from hostapd-ubus into main
Reviewed-on: DGNum/liminix#16
2024-09-07 17:53:21 +02:00
Raito Bezarius
1a770910a6 fix(ubus): rendez vous URL for the unix socket
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 17:48:06 +02:00
Raito Bezarius
5444059b63 feat(hostapd): enable ubus on RADIUS variant
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 17:18:59 +02:00
Raito Bezarius
ffc6492365 fix(ubus): set the socket path properly
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 17:15:31 +02:00
Raito Bezarius
71813a1f8f feat(hostapd): disable openssl to save space
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 17:03:50 +02:00
Raito Bezarius
032e57b34c feat(hostapd): ubus support
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-07 15:56:53 +02:00
Raito Bezarius
0fb671023c feat(services): introduce structured bundles
Structured bundles keep their original contents as a `passthru` field
named `components`.

This enable users to depend on a specific piece of the bundle instead of
the whole bundle.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-05 14:54:12 +02:00
Raito Bezarius
ebcdbf76bc fix(bridge): members are now granular services
They are still part of the bundle, but we can wait on each of them
independently now.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-05 14:54:12 +02:00
Raito Bezarius
78d0088b65 ubus: build with Lua
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-04 16:30:44 +02:00
Raito Bezarius
6d4237ff87 libubox: build with Lua
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-04 16:29:59 +02:00
Raito Bezarius
c24c659ee1 modules/ubus: init
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-04 16:08:56 +02:00
34 changed files with 484 additions and 102 deletions

22
ci.nix
View file

@ -1,21 +1,15 @@
{ {
nixpkgs sources ? import ./lon.nix
, unstable , nixpkgs ? sources.nixpkgs
, liminix , unstable ? nixpkgs
, liminix ? ./.
, ... }: , ... }:
let let
inherit (builtins) map; pkgs = (import nixpkgs { });
pkgs = (import nixpkgs {});
borderVmConf = ./bordervm.conf-example.nix; borderVmConf = ./bordervm.conf-example.nix;
inherit (pkgs.lib.attrsets) genAttrs; inherit (pkgs.lib.attrsets) genAttrs;
devices = [ devices = [
"gl-ar750"
"gl-mt300a"
"gl-mt300n-v2"
"qemu" "qemu"
"qemu-aarch64"
"qemu-armv7l"
"tp-archer-ax23"
"zyxel-nwa50ax" "zyxel-nwa50ax"
]; ];
vanilla = ./vanilla-configuration.nix; vanilla = ./vanilla-configuration.nix;
@ -44,12 +38,6 @@ let
imports = [ ./modules/all-modules.nix ]; imports = [ ./modules/all-modules.nix ];
}; };
}).outputs.optionsJson; }).outputs.optionsJson;
installers = map (f: "system.outputs.${f}") [
"vmroot"
"mtdimage"
"ubimage"
];
inherit (pkgs.lib) concatStringsSep;
in pkgs.stdenv.mkDerivation { in pkgs.stdenv.mkDerivation {
name = "liminix-doc"; name = "liminix-doc";
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [

View file

@ -1,7 +1,7 @@
# This "device" generates images that can be used with the QEMU # This "device" generates images that can be used with the QEMU
# emulator. The default output is a directory containing separate # emulator. The default output is a directory containing separate
# kernel (uncompressed vmlinux) and initrd (squashfs) images # kernel (uncompressed vmlinux) and initrd (squashfs) images
{ rec {
system = { system = {
crossSystem = { crossSystem = {
config = "mips-unknown-linux-musl"; config = "mips-unknown-linux-musl";
@ -41,6 +41,9 @@
../../modules/arch/mipseb.nix ../../modules/arch/mipseb.nix
../families/qemu.nix ../families/qemu.nix
]; ];
nixpkgs.hostPlatform = system.crossSystem;
kernel = { kernel = {
config = { config = {
MIPS_MALTA= "y"; MIPS_MALTA= "y";

View file

@ -1,4 +1,4 @@
{ rec {
system = { system = {
crossSystem = { crossSystem = {
config = "mipsel-unknown-linux-musl"; config = "mipsel-unknown-linux-musl";
@ -135,6 +135,8 @@
../../modules/zyxel-dual-image ../../modules/zyxel-dual-image
]; ];
nixpkgs.hostPlatform = system.crossSystem;
filesystem = dir { filesystem = dir {
lib = dir { lib = dir {
firmware = dir { firmware = dir {
@ -222,8 +224,8 @@
imageFormat = "fit"; imageFormat = "fit";
tftp = { tftp = {
# 5MB is nice. # 20MB is pretty good on this device as we have plenty of RAM.
freeSpaceBytes = 5 * 1024 * 1024; freeSpaceBytes = 20 * 1024 * 1024;
appendDTB = true; appendDTB = true;
loadAddress = lim.parseInt "0x2000000"; loadAddress = lim.parseInt "0x2000000";
}; };

View file

@ -1,4 +1,4 @@
{ nixpkgs ? <nixpkgs>, pkgs ? (import <nixpkgs> {}), lib ? pkgs.lib }: { nixpkgs ? <nixpkgs>, pkgs ? (import nixpkgs {}), lib ? pkgs.lib }:
args: args:
let let
modulesPath = builtins.toString ../modules; modulesPath = builtins.toString ../modules;

15
lon.lock Normal file
View file

@ -0,0 +1,15 @@
{
"version": "1",
"sources": {
"nixpkgs": {
"type": "GitHub",
"fetchType": "tarball",
"owner": "nixos",
"repo": "nixpkgs",
"branch": "nixos-unstable-small",
"revision": "b6227cadb5123c7e4cb159bf6f9f5705ae081a47",
"url": "https://github.com/nixos/nixpkgs/archive/b6227cadb5123c7e4cb159bf6f9f5705ae081a47.tar.gz",
"hash": "sha256-KFR30GNFhjzXl0kVEn+KK4xrFr0gggb1NBroP8ukbxY="
}
}
}

41
lon.nix Normal file
View file

@ -0,0 +1,41 @@
# Generated by lon. Do not modify!
let
lock = builtins.fromJSON (builtins.readFile ./lon.lock);
# Override with a path defined in an environment variable. If no variable is
# set, the original path is used.
overrideFromEnv =
name: path:
let
replacement = builtins.getEnv "LON_OVERRIDE_${name}";
in
if replacement == "" then
path
else
# this turns the string into an actual Nix path (for both absolute and
# relative paths)
if builtins.substring 0 1 replacement == "/" then
/. + replacement
else
/. + builtins.getEnv "PWD" + "/${replacement}";
fetchSource =
args@{ fetchType, ... }:
if fetchType == "git" then
builtins.fetchGit {
url = args.url;
ref = args.branch;
rev = args.revision;
narHash = args.hash;
}
else if fetchType == "tarball" then
builtins.fetchTarball {
url = args.url;
sha256 = args.hash;
}
else
builtins.throw "Unsupported source type ${fetchType}";
in
builtins.mapAttrs (name: args: overrideFromEnv name (fetchSource args)) lock.sources

View file

@ -69,6 +69,14 @@ in {
default = "uimage"; default = "uimage";
}; };
tftp = { tftp = {
commandLine = mkOption {
type = types.listOf types.str;
default = config.boot.commandLine;
description = ''
TFTP-specific command line.
Defaults to the classical one if unset.
'';
};
loadAddress = mkOption { loadAddress = mkOption {
type = types.ints.unsigned; type = types.ints.unsigned;
description = '' description = ''
@ -97,7 +105,13 @@ in {
}; };
}; };
}; };
imports = [ ./nixpkgs.nix ];
config = { config = {
# By default, we enable cross-compilation support.
nixpkgs.buildPlatform = lib.mkDefault builtins.currentSystem;
defaultProfile.packages = with pkgs; defaultProfile.packages = with pkgs;
[ s6 s6-init-bin execline s6-linux-init s6-rc ]; [ s6 s6-init-bin execline s6-linux-init s6-rc ];

View file

@ -43,8 +43,20 @@ in
}; };
members = mkOption { members = mkOption {
type = types.listOf liminix.lib.types.interface; type = types.attrsOf (types.submodule ({ ... }: { options = {
description = "interfaces to add to the bridge"; member = mkOption {
type = liminix.lib.types.interface;
description = "interface to add";
};
dependencies = mkOption {
type = types.listOf liminix.lib.types.service;
default = [];
description = "extra dependencies before attaching this interface to the bridge";
};
}; }));
description = "set of bridge members";
}; };
}; };

View file

@ -7,11 +7,10 @@
{ members, primary } : { members, primary } :
let let
inherit (liminix.networking) interface; inherit (liminix.services) structuredBundle oneshot;
inherit (liminix.services) bundle oneshot; inherit (lib) mapAttrs;
inherit (lib) mkOption types; addif = name: { dependencies ? [ ], member }: oneshot {
addif = member : oneshot { name = "${primary.name}.member.${name}";
name = "${primary.name}.member.${member.name}";
up = '' up = ''
echo "attaching $(output ${member} ifname) to $(output ${primary} ifname) bridge" echo "attaching $(output ${member} ifname) to $(output ${primary} ifname) bridge"
ip link set dev $(output ${member} ifname) master $(output ${primary} ifname) ip link set dev $(output ${member} ifname) master $(output ${primary} ifname)
@ -21,9 +20,9 @@ let
ip link set dev $(output ${member} ifname) nomaster ip link set dev $(output ${member} ifname) nomaster
''; '';
dependencies = [ primary member ]; dependencies = [ primary member ] ++ dependencies;
}; };
in bundle { in structuredBundle {
name = "${primary.name}.members"; name = "${primary.name}.members";
contents = map addif members; contents = mapAttrs addif members;
} }

View file

@ -20,6 +20,10 @@ in {
system.service.hostapd = mkOption { system.service.hostapd = mkOption {
type = liminix.lib.types.serviceDefn; type = liminix.lib.types.serviceDefn;
}; };
system.service.hostapd-ready = mkOption {
type = liminix.lib.types.serviceDefn;
};
}; };
config = { config = {
system.service.hostapd = liminix.callService ./service.nix { system.service.hostapd = liminix.callService ./service.nix {
@ -34,5 +38,12 @@ in {
type = types.attrs; type = types.attrs;
}; };
}; };
system.service.hostapd-ready = liminix.callService ./ready.nix {
interface = mkOption {
type = liminix.lib.types.interface;
description = "Interface for which to wait that the oper state Master or Master (VLAN) has been reached.";
};
};
}; };
} }

16
modules/hostapd/ready.nix Normal file
View file

@ -0,0 +1,16 @@
{
liminix
, ifwait
, lib
}:
{ interface } :
let
inherit (liminix.services) oneshot;
in oneshot {
name = "${interface.name}.wlan-oper";
up = ''
${ifwait}/bin/ifbridgeable -v $(output ${interface} ifname)
'';
dependencies = [ interface ];
}

View file

@ -15,7 +15,7 @@ in {
}; };
config = { config = {
services.hostname = oneshot { services.hostname = oneshot {
name = "hostname"; name = "hostname-${builtins.substring 0 12 (builtins.hashString "sha256" config.hostname)}";
up = "echo ${config.hostname} > /proc/sys/kernel/hostname"; up = "echo ${config.hostname} > /proc/sys/kernel/hostname";
down = "true"; down = "true";
}; };

View file

@ -83,11 +83,11 @@ let
localSystem = cfg.hostPlatform; localSystem = cfg.hostPlatform;
}; };
in in
import <nixpkgs> ({ import cfg.source ({
inherit (cfg) config overlays; inherit (cfg) config overlays;
} // systemArgs) } // systemArgs)
else else
import <nixpkgs> { import cfg.source {
inherit (cfg) config overlays localSystem crossSystem; inherit (cfg) config overlays localSystem crossSystem;
}; };
@ -97,6 +97,14 @@ in
{ {
options.nixpkgs = { options.nixpkgs = {
source = mkOption {
type = types.package // {
description = "Source of a nixpkgs repository";
};
default = <nixpkgs>;
defaultText = "<nixpkgs>";
};
pkgs = mkOption { pkgs = mkOption {
defaultText = literalExpression '' defaultText = literalExpression ''
@ -323,6 +331,8 @@ in
}; };
}; };
imports = [ ./misc/assertions.nix ];
config = { config = {
_module.args = { _module.args = {
pkgs = pkgs =

View file

@ -13,6 +13,14 @@ in
boot.initramfs = { boot.initramfs = {
enable = mkEnableOption "initramfs"; enable = mkEnableOption "initramfs";
}; };
system.build.toplevel = mkOption {
type = types.package;
description = ''
pkgs.systemconfig for the configured filesystem,
contains 'activate' and 'init' commands
'';
internal = true;
};
system.outputs = { system.outputs = {
initramfs = mkOption { initramfs = mkOption {
type = types.package; type = types.package;
@ -36,22 +44,45 @@ in
kernel.config = { kernel.config = {
BLK_DEV_INITRD = "y"; BLK_DEV_INITRD = "y";
INITRAMFS_SOURCE = builtins.toJSON "${config.system.outputs.initramfs}"; INITRAMFS_SOURCE = builtins.toJSON "${config.system.outputs.initramfs}";
# INITRAMFS_COMPRESSION_LZO = "y"; INITRAMFS_COMPRESSION_ZSTD = "y";
}; };
system.build.toplevel = config.system.outputs.systemConfiguration;
system.outputs = { system.outputs = {
initramfs = initramfs =
let inherit (pkgs.pkgsBuildBuild) gen_init_cpio; let
inherit (pkgs.pkgsBuildBuild) gen_init_cpio cpio writeScript;
inherit (pkgs) busybox;
failsafe-init = writeScript "init" ''
#!/bin/sh
exec >/dev/console
echo Running in initramfs
PATH=${busybox}/bin:$PATH
export PATH
mount -t proc none /proc
mount -t sysfs none /sys
${busybox}/bin/sh
'';
refs = pkgs.writeReferencesToFile busybox;
in runCommand "initramfs.cpio" {} '' in runCommand "initramfs.cpio" {} ''
cat << SPECIALS | ${gen_init_cpio}/bin/gen_init_cpio /dev/stdin > $out cat << SPECIALS | ${gen_init_cpio}/bin/gen_init_cpio /dev/stdin > out
dir /proc 0755 0 0 dir /proc 0755 0 0
dir /dev 0755 0 0 dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1 nod /dev/console 0600 0 0 c 5 1
dir /target 0755 0 0 dir /target 0755 0 0
dir /target/persist 0755 0 0 dir /target/persist 0755 0 0
dir /target/nix 0755 0 0 dir /target/nix 0755 0 0
dir /nix 0755 0 0
dir /nix/store 0755 0 0
dir /bin 0755 0 0
file /bin/sh ${busybox}/bin/sh 0755 0 0
file /init ${pkgs.preinit}/bin/preinit 0755 0 0 file /init ${pkgs.preinit}/bin/preinit 0755 0 0
file /failsafe-init ${failsafe-init} 0755 0 0
SPECIALS SPECIALS
find $(cat ${refs}) | ${cpio}/bin/cpio -H newc -o -A -v -O out
mv out $out
''; '';
systemConfiguration = systemConfiguration =
pkgs.systemconfig config.filesystem.contents; pkgs.systemconfig config.filesystem.contents;

View file

@ -12,10 +12,15 @@ let
arch = pkgs.stdenv.hostPlatform.linuxArch; arch = pkgs.stdenv.hostPlatform.linuxArch;
# UBI cannot run on the top of phram. # UBI cannot run on the top of phram.
needsSquashfs = config.rootfsType == "ubifs"; needsJffs2 = config.rootfsType == "ubifs";
rootfstype = if needsSquashfs then "squashfs" else config.rootfsType; # squashfs doesn't work out for us because only `bootablerootdir`
rootfs = if needsSquashfs then # contain what we need to boot, not `config.filesystem.contents` alas.
liminix.builders.squashfs config.filesystem.contents rootfstype = if needsJffs2 then "jffs2" else config.rootfsType;
rootfs = if needsJffs2 then
liminix.builders.jffs2 {
bootableRootDirectory = config.system.outputs.bootablerootdir;
inherit (config.hardware.flash) eraseBlockSize;
}
else config.system.outputs.rootfs; else config.system.outputs.rootfs;
in { in {
imports = [ ../ramdisk.nix ]; imports = [ ../ramdisk.nix ];
@ -36,14 +41,6 @@ in {
type = types.bool; type = types.bool;
default = false; default = false;
}; };
commandLine = mkOption {
type = types.listOf types.str;
default = config.boot.commandLine;
description = ''
TFTP-specific command line.
Defaults to the classical one if unset.
'';
};
}; };
options.system.outputs = { options.system.outputs = {
tftpboot = mkOption { tftpboot = mkOption {
@ -82,9 +79,13 @@ in {
config = { config = {
boot.ramdisk.enable = true; boot.ramdisk.enable = true;
kernel.config = mkIf needsSquashfs { kernel.config = mkIf needsJffs2 {
SQUASHFS = "y"; JFFS2_FS = "y";
SQUASHFS_XZ = "y"; JFFS2_LZO = "y";
JFFS2_RTIME = "y";
JFFS2_COMPRESSION_OPTIONS = "y";
JFFS2_ZLIB = "y";
JFFS2_CMODE_SIZE = "y";
}; };
system.outputs = rec { system.outputs = rec {

24
modules/ubus/default.nix Normal file
View file

@ -0,0 +1,24 @@
## ubus
## ====
##
## ubus is a micro-bus à la D-Bus for all your needs.
{ lib, pkgs, config, ...}:
let
inherit (lib) mkOption types;
inherit (pkgs) liminix;
in {
options = {
system.service.ubus = mkOption {
type = liminix.lib.types.serviceDefn;
};
};
config = {
system.service.ubus = liminix.callService ./service.nix {
package = mkOption {
type = types.package;
default = pkgs.ubus;
};
};
};
}

16
modules/ubus/service.nix Normal file
View file

@ -0,0 +1,16 @@
{
liminix
, writeText
, lib
}:
{ package } :
let
inherit (liminix.services) longrun;
in longrun {
# Long term: make it unique so that user can spawn multiple buses if they want.
name = "ubus";
run = ''
mkdir -p /run/ubus
${package}/bin/ubusd -s /run/ubus/ubus.sock
'';
}

View file

@ -1,23 +1,24 @@
final: prev: final: prev:
let let
isCross = final.stdenv.buildPlatform != final.stdenv.hostPlatform;
crossOnly = pkg : amendFn : if isCross then (amendFn pkg) else pkg;
extraPkgs = import ./pkgs/default.nix { extraPkgs = import ./pkgs/default.nix {
inherit (final) lib callPackage; inherit (final) lib callPackage;
}; };
inherit (final) fetchpatch; inherit (final) fetchpatch;
lua_no_readline = prev.lua5_3; luaHost = prev.lua5_3.overrideAttrs(o: {
# lua_no_readline = prev.lua5_3.overrideAttrs(o: { name = "lua-tty";
# name = "lua-tty"; preBuild = ''
# preBuild = '' makeFlagsArray+=(PLAT="posix" SYSLIBS="-Wl,-E -ldl" CFLAGS="-O2 -fPIC -DLUA_USE_POSIX -DLUA_USE_DLOPEN")
# makeFlagsArray+=(PLAT="posix" SYSLIBS="-Wl,-E -ldl" CFLAGS="-O2 -fPIC -DLUA_USE_POSIX -DLUA_USE_DLOPEN") '';
# ''; # lua in nixpkgs has a postInstall stanza that assumes only
# # lua in nixpkgs has a postInstall stanza that assumes only # one output, we need to override that if we're going to
# # one output, we need to override that if we're going to # convert to multi-output
# # convert to multi-output # outputs = ["bin" "man" "out"];
# # outputs = ["bin" "man" "out"]; makeFlags =
# makeFlags = builtins.filter (x: (builtins.match "(PLAT|MYLIBS).*" x) == null)
# builtins.filter (x: (builtins.match "(PLAT|MYLIBS).*" x) == null) o.makeFlags;
# o.makeFlags; });
# });
s6 = prev.s6.overrideAttrs(o: s6 = prev.s6.overrideAttrs(o:
let let
@ -42,7 +43,6 @@ let
(if o ? patches then o.patches else []) ++ (if o ? patches then o.patches else []) ++
(if patch_needed then [ patch ] else []); (if patch_needed then [ patch ] else []);
}); });
lua = let s = lua_no_readline.override { self = s; }; in s;
in in
extraPkgs // { extraPkgs // {
# liminix library functions # liminix library functions
@ -130,9 +130,18 @@ extraPkgs // {
"CONFIG_LIBNL32=y" "CONFIG_LIBNL32=y"
"CONFIG_PKCS12=y" "CONFIG_PKCS12=y"
"CONFIG_RSN_PREAUTH=y" "CONFIG_RSN_PREAUTH=y"
"CONFIG_UBUS=y"
"CONFIG_TLS=internal" "CONFIG_TLS=internal"
]; ];
h = prev.hostapd.overrideAttrs(o: { h = prev.hostapd.overrideAttrs(o: {
buildInputs = o.buildInputs ++ [ final.libubox final.ubus ];
src = final.fetchFromGitea {
domain = "git.dgnum.eu";
owner = "DGNum";
repo = "hostapd";
rev = "hostap-liminix-integration";
hash = "sha256-5Xi90keCHxvuKR5Q7STuZDzuM9h9ac6aWoXVQYvqkQI=";
};
extraConfig = ""; extraConfig = "";
configurePhase = '' configurePhase = ''
cat > hostapd/defconfig <<EOF cat > hostapd/defconfig <<EOF
@ -163,10 +172,18 @@ extraPkgs // {
"CONFIG_LIBNL32=y" "CONFIG_LIBNL32=y"
"CONFIG_PKCS12=y" "CONFIG_PKCS12=y"
"CONFIG_RSN_PREAUTH=y" "CONFIG_RSN_PREAUTH=y"
# Required to read the key material for RADIUS. "CONFIG_UBUS=y"
"CONFIG_TLS=openssl" "CONFIG_TLS=internal"
]; ];
h = prev.hostapd.overrideAttrs(o: { h = prev.hostapd.overrideAttrs(o: {
buildInputs = o.buildInputs ++ [ final.libubox final.ubus ];
src = final.fetchFromGitea {
domain = "git.dgnum.eu";
owner = "DGNum";
repo = "hostapd";
rev = "hostap-liminix-integration";
hash = "sha256-5Xi90keCHxvuKR5Q7STuZDzuM9h9ac6aWoXVQYvqkQI=";
};
extraConfig = ""; extraConfig = "";
configurePhase = '' configurePhase = ''
cat > hostapd/defconfig <<EOF cat > hostapd/defconfig <<EOF
@ -175,7 +192,7 @@ extraPkgs // {
${o.configurePhase} ${o.configurePhase}
''; '';
}); });
in h.override { sqlite = null; }; in h.override { openssl = null; sqlite = null; };
@ -197,8 +214,7 @@ extraPkgs // {
]; ];
}); });
luaFull = prev.lua; lua = crossOnly prev.lua5_3 (_: luaHost);
inherit lua;
mtdutils = prev.mtdutils.overrideAttrs(o: { mtdutils = prev.mtdutils.overrideAttrs(o: {
patches = (if o ? patches then o.patches else []) ++ [ patches = (if o ? patches then o.patches else []) ++ [

View file

@ -1,5 +1,5 @@
default: fs.lua init.lua nl.lua svc.lua net/constants.lua default: wlan.lua fs.lua init.lua nl.lua svc.lua net/constants.lua
test: test:
ln -s . anoia ln -s . anoia

View file

@ -4,6 +4,7 @@
, linotify , linotify
, lua , lua
, lualinux , lualinux
, iwinfo
, cpio , cpio
}: }:
let pname = "anoia"; let pname = "anoia";
@ -12,7 +13,7 @@ in stdenv.mkDerivation {
version = "0.1"; version = "0.1";
src = ./.; src = ./.;
nativeBuildInputs = [ fennel cpio ]; nativeBuildInputs = [ fennel cpio ];
buildInputs = with lua.pkgs; [ linotify lualinux ]; buildInputs = with lua.pkgs; [ linotify lualinux iwinfo ];
outputs = [ "out" "dev" ]; outputs = [ "out" "dev" ];
doCheck = true; doCheck = true;

8
pkgs/anoia/wlan.fnl Normal file
View file

@ -0,0 +1,8 @@
(local { : nl80211 } (require :iwinfo))
(fn is-bridgeable [ifname]
(let [mode (nl80211.mode ifname)]
(or (= mode "Master") (= mode "Master (VLAN)"))
))
{ : is-bridgeable }

View file

@ -112,6 +112,7 @@ in {
tufted = callPackage ./tufted {}; tufted = callPackage ./tufted {};
libubox = callPackage ./libubox {}; libubox = callPackage ./libubox {};
ubus = callPackage ./ubus {}; ubus = callPackage ./ubus {};
iwinfo = callPackage ./iwinfo {};
uevent-watch = callPackage ./uevent-watch {}; uevent-watch = callPackage ./uevent-watch {};
usb-modeswitch = callPackage ./usb-modeswitch {}; usb-modeswitch = callPackage ./usb-modeswitch {};
writeAshScript = callPackage ./write-ash-script {}; writeAshScript = callPackage ./write-ash-script {};

View file

@ -10,6 +10,7 @@
, linotify , linotify
, anoia , anoia
, netlink-lua , netlink-lua
, iwinfo
, fennel , fennel
}: }:
let packages = [ let packages = [
@ -18,7 +19,7 @@ let packages = [
fennel fennel
lualinux lualinux
netlink-lua netlink-lua
lua.pkgs.readline iwinfo
]; ];
join = ps: builtins.concatStringsSep ";" ps; join = ps: builtins.concatStringsSep ";" ps;
luapath = join (builtins.map (f: luapath = join (builtins.map (f:

View file

@ -1,11 +1,14 @@
{ {
lua lua
, netlink-lua , netlink-lua
, lualinux
, iwinfo
, writeFennelScript , writeFennelScript
, runCommand , runCommand
, anoia , anoia
}: }:
runCommand "ifwait" {} '' runCommand "ifwait" {} ''
mkdir -p $out/bin mkdir -p $out/bin
cp -p ${writeFennelScript "ifwait" [anoia netlink-lua] ./ifwait.fnl} $out/bin/ifwait cp -p ${writeFennelScript "ifwait" [ anoia netlink-lua ] ./ifwait.fnl} $out/bin/ifwait
cp -p ${writeFennelScript "ifbridgeable" [ anoia lualinux iwinfo ] ./ifbridgeable.fnl} $out/bin/ifbridgeable
'' ''

View file

@ -0,0 +1,30 @@
(local wlan (require :anoia.wlan))
(local { : assoc } (require :anoia))
(local { : msleep } (require :lualinux))
(fn parse-args [args]
(match args
["-v" & rest] (assoc (parse-args rest) :verbose true)
[linkname] {:link linkname}
_ nil))
(fn run [args poll-fn]
(let [parameters
(assert (parse-args args)
(.. "Usage: ifbridgeable [-v] ifname"))]
(when parameters.verbose
(print (.. "ifbridgeable: waiting for "
parameters.link " to be bridgeable")))
(while (not (poll-fn parameters.link))
(when parameters.verbose
(print (.. "ifbridgeable: waiting for " parameters.link " to be bridgeable")))
(msleep 500)
)
)
)
(when (not (= (. arg 0) "test"))
(run arg wlan.is-bridgeable))
{ : run }

59
pkgs/iwinfo/default.nix Normal file
View file

@ -0,0 +1,59 @@
{
lib,
stdenv,
fetchFromGitea,
ubus,
libubox,
lua5_3,
libnl-tiny,
backend ? "nl80211"
}:
let
lua = lua5_3;
in
stdenv.mkDerivation rec {
pname = "iwinfo";
version = "unstable-07-09-2024";
src = fetchFromGitea {
domain = "git.dgnum.eu";
owner = "DGNum";
repo = "iwinfo";
rev = "14685a26805155aa5c137993b9a4861a0bc585d5";
hash = "sha256-lg4sBoYcFFLhcUv+wKR6u1OCartjtnAoF9M5FdfO6JE=";
};
BACKENDS = backend;
buildInputs = [
ubus
libubox
lua
libnl-tiny
];
CFLAGS = "-I${libnl-tiny}/include/libnl-tiny -D_GNU_SOURCE";
installPhase = ''
runHook preInstall
install -Dm755 iwinfo $out/bin/iwinfo
install -Dm755 iwinfo.so $out/lib/lua/${lua.luaversion}/iwinfo.so
install -Dm755 libiwinfo.so $out/lib/libiwinfo.so
install -Dm755 libiwinfo.so.0 $out/lib/libiwinfo.so.0
mkdir -p $out/include
cp -r include/* $out/include
runHook postInstall
'';
meta = {
description = "Library to access wireless devices";
homepage = "https://github.com/openwrt/iwinfo";
license = lib.licenses.gpl2Only;
maintainers = with lib.maintainers; [ raitobezarius ];
mainProgram = "iwinfo";
platforms = lib.platforms.all;
};
}

View file

@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [buildPackages.stdenv.cc] ++ nativeBuildInputs = [buildPackages.stdenv.cc] ++
(with buildPackages.pkgs; [ (with buildPackages.pkgs; [
rsync bc bison flex pkg-config rsync bc bison flex pkg-config
openssl ncurses.all perl openssl ncurses.all perl zstd
]); ]);
CC = "${stdenv.cc.bintools.targetPrefix}gcc"; CC = "${stdenv.cc.bintools.targetPrefix}gcc";
HOSTCC = with buildPackages.pkgs; HOSTCC = with buildPackages.pkgs;

View file

@ -1,9 +1,9 @@
{ {
lib, lib,
stdenv, stdenv,
fetchgit, fetchFromGitea,
cmake, cmake,
lua5_1, lua,
json_c json_c
}: }:
@ -11,29 +11,32 @@ stdenv.mkDerivation rec {
pname = "libubox"; pname = "libubox";
version = "unstable-2024-04-09"; version = "unstable-2024-04-09";
src = fetchgit { src = fetchFromGitea {
url = "https://git.openwrt.org/project/libubox.git"; domain = "git.dgnum.eu";
rev = "eb9bcb64185ac155c02cc1a604692c4b00368324"; owner = "DGNum";
hash = "sha256-5KO2E+4pcDp/pe2+vjoQDmyMwCc0yKm847U4J6HjxyA="; repo = "libubox";
rev = "1c4b2dc4c12848e1b70b11e1cb2139ca8f19c860";
hash = "sha256-aPhGJ7viXQmnoQRY8DuRvtwtxSy+S4qPj1fBsK066Yc=";
}; };
nativeBuildInputs = [ nativeBuildInputs = [
cmake cmake
lua5_1 lua
]; ];
buildInputs = [ buildInputs = [
lua5_1 lua
json_c json_c
]; ];
# Otherwise, CMake cannot find jsoncpp? # Otherwise, CMake cannot find jsoncpp?
env.NIX_CFLAGS_COMPILE = toString [ "-I${json_c.dev}/include/json-c" "-D JSONC" ]; env.NIX_CFLAGS_COMPILE = toString [ "-I${json_c.dev}/include/json-c" "-D JSONC" "-D LUA_COMPAT_MODULE" ];
cmakeFlags = [ cmakeFlags = [
"-DBUILD_EXAMPLES=off" "-DBUILD_EXAMPLES=off"
# TODO: it explode at install phase. # TODO: it explode at install phase.
"-DBUILD_LUA=off" "-DBUILD_LUA=on"
"-DLUAPATH=${placeholder "out"}/lib/lua/${lua.luaversion}/"
]; ];
meta = { meta = {

View file

@ -39,6 +39,7 @@ let
, contents ? [] , contents ? []
, buildInputs ? [] , buildInputs ? []
, isTrigger ? false , isTrigger ? false
, passthru ? {}
} @ args: } @ args:
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation {
# we use stdenvNoCC to avoid generating derivations with names # we use stdenvNoCC to avoid generating derivations with names
@ -50,6 +51,8 @@ let
dependencies = builtins.map (d: d.name) dependencies; dependencies = builtins.map (d: d.name) dependencies;
contents = builtins.map (d: d.name) contents; contents = builtins.map (d: d.name) contents;
builder = ./builder.sh; builder = ./builder.sh;
inherit passthru;
}; };
longrun = { longrun = {
@ -100,7 +103,18 @@ let
serviceType = "bundle"; serviceType = "bundle";
inherit contents dependencies; inherit contents dependencies;
}); });
structuredBundle = {
name
, contents ? {}
, dependencies ? []
, ...
} @ args: service (args // {
serviceType = "bundle";
contents = builtins.attrValues contents;
inherit dependencies;
passthru.components = contents;
});
target = bundle; target = bundle;
in { in {
inherit target bundle oneshot longrun output; inherit target bundle oneshot longrun output structuredBundle;
} }

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -Eeuo pipefail
ssh_command=${SSH_COMMAND-ssh} ssh_command=${SSH_COMMAND-ssh}
@ -13,19 +14,24 @@ case "$1" in
reboot="soft" reboot="soft"
shift shift
;; ;;
"--root")
root_prefix="$2"
shift
shift
;;
esac esac
target_host=$1 target_host=$1
shift shift
if [ -z "$target_host" ] ; then if [ -z "$target_host" ] ; then
echo Usage: liminix-rebuild \[--no-reboot\] target-host params echo Usage: liminix-rebuild \[--no-reboot\] \[--fast\] target-host params
exit 1 exit 1
fi fi
if toplevel=$(nix-build "$@" -A outputs.systemConfiguration --no-out-link); then if toplevel=$(nix-build "$@" -A outputs.systemConfiguration --no-out-link); then
echo systemConfiguration $toplevel echo systemConfiguration $toplevel
min-copy-closure $target_host $toplevel min-copy-closure --root "$root_prefix" $target_host $toplevel
$ssh_command $target_host $toplevel/bin/install $ssh_command $target_host $toplevel/bin/install
case "$reboot" in case "$reboot" in
reboot) reboot)

View file

@ -4,9 +4,13 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/stat.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <dirent.h>
#include <asm/setup.h> /* for COMMAND_LINE_SIZE */ #include <asm/setup.h> /* for COMMAND_LINE_SIZE */
@ -44,6 +48,25 @@ static int fork_exec(char * command, char *args[])
return execve(command, args, NULL); return execve(command, args, NULL);
} }
static void debug_listdir(const char * path)
{
DIR *mydir;
struct dirent *myfile;
struct stat mystat;
char buf[512];
mydir = opendir(path);
while((myfile = readdir(mydir)) != NULL)
{
sprintf(buf, "%s/%s", path, myfile->d_name);
stat(buf, &mystat);
printf("%llu", mystat.st_size);
printf(" %s\n", myfile->d_name);
}
closedir(mydir);
}
char banner[] = "Running pre-init...\n"; char banner[] = "Running pre-init...\n";
char buf[COMMAND_LINE_SIZE]; char buf[COMMAND_LINE_SIZE];
@ -98,6 +121,7 @@ int main(int argc, char *argv[], char *envp[])
AVER(mount(opts.device, "/target/persist", opts.fstype, 0, opts.mount_opts)); AVER(mount(opts.device, "/target/persist", opts.fstype, 0, opts.mount_opts));
} else { } else {
if(mount(opts.device, "/target/persist", opts.fstype, 0, opts.mount_opts) < 0) { if(mount(opts.device, "/target/persist", opts.fstype, 0, opts.mount_opts) < 0) {
ERR("failed to mount primary device, mount the alternative device\n");
AVER(mount(opts.altdevice, "/target/persist", opts.fstype, 0, opts.mount_opts)); AVER(mount(opts.altdevice, "/target/persist", opts.fstype, 0, opts.mount_opts));
} }
} }
@ -107,7 +131,12 @@ int main(int argc, char *argv[], char *envp[])
"bind", MS_BIND, NULL)); "bind", MS_BIND, NULL));
char *exec_args[] = { "activate", "/target", NULL }; char *exec_args[] = { "activate", "/target", NULL };
AVER(fork_exec("/target/persist/activate", exec_args)); if (fork_exec("/target/persist/activate", exec_args) < 0) {
ERR("failed to activate the system\n");
pr_u32(errno); ERR ( " - "); ERR(strerror(errno)); ERR("\n");
goto failsafe;
}
AVER(chdir("/target")); AVER(chdir("/target"));
AVER(mount("/target", "/", "bind", MS_BIND | MS_REC, NULL)); AVER(mount("/target", "/", "bind", MS_BIND | MS_REC, NULL));
@ -118,5 +147,23 @@ int main(int argc, char *argv[], char *envp[])
AVER(execve("/persist/init", argv, envp)); AVER(execve("/persist/init", argv, envp));
} }
failsafe:
debug_listdir("/");
debug_listdir("/target");
ERR("failed to mount the rootfs\n");
ERR("final stand using the failsafe initialization method\n");
ERR("the boot process is manual from now on\n");
argv[0] = "init";
argv[1] = NULL;
// Attempt to unmount the /target mount-bind.
AVER(umount("/target"));
AVER(execve("/failsafe-init", argv, envp));
debug_listdir("/");
debug_listdir("/target");
die(); die();
} }

View file

@ -2,14 +2,15 @@
qemuLim qemuLim
, socat , socat
, writeShellScript , writeShellScript
, writeFennel
, runCommand , runCommand
, fennel
, lib , lib
, lua , lua
, pkgsBuildBuild , pkgsBuildBuild
}: let }: let
run-liminix-vm = pkgsBuildBuild.writeFennel "run-liminix-vm" { writeFennel = pkgsBuildBuild.writeFennel.override { inherit lua; };
packages = [ qemuLim pkgsBuildBuild.lua.pkgs.luaposix pkgsBuildBuild.lua.pkgs.fennel ]; run-liminix-vm = writeFennel "run-liminix-vm" {
packages = [ qemuLim lua.pkgs.luaposix fennel ];
} ./run-liminix-vm.fnl; } ./run-liminix-vm.fnl;
connect = writeShellScript "connect-vm" '' connect = writeShellScript "connect-vm" ''
export PATH="${lib.makeBinPath [socat]}:$PATH" export PATH="${lib.makeBinPath [socat]}:$PATH"

View file

@ -1,26 +1,35 @@
{ stdenv, lib, fetchFromGitHub, cmake, libubox, json_c }: { stdenv, fetchFromGitea, lib, cmake, libubox, json_c, lua, defaultSocketLocation ? "/run/ubus/ubus.sock" }:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "ubus"; pname = "ubus";
version = "unstable-04-09-2024"; version = "unstable-04-09-2024";
src = fetchFromGitHub { src = fetchFromGitea {
owner = "openwrt"; domain = "git.dgnum.eu";
owner = "DGNum";
repo = "ubus"; repo = "ubus";
rev = "65bb027054def3b94a977229fd6ad62ddd32345b"; rev = "ebb1dc92e4985538a8e18b7e926264118138f281";
hash = "sha256-n82Ub0IiuvWbnlDCoN+0hjo/1PbplEbc56kuOYMrHxQ="; hash = "sha256-fo4zleC9R6uzlcOJ/jQ0t0nSBHUAq/uqPVd9xJdkAM0=";
}; };
# We don't use /var/run/ in Liminix by default.
postPatch = ''
substituteInPlace CMakeLists.txt \
--replace-fail "/var/run/ubus/ubus.sock" "${defaultSocketLocation}"
'';
nativeBuildInputs = [ nativeBuildInputs = [
cmake cmake
]; ];
buildInputs = [ buildInputs = [
lua
libubox libubox
json_c json_c
]; ];
cmakeFlags = [ cmakeFlags = [
"-DBUILD_LUA=off" "-DBUILD_LUA=on"
"-DLUAPATH=${placeholder "out"}/lib/lua/${lua.luaversion}"
"-DBUILD_EXAMPLES=off" "-DBUILD_EXAMPLES=off"
]; ];
} }

View file

@ -27,7 +27,7 @@ name :
echo "#!${lua}/bin/lua ${luaFlags}" echo "#!${lua}/bin/lua ${luaFlags}"
echo "package.path = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luapath)} .. package.path" echo "package.path = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luapath)} .. package.path"
echo "package.cpath = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luacpath)} .. package.cpath" echo "package.cpath = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luacpath)} .. package.cpath"
echo "local ok, stdlib = pcall(require,'posix.stdlib'); if ok then stdlib.setenv('PATH',${lib.escapeShellArg (lib.makeBinPath packages)} .. \":\" .. os.getenv('PATH')) end" echo "local ok, stdlib = pcall(require,'posix.stdlib'); if ok then stdlib.setenv('PATH', \"${lib.makeBinPath packages}\" .. \":\" .. os.getenv('PATH')) end"
fennel ${if correlate then "--correlate" else ""} --compile ${source} fennel ${if correlate then "--correlate" else ""} --compile ${source}
) > ${name}.lua ) > ${name}.lua
''; '';