all-formats: fix incorrect symlinks i.e. for sd-image formats

- output $out/$basename instead of $out being a symlink to the resulting file.
  This works around problem where we cannot predict the file extension of the output reliably,
  and therefore the direct symlink had the wrong extension in some cases.
- fix wrong file symlinked under $out for sd image formats
This commit is contained in:
DavHau 2024-07-28 16:03:16 +07:00 committed by Jörg Thalheim
parent 9a666f144f
commit b9c5637760

View File

@ -36,11 +36,14 @@
# attrset of formats to be exposed under config.system.formats # attrset of formats to be exposed under config.system.formats
formats = lib.flip lib.mapAttrs allConfigs ( formats = lib.flip lib.mapAttrs allConfigs (
formatName: conf: pkgs.runCommand "${conf.config.system.build.${conf.config.formatAttr}.name}${conf.config.fileExtension}" {} '' formatName: conf: exposeConfig conf (
set -efu pkgs.runCommand "${conf.config.system.build.${conf.config.formatAttr}.name}" {} ''
target=$(find '${conf.config.system.build.${conf.config.formatAttr}}' -name '*${conf.config.fileExtension}' -xtype f -print -quit) set -efu
ln -s "$target" "$out" target=$(find '${conf.config.system.build.${conf.config.formatAttr}}' -name '*${conf.config.fileExtension}' -xtype f -print -quit)
'' mkdir $out
ln -s "$target" "$out/$(basename "$target")"
''
)
); );
in { in {
_file = ./all-formats.nix; _file = ./all-formats.nix;
@ -54,7 +57,7 @@ in {
options.formats = lib.mkOption { options.formats = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw; type = lib.types.lazyAttrsOf lib.types.raw;
description = '' description = ''
Different target formats generated for this NixOS configuratation. Different target formats generated for this NixOS configuration.
''; '';
}; };