chmod +x $out/etc/init.d/... not working
With this perfect, great builder i'm able to initialize, upgrade and provision my router and access points in a matter of minutes. I love it!
I've created a dozen of nix-files which results in installing packages and provisioning uci-defaults files to do all the configuration.
For each OpenWRT-device i do some concatenation like:
...
luci = import ../../modules/openwrt/luci.nix;
wpad = import ../../modules/openwrt/wpad.nix;
iperf3 = import ../../modules/openwrt/iperf3.nix;
watchcat = import ../../modules/openwrt/watchcat.nix;
config = profiles.identifyProfile "ubnt_unifiac-mesh" // {
packages = unregulatory.packages ++ zabbix_agentd.packages ++ ttyd.packages ++ usteer.packages ++ dropbear.packages ++ dumbap.packages ++
luci.packages ++ watchcat.packages ++ wpad.packages ++ iperf3.packages ++ [
"nano"
];
release = vars.openwrt.release;
target = "ath79";
variant = "generic";
profile = "ubnt_unifiac-mesh";
EXTRA_IMAGE_NAME = "ap-buiten";
disabledServices = [ "dnsmasq" "firewall" "odhcpd" ];
files = pkgs.runCommand "image-files" { } ''
${dumbap.snippet}
${iperf3.snippet}
${luci.snippet}
...
One small issue i seem to be running into is that i seem to be unable to get provisioned files to have the executable flag set in the resulting sysupgrade image.
Given the below nix-file which is to enable iperf3 running as a service on all my OpenWRT devices which i have Zabbix configured to test on a regular basis. It exposes a combination of packages and snippet which get concatenated with other nix-files (see the snippet above).
In this specific nix-file i write a service-definition file $out/etc/init.d/iperf3 which needs to be executable. If i add an instruction to add the executable flag on this file, the flag seems to get lost somewhere. I can imagine that this happens during the copying of files to the image.
I can workaround the issue by adding the executable flag from within a uci-defaults file. Which is not a problem, but is not as "clean" as it could be.
let
in
{
packages = [ "iperf3" ];
snippet = ''
mkdir -p $out/etc/uci-defaults
cat > $out/etc/uci-defaults/96-iperf3 <<EOF
chmod +x /etc/init.d/iperf3 <=== this action does work
/etc/init.d/iperf3 enable
/etc/init.d/iperf3 start
EOF
mkdir -p $out/etc/init.d
cat > $out/etc/init.d/iperf3 <<EOF
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2011 OpenWrt.org
START=60
USE_PROCD=1
PROG=/usr/bin/iperf3
start_service() {
procd_open_instance
procd_set_param command /usr/bin/iperf3 -s -D
procd_set_param respawn
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
EOF
chmod +x $out/etc/init.d/iperf3 <=== this action does not work
'';
}
Is this an issue which might be resolved?
I think i see the same issue when looking at the uci-defaults file in /rom/etc/uci-defaults:
This as my custom uci-defaults files are not executable while the OpenWRT ones are.
thanks in advance!
In our setup I have the following:
files = pkgs.runCommandNoCC "image-files" {} ''
mkdir -p $out/etc/uci-defaults
cat > $out/etc/uci-defaults/99-zentralwerk <<EOF
${uciConfig hostName}
EOF
mkdir -p $out/usr/{bin,sbin}
cp ${./usteer-info.sh} $out/usr/sbin/usteer-info.sh
cp ${./usteer-stats.sh} $out/usr/bin/usteer-stats.sh
chmod +x $out/usr/bin/*.sh $out/usr/sbin/*.sh
'';
The scripts in /etc/uci-defaults don't have to be executable, they're sourced by /lib/functions.sh.
My scripts in /usr turn up executable in the running OpenWrt system.