diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9cfa5d8..73bc023 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,10 +26,11 @@ jobs: id: generate-recipes shell: bash run: | - sudo apt install -y jsonnet - mkdir config/recipes - - RECIPES=$(jsonnet ./config/templates/recipe-std.jsonnet -m ./config/recipes -y) + curl -L -o pkl https://github.com/apple/pkl/releases/download/0.25.3/pkl-linux-amd64 + chmod +x pkl + ./pkl --version + + RECIPES=$(./pkl eval ./config/templates/std.pkl -f json -m ./config/recipes) # newlines replaced with spaces echo "Generated recipes: ${RECIPES//$'\n'/ }" diff --git a/config/templates/recipe-std.jsonnet b/config/templates/recipe-std.jsonnet deleted file mode 100644 index ff713a3..0000000 --- a/config/templates/recipe-std.jsonnet +++ /dev/null @@ -1,53 +0,0 @@ -local project = { - image_name: "atomic-studio", - description: "Operating system based on Fedora Atomic meant for content creators and artists", - base_images: "ghcr.io/ublue-os", -}; - -local modules = { - shared: ["packages", "files", "scripts", "bling", "services"], - fx: ["apps", "flatpaks", "audinux"], - nvidia: [], - amd: ["packages", "scripts"], - gnome: ["apps"], - plasma: ["apps", "scripts", "files"], - misc: [{ "type": "yafti" }, { "type": "signing" }], -}; - -local gen_module_definition(prefix, modules) = [ - { "from-file": ("common/" + prefix + "/" + module + ".yml")} - for module in modules -]; - -local gen_image_tags(baseimage, nvidia, fx) = - (if (baseimage == "silverblue") then "-gnome" else "") - + (if(fx) then "-fx" else "") - + (if(nvidia) then "-nvidia" else ""); - -local image(baseimage, nvidia, fx) = { - "name": project.image_name + gen_image_tags(baseimage, nvidia, fx), - "description": project.description, - "base-image": project.base_images + "/" + baseimage + (if (nvidia) then "-nvidia" else "-main"), - "image-version": "latest", - "modules": std.flattenArrays( - [ - gen_module_definition("shared", modules.shared), - if (nvidia) then [] else gen_module_definition("shared/amd", modules.amd), - if (baseimage == "silverblue") then gen_module_definition("gnome", modules.gnome) else gen_module_definition("plasma", modules.plasma), - if (fx) then gen_module_definition("fx", modules.fx) else [], - modules.misc, - ]), -}; - -local gen_all_variations(prefix) = { - [prefix + gen_image_tags(base_image, nvidia, fx) + ".yml"]: image(base_image, nvidia, fx) - for nvidia in [ - true, false - ] for base_image in [ - "kinoite", "silverblue" - ] for fx in [ - true, false - ] -}; - -gen_all_variations("recipe") diff --git a/config/templates/std.pkl b/config/templates/std.pkl new file mode 100644 index 0000000..19cf650 --- /dev/null +++ b/config/templates/std.pkl @@ -0,0 +1,91 @@ +class Project { + image_name: String + description: String + base_images: String +} + +class Image { + name: String + description: String + `base-image`: String + `image-version`: String + modules: Listing +} + +class ImportModule { + `from-file`: String +} + +const meta = (Project) { + image_name = "atomic-studio" + description = "Operating system based on Fedora Atomic meant for content creators and artists" + base_images = "ghcr.io/ublue-os" +} + +const allModules { + shared = List("packages", "files", "scripts", "bling", "services") + fx = List("apps", "flatpaks", "audinux") + nvidia = List() + amd = List("packages", "scripts") + gnome = List("apps") + plasma = List("apps", "scripts", "files") + misc = List(new Mapping { + ["type"] = "yafti" + }, new Mapping { + ["type"] = "signing" + }) +} + + +const function toImportModule(baseFolder: String, extension: String, prefix: String, modules: List): Listing = new Listing { + for (_module in modules) { + new ImportModule { + `from-file` = "\(baseFolder)/\(prefix)/\(_module)\(extension)" + } + } +} + +const function genImageTags(base: String, nvidia: Boolean, fx: Boolean): String = (if (base == "silverblue") "-gnome" else "") + (if (fx) "-fx" else "") + (if (nvidia) "-nvidia" else "") + +const function genImage(base: String, nvidia: Boolean, fx: Boolean): Image = (Image) { + name = "\(meta.image_name)\(genImageTags(base, nvidia, fx))" + description = meta.description + `base-image` = "\(meta.base_images)/\(base)\(if (nvidia) "-nvidia" else "-main")" + `image-version` = "latest" + modules = new Listing { + ...(toImportModule("common", ".yml", "shared", allModules.shared)) + ...?(if(nvidia) null else toImportModule("common", ".yml", "shared/amd", allModules.amd)) + ...?(if(base == "silverblue") toImportModule("common", ".yml", "gnome", allModules.gnome) else toImportModule("common", ".yml", "plasma", allModules.plasma)) + ...?(if(fx) toImportModule("common", ".yml", "fx", allModules.fx) else null) + } +} + + /*[ + gen_module_definition("shared", modules.shared), + if (nvidia) then [] else gen_module_definition("shared/amd", modules.amd), + if (baseimage == "silverblue") then gen_module_definition("gnome", modules.gnome) else gen_module_definition("plasma", modules.plasma), + if (fx) then gen_module_definition("fx", modules.fx) else [], + modules.misc, + ]),*/ + +const function atomicStudioImages(prefix: String, extension: String): Mapping = new Mapping { + for (_base in List("kinoite", "silverblue")) { + for (_nvidia in List(false, true)) { + for (_fx in List(false, true)) { + ["\(prefix)\(genImageTags(_base, _nvidia, _fx))\(extension)"] = genImage(_base, _nvidia, _fx) + } + } + } +} + + +output { + files { + for (_filename, _recipe in atomicStudioImages("recipe", ".yml")) { + [_filename] { + value = _recipe + renderer = new YamlRenderer {} + } + } + } +}