gnu: Add maxima.
[jackhill/guix/guix.git] / tests / guix-register.sh
CommitLineData
a7a4e6a4 1# GNU Guix --- Functional package management for GNU
349fd3b1 2# Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
a7a4e6a4
LC
3#
4# This file is part of GNU Guix.
5#
6# GNU Guix is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or (at
9# your option) any later version.
10#
11# GNU Guix is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19#
20# Test the 'guix-register' command-line utility.
21#
22
23guix-register --version
24
25new_store="t-register-$$"
26closure="t-register-closure-$$"
27rm -rf "$new_store"
28
29exit_hook=":"
30trap "chmod -R +w $new_store ; rm -rf $new_store $closure ; \$exit_hook" EXIT
31
349fd3b1
LC
32#
33# Registering items in the current store---i.e., without '--prefix'.
34#
35
36new_file="$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-guix-register-$$"
37echo "Fake store file to test registration." > "$new_file"
38
39# Register the file with zero references and no deriver.
40guix-register <<EOF
41$new_file
42
430
44EOF
45
46# Make sure it's valid, and delete it.
47guile -c "
48 (use-modules (guix store))
49 (define s (open-connection))
50 (exit (and (valid-path? s \"$new_file\")
51 (null? (references s \"$new_file\"))
52 (pair? (delete-paths s (list \"$new_file\")))))"
53
54
55#
56# Registering items in a new store, with '--prefix'.
57#
58
a7a4e6a4
LC
59mkdir -p "$new_store/$storedir"
60new_store_dir="`cd "$new_store/$storedir" ; pwd`"
61new_store="`cd "$new_store" ; pwd`"
62
63to_copy="`guix build guile-bootstrap`"
64cp -r "$to_copy" "$new_store_dir"
65copied="$new_store_dir/`basename $to_copy`"
66
67# Create a file representing a closure with zero references, and with an empty
caf96deb
LC
68# "deriver" field. Note that we give the file name as it appears in the
69# original store, and 'guix-register' translates it to match the prefix.
a7a4e6a4 70cat >> "$closure" <<EOF
caf96deb 71$to_copy
a7a4e6a4
LC
72
730
74EOF
75
76# Register it.
77guix-register -p "$new_store" < "$closure"
78
79# Doing it a second time shouldn't hurt.
caf96deb 80guix-register --prefix "$new_store" "$closure"
a7a4e6a4
LC
81
82# Now make sure this is recognized as valid.
83
84NIX_IGNORE_SYMLINK_STORE=1
85NIX_STORE_DIR="$new_store_dir"
caf96deb 86NIX_STATE_DIR="$new_store$localstatedir"
aa2480e5
LC
87NIX_LOG_DIR="$new_store$localstatedir/log/guix"
88NIX_DB_DIR="$new_store$localstatedir/guix/db"
a7a4e6a4 89
caf96deb 90export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \
a7a4e6a4
LC
91 NIX_LOG_DIR NIX_DB_DIR
92
93guix-daemon --disable-chroot &
94subdaemon_pid=$!
95exit_hook="kill $subdaemon_pid"
96
caf96deb
LC
97final_name="$storedir/`basename $to_copy`"
98
a7a4e6a4 99# At this point the copy in $new_store must be valid, and unreferenced.
caf96deb
LC
100# The database under $new_store uses the $final_name, but we can't use
101# that name in a 'valid-path?' query because 'assertStorePath' would kill
102# us because of the wrong prefix. So we just list dead paths instead.
a7a4e6a4
LC
103guile -c "
104 (use-modules (guix store))
105 (define s (open-connection))
caf96deb
LC
106 (exit (equal? (list \"$copied\") (dead-paths s)))"
107
108# When 'sqlite3' is available, check the name in the database.
109if type -P sqlite3
110then
111 echo "select * from ValidPaths where path=\"$final_name\";" | \
112 sqlite3 $NIX_DB_DIR/db.sqlite
113fi