about summary refs log tree commit diff
path: root/nixos/lib
diff options
context:
space:
mode:
authorLeon Barrett <Leon.Barrett@sony.com>2023-03-31 14:51:38 -0700
committerLeon Barrett <Leon.Barrett@sony.com>2023-04-16 09:54:45 -0700
commit15c760d6b8fd425c4f10cda6f82959dd98ea191c (patch)
tree083ab48e541133fcd619985ccf4c46545aab6985 /nixos/lib
parenta711e445cc057ac06160816b848f5752a6b4b753 (diff)
downloadnixlib-15c760d6b8fd425c4f10cda6f82959dd98ea191c.tar
nixlib-15c760d6b8fd425c4f10cda6f82959dd98ea191c.tar.gz
nixlib-15c760d6b8fd425c4f10cda6f82959dd98ea191c.tar.bz2
nixlib-15c760d6b8fd425c4f10cda6f82959dd98ea191c.tar.lz
nixlib-15c760d6b8fd425c4f10cda6f82959dd98ea191c.tar.xz
nixlib-15c760d6b8fd425c4f10cda6f82959dd98ea191c.tar.zst
nixlib-15c760d6b8fd425c4f10cda6f82959dd98ea191c.zip
nixos/make-disk-image: fix contents dir paths
`make-disk-image` is a tool for creating VM images. It takes an argument
`contents` that allows one to specify files and directories that should
be copied into the VM image. However, directories end up not at the
specified target, but instead at a subdirectory of the target, with a
nix-store-like path, e.g.
`/target/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-source`. See issue
https://github.com/NixOS/nixpkgs/issues/226203 .

This change adds a test for make-disk-image's contents directory
handling and adds a fix (appending `/` to rsync input directory names).

This closes issue https://github.com/NixOS/nixpkgs/issues/226203 .
Diffstat (limited to 'nixos/lib')
-rw-r--r--nixos/lib/make-disk-image.nix11
1 files changed, 8 insertions, 3 deletions
diff --git a/nixos/lib/make-disk-image.nix b/nixos/lib/make-disk-image.nix
index d641d1289fe4..db53bb98ee4e 100644
--- a/nixos/lib/make-disk-image.nix
+++ b/nixos/lib/make-disk-image.nix
@@ -402,11 +402,16 @@ let format' = format; in let
         done
       else
         mkdir -p $root/$(dirname $target)
-        if ! [ -e $root/$target ]; then
-          rsync $rsync_flags $source $root/$target
-        else
+        if [ -e $root/$target ]; then
           echo "duplicate entry $target -> $source"
           exit 1
+        elif [ -d $source ]; then
+          # Append a slash to the end of source to get rsync to copy the
+          # directory _to_ the target instead of _inside_ the target.
+          # (See `man rsync`'s note on a trailing slash.)
+          rsync $rsync_flags $source/ $root/$target
+        else
+          rsync $rsync_flags $source $root/$target
         fi
       fi
     done