Move "system" options to "build" add UCI system options

This commit is contained in:
Ehmry - 2022-06-23 16:20:00 -05:00
parent 807ee39110
commit 2999346274
5 changed files with 78 additions and 52 deletions

View File

@ -34,7 +34,12 @@ let
({ pkgs, ... }: {
# find target/variant for an old Fritzbox
system.profile = "avm_fritz7412";
build.profile = "avm_fritz7412";
system.settings = {
hostname = "testrouter";
description = "nix-openwrt-imagebuilder example";
};
# add package to include in the image, ie. packages that you don't
# want to install manually later
@ -76,7 +81,12 @@ in sys.config.system.build.image
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
({ pkgs, ... }: {
system.profile = "avm_fritz7412";
build.profile = "avm_fritz7412";
system.settings = {
hostname = "testrouter";
description = "nix-openwrt-imagebuilder example";
};
# add package to include in the image, ie. packages that you don't
# want to install manually later

View File

@ -1,7 +1,12 @@
{ pkgs, ... }:
{
system.profile = "avm_fritz7412";
build.profile = "avm_fritz7412";
system.settings = {
description = "nix-openwrt-imagebuilder example";
timezone = "CET-1CEST,M3.5.0,M10.5.0/3";
};
packages.include = [ "tcpdump" "vxlan" "kmod-vxlan" ];

View File

@ -1,12 +1,40 @@
{ config, lib, pkgs, profiles, ... }:
{
system.build.image = import ../../builder.nix {
inherit pkgs;
inherit (config.system) release target variant profile;
inherit (config) files extraFiles;
packages = config.packages.include
++ map (x: "-${x}") config.packages.exclude;
disabledServices = config.services.disabled;
let cfg = config.build;
in {
options.build = with lib; {
profile = mkOption {
type = with types; nullOr str;
default = null;
description = "Hardware profile";
};
release = mkOption {
type = types.str;
default = "21.02.3";
description = "OpenWRT release";
};
target = mkOption {
type = types.str;
description = "OpenWRT target";
};
variant = mkOption {
type = types.str;
description = "Hardware variant";
};
};
config = {
build = lib.mkIf (cfg.profile != null) (lib.mapAttrs (_: lib.mkDefault) {
inherit (profiles.identifyProfile cfg.profile) target variant;
});
system.build.image = import ../../builder.nix {
inherit pkgs;
inherit (cfg) release target variant profile;
inherit (config) files extraFiles;
packages = config.packages.include
++ map (x: "-${x}") config.packages.exclude;
disabledServices = config.services.disabled;
};
};
}

View File

@ -2,48 +2,31 @@
let cfg = config.system;
in {
options.system = with lib;
let nullOrStr = types.nullOr types.str;
in {
build = mkOption {
default = { };
description = ''
Attribute set of derivations used to construct the system.
'';
type = types.submoduleWith {
modules =
[{ freeformType = with types; lazyAttrsOf (uniq unspecified); }];
};
};
profile = mkOption {
type = nullOrStr;
default = null;
description = "Hardware profile";
};
release = mkOption {
type = types.str;
default = "21.02.3";
description = "OpenWRT release";
};
target = mkOption {
type = types.str;
description = "OpenWRT target";
};
variant = mkOption {
type = types.str;
description = "Hardware variant";
};
options.system = with lib; {
settings = mkOption {
default = { };
type = types.uciSection;
description = ''
See <link xlink:href="https://openwrt.org/docs/guide-user/base-system/system_configuration"/>'';
};
config.system = lib.mkIf (cfg.profile != null)
(lib.mapAttrs (_: lib.mkDefault) {
inherit (profiles.identifyProfile cfg.profile) target variant;
});
build = mkOption {
default = { };
description = ''
Attribute set of derivations used to construct the system.
'';
type = types.submoduleWith {
modules =
[{ freeformType = with types; lazyAttrsOf (uniq unspecified); }];
};
};
};
config.uci.batch = lib.toUciBatch {
config = "system";
type = "system";
} cfg.settings;
}

View File

@ -9,7 +9,7 @@ let
inherit pkgs;
profiles = import ../profiles.nix {
inherit pkgs;
inherit (config.system) release;
inherit (config.build) release;
};
};
})