GUID for gdisk: have Guix inject the hash of the inputs into the source tree
This commit is contained in:
parent
77b33ac0e1
commit
3b640e997d
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,6 +5,9 @@
|
||||||
/build/check_makefile
|
/build/check_makefile
|
||||||
/build/check_makefile_targets
|
/build/check_makefile_targets
|
||||||
/build/check_makefile_w_arnings
|
/build/check_makefile_w_arnings
|
||||||
|
/build/gpt_disk_guid
|
||||||
|
/build/gpt_partition_guid
|
||||||
|
/build/input-hash
|
||||||
/build/iso_files/boot/iso_boot.sys
|
/build/iso_files/boot/iso_boot.sys
|
||||||
/build/iso_files/os.zip
|
/build/iso_files/os.zip
|
||||||
/build/makefile_built_directories
|
/build/makefile_built_directories
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -70,6 +70,8 @@ ${bld}/makefile_w_arnings: | $${@D}
|
||||||
${built_files}: | $${@D}
|
${built_files}: | $${@D}
|
||||||
|
|
||||||
${bld}/makefile_w_arnings: ${Makefiles}
|
${bld}/makefile_w_arnings: ${Makefiles}
|
||||||
|
test -e input-hash || printf "\033[1;31mWARNING: input-hash should be created by guix build.\033[m\n"
|
||||||
|
|
||||||
@unset MAKEFLAGS MAKELEVEL MAKE_TERMERR MFLAGS; \
|
@unset MAKEFLAGS MAKELEVEL MAKE_TERMERR MFLAGS; \
|
||||||
make -n --warn-undefined-variables \
|
make -n --warn-undefined-variables \
|
||||||
OS_FILENAME=${OS_FILENAME} \
|
OS_FILENAME=${OS_FILENAME} \
|
||||||
|
|
|
@ -51,6 +51,9 @@ built_files += ${os_filename} \
|
||||||
${bld}/os.hex_with_offsets \
|
${bld}/os.hex_with_offsets \
|
||||||
${bld}/iso_files/os.zip \
|
${bld}/iso_files/os.zip \
|
||||||
${bld}/iso_files/boot/iso_boot.sys \
|
${bld}/iso_files/boot/iso_boot.sys \
|
||||||
|
${bld}/input-hash \
|
||||||
|
${bld}/gpt_disk_guid \
|
||||||
|
${bld}/gpt_partition_guid \
|
||||||
${more_offset_dec} \
|
${more_offset_dec} \
|
||||||
${more_offset_hex} \
|
${more_offset_hex} \
|
||||||
|
|
||||||
|
@ -221,12 +224,39 @@ ${bld}/os.zip.adjusted: ${bld}/os.zip ${dep_bytes_zip_start} ${bld}/check_makefi
|
||||||
|
|
||||||
gdisk_pipe_commands_slowly=while read str; do echo "$$str"; printf "\033[1;33m%s\033[m\n" "$$str" >&2; sleep 0.01; done
|
gdisk_pipe_commands_slowly=while read str; do echo "$$str"; printf "\033[1;33m%s\033[m\n" "$$str" >&2; sleep 0.01; done
|
||||||
|
|
||||||
commit_hash_as_guid=$$((git log -1 --pretty=format:%H || echo 0000000000000000000000000000000000000000) | sed -e 's/^\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\).*$$/\1-\2-\3-\4-\5/' | tr '[:lower:]' '[:upper:]')
|
.PHONY: force-input-hash
|
||||||
git_dirty=test -n "$$(git diff --shortstat)"
|
${bld}/input-hash: force-input-hash ${bld}/check_makefile
|
||||||
gpt_disk_guid=${commit_hash_as_guid}$$(if $$git_dirty; then printf '0'; else printf '2'; fi)
|
# input-hash must be a 33 (or more) character-long hexadecimal hash of the
|
||||||
gpt_partition_guid=${commit_hash_as_guid}$$(if $$git_dirty; then printf '1'; else printf '3'; fi)
|
# inputs. It can be used to generate UUIDs for the generated disk image, for
|
||||||
|
# example.
|
||||||
|
#
|
||||||
|
# We use `git log -1 --pretty=format:%H' to obtain the hash of the current
|
||||||
|
# commit as a fallback, but we do not have access to that information
|
||||||
|
# within a Guix build environment.
|
||||||
|
h=$$( cat input-hash \
|
||||||
|
|| git log -1 --pretty=format:%H \
|
||||||
|
|| echo 0000000000000000000000000000000000000000 \
|
||||||
|
); \
|
||||||
|
if test "$$h" != "$$(cat $@ || echo '')"; then \
|
||||||
|
echo "$$h" > "$@"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The last digit is 1, to distinguish the disk GUID from the partition GUID
|
||||||
|
${bld}/gpt_disk_guid: ${bld}/input-hash ${bld}/check_makefile
|
||||||
|
cat $< \
|
||||||
|
| sed -e 's/^\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{11\}\).*$$/\1-\2-\3-\4-\51/' \
|
||||||
|
| tr '[:lower:]' '[:upper:]' \
|
||||||
|
> $@
|
||||||
|
|
||||||
|
# The last digit is 2, to distinguish the disk GUID from the partition GUID
|
||||||
|
${bld}/gpt_partition_guid: ${bld}/input-hash ${bld}/check_makefile
|
||||||
|
cat $< \
|
||||||
|
| sed -e 's/^\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{11\}\).*$$/\1-\2-\3-\4-\52/' \
|
||||||
|
| tr '[:lower:]' '[:upper:]' \
|
||||||
|
> $@
|
||||||
|
|
||||||
${os_filename}: ${bld}/os.32k ${bld}/os.iso ${bld}/os.fat12 ${bld}/os.zip.adjusted \
|
${os_filename}: ${bld}/os.32k ${bld}/os.iso ${bld}/os.fat12 ${bld}/os.zip.adjusted \
|
||||||
|
${bld}/gpt_disk_guid ${bld}/gpt_partition_guid \
|
||||||
${dep_bytes_header_32k_start} \
|
${dep_bytes_header_32k_start} \
|
||||||
${dep_bytes_header_32k_size} \
|
${dep_bytes_header_32k_size} \
|
||||||
${dep_bytes_fat12_start} \
|
${dep_bytes_fat12_start} \
|
||||||
|
@ -266,8 +296,8 @@ ${os_filename}: ${bld}/os.32k ${bld}/os.iso ${bld}/os.fat12 ${bld}/os.zip.adjust
|
||||||
printf "1\nN\n"; \
|
printf "1\nN\n"; \
|
||||||
printf "01\nY\nN\n"; \
|
printf "01\nY\nN\n"; \
|
||||||
printf "x\n"; \
|
printf "x\n"; \
|
||||||
printf "g\n${gpt_disk_guid}\n"; \
|
printf "g\n$$(cat ${bld}/gpt_disk_guid)\n"; \
|
||||||
printf "c\n${gpt_partition_guid}\n"; \
|
printf "c\n$$(cat ${bld}/gpt_partition_guid)\n"; \
|
||||||
printf "p\no\nw\nY\n") | ${gdisk_pipe_commands_slowly} | gdisk $@
|
printf "p\no\nw\nY\n") | ${gdisk_pipe_commands_slowly} | gdisk $@
|
||||||
# Inject MS-DOS newlines (CR+LF) and comments (":: ") in the GUID field of unused partition table entries,
|
# Inject MS-DOS newlines (CR+LF) and comments (":: ") in the GUID field of unused partition table entries,
|
||||||
# so that the part that is to be skipped by MS-DOS does not form a line longer than the MS-DOS maximum
|
# so that the part that is to be skipped by MS-DOS does not form a line longer than the MS-DOS maximum
|
||||||
|
|
15
guix.scm
15
guix.scm
|
@ -25,6 +25,8 @@
|
||||||
(ice-9 popen)
|
(ice-9 popen)
|
||||||
(ice-9 rdelim)
|
(ice-9 rdelim)
|
||||||
(gnu packages version-control)
|
(gnu packages version-control)
|
||||||
|
(gnu packages vim)
|
||||||
|
(gnu packages package-management)
|
||||||
(gnu packages assembly)
|
(gnu packages assembly)
|
||||||
(gnu packages base)
|
(gnu packages base)
|
||||||
(gnu packages mtools)
|
(gnu packages mtools)
|
||||||
|
@ -75,6 +77,17 @@
|
||||||
`(#:phases
|
`(#:phases
|
||||||
(modify-phases %standard-phases
|
(modify-phases %standard-phases
|
||||||
;; unpack ;; this phase is enabled
|
;; unpack ;; this phase is enabled
|
||||||
|
(add-after 'unpack 'compute-input-hash
|
||||||
|
(lambda* (#:key inputs #:allow-other-keys)
|
||||||
|
(invoke "sh" "-c"
|
||||||
|
(string-append
|
||||||
|
" guix hash -rx . --format=base32"
|
||||||
|
" | tr '[:lower:]' '[:upper:]'"
|
||||||
|
" | head -c 48"
|
||||||
|
" | base32 -d"
|
||||||
|
" | xxd -ps"
|
||||||
|
" | head -c 60"
|
||||||
|
" > input-hash"))))
|
||||||
;; patch-source-shebangs ;; this phase is enabled
|
;; patch-source-shebangs ;; this phase is enabled
|
||||||
(add-after 'patch-source-shebangs 'make-clean
|
(add-after 'patch-source-shebangs 'make-clean
|
||||||
(lambda* (#:key inputs #:allow-other-keys)
|
(lambda* (#:key inputs #:allow-other-keys)
|
||||||
|
@ -99,6 +112,8 @@
|
||||||
(list "in-guix" ,makefile-commit-timestamp)))
|
(list "in-guix" ,makefile-commit-timestamp)))
|
||||||
(native-inputs
|
(native-inputs
|
||||||
`(("git" ,git)
|
`(("git" ,git)
|
||||||
|
("xxd" ,xxd)
|
||||||
|
("guix" ,guix)
|
||||||
("nasm" ,nasm)
|
("nasm" ,nasm)
|
||||||
("which" ,which)
|
("which" ,which)
|
||||||
("mtools" ,mtools)
|
("mtools" ,mtools)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user