Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
feat: try to use pkl as templating engine
Browse files Browse the repository at this point in the history
  • Loading branch information
tulilirockz committed Apr 27, 2024
1 parent 645e3ff commit fa684ad
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 57 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'/ }"
Expand Down
53 changes: 0 additions & 53 deletions config/templates/recipe-std.jsonnet

This file was deleted.

91 changes: 91 additions & 0 deletions config/templates/std.pkl
Original file line number Diff line number Diff line change
@@ -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<ImportModule?>
}

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<String>): Listing<ImportModule> = new Listing<ImportModule> {
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<String, Image> = new Mapping<String, Image> {
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 {}
}
}
}
}

0 comments on commit fa684ad

Please sign in to comment.