Add UCI batch and Dropbear options
This commit is contained in:
parent
2cd689783a
commit
807ee39110
|
@ -5,6 +5,10 @@
|
||||||
|
|
||||||
packages.include = [ "tcpdump" "vxlan" "kmod-vxlan" ];
|
packages.include = [ "tcpdump" "vxlan" "kmod-vxlan" ];
|
||||||
|
|
||||||
|
dropbear.settings = {
|
||||||
|
PasswordAuth = false;
|
||||||
|
};
|
||||||
|
|
||||||
files = pkgs.runCommandNoCC "image-files" { } ''
|
files = pkgs.runCommandNoCC "image-files" { } ''
|
||||||
mkdir -p $out/etc/uci-defaults
|
mkdir -p $out/etc/uci-defaults
|
||||||
cat > $out/etc/uci-defaults/99-custom <<EOF
|
cat > $out/etc/uci-defaults/99-custom <<EOF
|
||||||
|
|
16
lib/modules/dropbear.nix
Normal file
16
lib/modules/dropbear.nix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
let cfg = config.dropbear;
|
||||||
|
in {
|
||||||
|
options.dropbear.settings = with lib;
|
||||||
|
mkOption {
|
||||||
|
default = { };
|
||||||
|
type = types.uciSection;
|
||||||
|
description = ''
|
||||||
|
See <link xlink:href="https://openwrt.org/docs/guide-user/base-system/dropbear"/>'';
|
||||||
|
};
|
||||||
|
|
||||||
|
config.uci.batch = lib.toUciBatch {
|
||||||
|
config = "dropbear";
|
||||||
|
type = "dropbear";
|
||||||
|
} cfg.settings;
|
||||||
|
}
|
20
lib/modules/uci.nix
Normal file
20
lib/modules/uci.nix
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
let cfg = config.uci;
|
||||||
|
in {
|
||||||
|
options.uci.batch = mkOption {
|
||||||
|
type = types.lines;
|
||||||
|
description = "UCI script to execute on first boot.";
|
||||||
|
example = ''
|
||||||
|
set system.@system[0].hostname='testap'
|
||||||
|
set dropbear.@dropbear[0].RootPasswordAuth='off'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
config.extraFiles."/etc/uci-defaults/99-config.uci.batch".text =
|
||||||
|
mkIf (cfg.batch != "") ''
|
||||||
|
uci -q batch << NIX_EOI
|
||||||
|
${cfg.batch}
|
||||||
|
uci commit
|
||||||
|
NIX_EOI
|
||||||
|
'';
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
{ pkgs ? import <nixpkgs> { }, modules }:
|
{ pkgs ? import <nixpkgs> { }, modules }:
|
||||||
|
|
||||||
let
|
let
|
||||||
result = pkgs.lib.evalModules {
|
lib' = pkgs.lib.extend (import ./uci.nix);
|
||||||
|
result = lib'.evalModules {
|
||||||
modules = [
|
modules = [
|
||||||
({ config, ... }: {
|
({ config, ... }: {
|
||||||
config._module.args = {
|
config._module.args = {
|
||||||
|
@ -12,11 +13,13 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
./modules/system.nix
|
./modules/build.nix
|
||||||
|
./modules/dropbear.nix
|
||||||
./modules/files.nix
|
./modules/files.nix
|
||||||
./modules/packages.nix
|
./modules/packages.nix
|
||||||
./modules/services.nix
|
./modules/services.nix
|
||||||
./modules/build.nix
|
./modules/system.nix
|
||||||
|
./modules/uci.nix
|
||||||
] ++ modules;
|
] ++ modules;
|
||||||
};
|
};
|
||||||
in { inherit (result) config options; }
|
in { inherit (result) config options; }
|
||||||
|
|
18
lib/uci.nix
Normal file
18
lib/uci.nix
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
final: prev:
|
||||||
|
let lib = prev;
|
||||||
|
in {
|
||||||
|
|
||||||
|
types = lib.types
|
||||||
|
// (with lib.types; { uciSection = attrsOf (oneOf [ bool int str ]); });
|
||||||
|
|
||||||
|
toUciBatch = with builtins;
|
||||||
|
let toAtom = v: if isBool v then (if v then "0" else "1") else (toString v);
|
||||||
|
in { config, type, section ? "@${type}[0]" }:
|
||||||
|
attrs:
|
||||||
|
let
|
||||||
|
cmds = [ "set ${config}.${section}=${type}" ]
|
||||||
|
++ (lib.attrsets.mapAttrsToList (option: value:
|
||||||
|
"set ${config}.${section}.${option}='${toAtom value}'") attrs);
|
||||||
|
|
||||||
|
in lib.strings.concatStringsSep "\n" cmds;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user