Skip to content

loader: allow custom path - #2378

Merged
supakeen merged 1 commit into
osbuild:mainfrom
supakeen:allow-defs-path-passing
May 29, 2026
Merged

supakeen merged 1 commit into
osbuild:mainfrom
supakeen:allow-defs-path-passing

Conversation

@supakeen

Copy link
Copy Markdown
Member

Currently our definition loader always uses the embedded data filesystem exposed by dataFS(). It is possible to switch what dataFS() returns with an experimental environment flag.

We want to make loading of definitions a little bit less experimental by allowing a definition path to be set by calling code; instead of the library reading the environment.

A hurdle was that distro.ParseID loaded the definitions directly.

In this commit I introduce a new Loader type that embeds an fs.FS, ParseID becomes a method on this Loader. Where necessary old constructors that do not take a loader will automatically call the new WithLoader variants by passing the BuiltinLoader (which gives the same behavior).

This will allow us to pass custom paths in image-builder and osbuild-composer through (for example) a --force-defs-path and the potential to start shipping our definitions in a subpackage that installs into /usr which would allow for much easier downstream patching and other distributions shipping their own custom definition packages.

Currently our definition loader always uses the embedded data
filesystem exposed by `dataFS()`. It is possible to switch what
`dataFS()` returns with an experimental environment flag.

We want to make loading of definitions a little bit less experimental
by allowing a definition path to be set by calling code; instead of the
library reading the environment.

A hurdle was that `distro.ParseID` loaded the definitions directly.

In this commit I introduce a new `Loader` type that embeds an `fs.FS`,
`ParseID` becomes a method on this `Loader`. Where necessary old
constructors that do not take a loader will automatically call the new
WithLoader variants by passing the `BuiltinLoader` (which gives the same
behavior).

This will allow us to pass custom paths in `image-builder` and
`osbuild-composer` through (for example) a `--force-defs-path` and the
potential to start shipping our definitions in a subpackage that
installs into `/usr` which would allow for much easier downstream
patching *and* other distributions shipping their own custom definition
packages.

Signed-off-by: Simon de Vlieger <[email protected]>
@supakeen
supakeen requested a review from a team as a code owner May 28, 2026 06:55

@thozza thozza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this kick-off PR.

While the change does what it claims to do, I wonder what is the long term plan here? I think that a fully forced override of distro definitions is a feature that has a use case of its own (i.e. build systems). That said, I still think that the deleted code comment claiming that we want to have search paths is something that we should not just abandon. I think that a hierarchical override, like we allow for repo configs, is a really useful feature. It would allow selectively override just specific distro or image type, while allowing us to keep the fallback to the built-in definitions.

Comment on lines +21 to +23
func ClearLoader(d *DistroYAML) {
d.loader = nil
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been simply

func (d *DistroYAML) ClearLoader() {
	d.loader = nil
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm yes, not a big issue; I think I only have a use case for it in the testcases to make it easier to compare the structs and then my brain got tangled up and it ended up like this 🙂

Comment thread pkg/distro/defs/loader.go
Comment on lines -46 to -47
// XXX: this is a short term measure, pass a set of
// searchPaths down the stack instead

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think that this would be a much nicer idea, than a fully forced override.

@supakeen

supakeen commented May 28, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for this kick-off PR.

While the change does what it claims to do, I wonder what is the long term plan here? I think that a fully forced override of distro definitions is a feature that has a use case of its own (i.e. build systems). That said, I still think that the deleted code comment claiming that we want to have search paths is something that we should not just abandon. I think that a hierarchical override, like we allow for repo configs, is a really useful feature. It would allow selectively override just specific distro or image type, while allowing us to keep the fallback to the built-in definitions.

The long term plan is as of yet to be defined. This change doesn't preclude the potential of having multiple search paths (Loader would then probably be changed to contain a []fs.FS instead) but doing that in this PR would require solving the merging of definitions.

I assume in the future we will have []fs.FS and in image-builder have both --force-defs-dir (to override all built-in definitions) and --extra-defs-dir, mirroring what we have for repositories though we'll start off with --force-defs-dir only and set the 'default' definition directory to a path in /usr/share.

@brlane-rht brlane-rht left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@brlane-rht

Copy link
Copy Markdown
Contributor

FWIW I like the idea of search paths, but don't like trying to merge things. I think it'll make things overly complex, and make it difficult for users to reason about the results. It's more clear if you just override the defaults with the content of the new path.

@supakeen
supakeen added this pull request to the merge queue May 29, 2026
Merged via the queue into osbuild:main with commit 02fed91 May 29, 2026
20 checks passed
@supakeen
supakeen deleted the allow-defs-path-passing branch May 29, 2026 05:22
achilleas-k pushed a commit to achilleas-k/image-builder that referenced this pull request Jun 17, 2026
Previously it was possible to pass a custom definition directory through
the use of `IMAGE_BUILDER_EXPERIMENTAL` options. In `images` 0.269.0 I
landed a PR [1] that allows us setting the definition path in code.

This commit implements that, plus test cases, to pass custom
definitions.

We keep the argument hidden as we still consider it to be experimental
until we flesh out certain things but this *will* allow us to source our
default image definitions from disk instead of the embedded filesystem
in the near future (a follow up) so consider this the lead-up to that.

The argument follows the same naming as others, `force` means to
entirely wipe and override the built-ins. In the future there will
likely be an `extra` equivalent to extend, or override pre-existing
definitions in the same way we do for repositories.

We might enable this for build systems in their respective plugins at
some point as well.

[1]: osbuild#2378

Signed-off-by: Simon de Vlieger <[email protected]>
achilleas-k pushed a commit to achilleas-k/image-builder that referenced this pull request Jun 17, 2026
Previously it was possible to pass a custom definition directory through
the use of `IMAGE_BUILDER_EXPERIMENTAL` options. In `images` 0.269.0 I
landed a PR [1] that allows us setting the definition path in code.

This commit implements that, plus test cases, to pass custom
definitions.

We keep the argument hidden as we still consider it to be experimental
until we flesh out certain things but this *will* allow us to source our
default image definitions from disk instead of the embedded filesystem
in the near future (a follow up) so consider this the lead-up to that.

The argument follows the same naming as others, `force` means to
entirely wipe and override the built-ins. In the future there will
likely be an `extra` equivalent to extend, or override pre-existing
definitions in the same way we do for repositories.

We might enable this for build systems in their respective plugins at
some point as well.

[1]: osbuild#2378

Signed-off-by: Simon de Vlieger <[email protected]>
achilleas-k pushed a commit to achilleas-k/image-builder that referenced this pull request Jun 18, 2026
Previously it was possible to pass a custom definition directory through
the use of `IMAGE_BUILDER_EXPERIMENTAL` options. In `images` 0.269.0 I
landed a PR [1] that allows us setting the definition path in code.

This commit implements that, plus test cases, to pass custom
definitions.

We keep the argument hidden as we still consider it to be experimental
until we flesh out certain things but this *will* allow us to source our
default image definitions from disk instead of the embedded filesystem
in the near future (a follow up) so consider this the lead-up to that.

The argument follows the same naming as others, `force` means to
entirely wipe and override the built-ins. In the future there will
likely be an `extra` equivalent to extend, or override pre-existing
definitions in the same way we do for repositories.

We might enable this for build systems in their respective plugins at
some point as well.

[1]: osbuild#2378

Signed-off-by: Simon de Vlieger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants