# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
#
-# Test the daemon and its interaction with 'guix substitute-binary'.
+# Test 'guix system', mostly error reporting.
#
set -e
tmpfile="t-guix-system-$$"
errorfile="t-guix-system-error-$$"
-trap 'rm -f "$tmpfile" "$errorfile"' EXIT
+
+# Note: This directory is chosen outside $builddir so that relative file name
+# canonicalization doesn't mess up with 'current-source-directory', used by
+# 'local-file' ('load' forces 'relative' for
+# %FILE-PORT-NAME-CANONICALIZATION.)
+tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$"
+mkdir "$tmpdir"
+
+trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
# Reporting of syntax errors.
fi
-# Reporting of duplicate service identifiers.
+# Reporting of unbound variables.
cat > "$tmpfile" <<EOF
-(use-modules (gnu))
-(use-service-modules networking)
+(use-modules (gnu)) ; 1
+(use-service-modules networking) ; 2
-(operating-system
+(operating-system ; 4
+ (host-name "antelope") ; 5
+ (timezone "Europe/Paris") ; 6
+ (locale "en_US.UTF-8") ; 7
+
+ (bootloader (GRUB-config (device "/dev/sdX"))) ; 9
+ (file-systems (cons (file-system
+ (device "root")
+ (title 'label)
+ (mount-point "/")
+ (type "ext4"))
+ %base-file-systems)))
+EOF
+
+if guix system build "$tmpfile" -n 2> "$errorfile"
+then false
+else
+ grep "$tmpfile:9:.*[Uu]nbound variable.*GRUB-config" "$errorfile"
+fi
+
+OS_BASE='
(host-name "antelope")
(timezone "Europe/Paris")
(locale "en_US.UTF-8")
(bootloader (grub-configuration (device "/dev/sdX")))
(file-systems (cons (file-system
(device "root")
- (title 'label)
+ (title (string->symbol "label"))
(mount-point "/")
(type "ext4"))
%base-file-systems))
+'
+# Reporting of duplicate service identifiers.
+
+cat > "$tmpfile" <<EOF
+(use-modules (gnu))
+(use-service-modules networking)
+
+(operating-system
+ $OS_BASE
(services (cons* (dhcp-client-service)
(dhcp-client-service) ;twice!
%base-services)))
else
grep "service 'networking'.*more than once" "$errorfile"
fi
+
+# Reporting unmet shepherd requirements.
+
+cat > "$tmpfile" <<EOF
+(use-modules (gnu) (gnu services shepherd))
+(use-service-modules networking)
+
+(define buggy-service-type
+ (shepherd-service-type
+ 'buggy
+ (lambda _
+ (shepherd-service
+ (provision '(buggy!))
+ (requirement '(does-not-exist))
+ (start #t)))))
+
+(operating-system
+ $OS_BASE
+ (services (cons (service buggy-service-type #t)
+ %base-services)))
+EOF
+
+if guix system build "$tmpfile" 2> "$errorfile"
+then
+ exit 1
+else
+ grep "service 'buggy!'.*'does-not-exist'.*undefined" "$errorfile"
+fi
+
+# Reporting inconsistent user accounts.
+
+make_user_config ()
+{
+ cat > "$tmpfile" <<EOF
+(use-modules (gnu))
+(use-service-modules networking)
+
+(operating-system
+ (host-name "antelope")
+ (timezone "Europe/Paris")
+ (locale "en_US.UTF-8")
+
+ (bootloader (grub-configuration (device "/dev/sdX")))
+ (file-systems (cons (file-system
+ (device "root")
+ (title 'label)
+ (mount-point "/")
+ (type "ext4"))
+ %base-file-systems))
+ (users (list (user-account
+ (name "dave")
+ (home-directory "/home/dave")
+ (group "$1")
+ (supplementary-groups '("$2"))))))
+EOF
+}
+
+make_user_config "users" "wheel"
+guix system build "$tmpfile" -n # succeeds
+
+guix system build "$tmpfile" -d # succeeds
+guix system build "$tmpfile" -d | grep '\.drv$'
+
+guix system vm "$tmpfile" -d # succeeds
+guix system vm "$tmpfile" -d | grep '\.drv$'
+
+make_user_config "group-that-does-not-exist" "users"
+if guix system build "$tmpfile" -n 2> "$errorfile"
+then false
+else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
+
+make_user_config "users" "group-that-does-not-exist"
+if guix system build "$tmpfile" -n 2> "$errorfile"
+then false
+else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
+
+# Try 'local-file' and relative file name resolution.
+
+cat > "$tmpdir/config.scm"<<EOF
+(use-modules (gnu))
+(use-service-modules networking)
+
+(operating-system
+ $OS_BASE
+ (services (cons (tor-service (local-file "my-torrc"))
+ %base-services)))
+EOF
+
+cat > "$tmpdir/my-torrc"<<EOF
+# This is an example file.
+EOF
+
+# In both cases 'my-torrc' should be properly resolved.
+guix system build "$tmpdir/config.scm" -n
+(cd "$tmpdir"; guix system build "config.scm" -n)