Add extraFiles option

This commit is contained in:
Ehmry - 2022-06-23 11:47:26 -05:00
parent 6ba2d4800f
commit 2cd689783a
3 changed files with 45 additions and 5 deletions

View File

@ -20,8 +20,10 @@
, packagesArch ? null , packagesArch ? null
# Extra OpenWRT packages (can be prefixed with "-") # Extra OpenWRT packages (can be prefixed with "-")
, packages ? [] , packages ? []
# Include extra files # Directory of extra files to include
, files ? null , files ? null
# Attrset of files to include
, extraFiles ? { }
# Which services in /etc/init.d/ should be disabled # Which services in /etc/init.d/ should be disabled
, disabledServices ? [] , disabledServices ? []
# Add to output name # Add to output name
@ -95,10 +97,23 @@ stdenv.mkDerivation {
# copy files to avoid making etc read-only # copy files to avoid making etc read-only
"cp -r --no-preserve=all ${files} files" "cp -r --no-preserve=all ${files} files"
} }
${lib.strings.concatStringsSep "\n" (
lib.attrsets.mapAttrsToList (
path: { source, text }: ''
mkdir -p $(dirname ./files/${path})
${
if text != null then ''
cat << NIX_EOF > ./files/${path}
${text}
NIX_EOF
'' else "cat < ${source} > ./files/${path}"}
''
) extraFiles)
}
make image SHELL=${runtimeShell} \ make image SHELL=${runtimeShell} \
PROFILE="${profile}" \ PROFILE="${profile}" \
PACKAGES="${lib.concatStringsSep " " packages}" \ PACKAGES="${lib.concatStringsSep " " packages}" \
${lib.optionalString (files != null) ${lib.optionalString (files != null || extraFiles != { })
''FILES=./files'' ''FILES=./files''
} \ } \
DISABLED_SERVICES="${lib.concatStringsSep " " disabledServices}" \ DISABLED_SERVICES="${lib.concatStringsSep " " disabledServices}" \

View File

@ -4,7 +4,7 @@
system.build.image = import ../../builder.nix { system.build.image = import ../../builder.nix {
inherit pkgs; inherit pkgs;
inherit (config.system) release target variant profile; inherit (config.system) release target variant profile;
inherit (config) files; inherit (config) files extraFiles;
packages = config.packages.include packages = config.packages.include
++ map (x: "-${x}") config.packages.exclude; ++ map (x: "-${x}") config.packages.exclude;
disabledServices = config.services.disabled; disabledServices = config.services.disabled;

View File

@ -1,8 +1,9 @@
{ lib, ... }: { lib, ... }:
{ {
options.files = with lib; options = with lib; {
mkOption {
files = mkOption {
type = types.path; type = types.path;
default = null; default = null;
example = literalExample '' example = literalExample ''
@ -18,4 +19,28 @@
''; '';
description = "Directory of files to included in images."; description = "Directory of files to included in images.";
}; };
extraFiles = mkOption {
default = { };
description = ''
Set of files to build into the image.
'';
type = with types;
attrsOf (submodule {
options = {
source = mkOption {
default = null;
type = types.path;
description = "Path of the source file.";
};
text = mkOption {
default = null;
type = types.nullOr types.lines;
description = "Text of the file.";
};
};
});
};
};
} }