summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-07-18 11:03:50 +0200
committerLudovic Courtès <ludo@gnu.org>2014-07-18 20:40:51 +0200
commit689142cd759457f375230a00dc719ddc00dc2fe4 (patch)
treed605e372177e1a2f3c895d5cfb86c401d3a1de38
parent1c00f83650d9412f140cce6766753a611330d6f1 (diff)
guix-register: Add '--state-directory' parameter.
* nix/guix-register/guix-register.cc (GUIX_OPT_STATE_DIRECTORY): New macro. (parse_opt): Honor it. * tests/guix-register.sh: Add test with '--state-directory'. * guix/store.scm (register-path): Add #:state-directory parameter.
-rw-r--r--guix/store.scm16
-rw-r--r--nix/guix-register/guix-register.cc13
-rw-r--r--tests/guix-register.sh72
3 files changed, 67 insertions, 34 deletions
diff --git a/guix/store.scm b/guix/store.scm
index 8c774a6db2f..79dcf22cca7 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -797,11 +797,14 @@ signing them if SIGN? is true."
797 (loop tail))))))) 797 (loop tail)))))))
798 798
799(define* (register-path path 799(define* (register-path path
800 #:key (references '()) deriver prefix) 800 #:key (references '()) deriver prefix
801 state-directory)
801 "Register PATH as a valid store file, with REFERENCES as its list of 802 "Register PATH as a valid store file, with REFERENCES as its list of
802references, and DERIVER as its deriver (.drv that led to it.) If PREFIX is 803references, and DERIVER as its deriver (.drv that led to it.) If PREFIX is
803not #f, it must be the name of the directory containing the new store to 804not #f, it must be the name of the directory containing the new store to
804initialize. Return #t on success. 805initialize; if STATE-DIRECTORY is not #f, it must be a string containing the
806absolute file name to the state directory of the store being initialized.
807Return #t on success.
805 808
806Use with care as it directly modifies the store! This is primarily meant to 809Use with care as it directly modifies the store! This is primarily meant to
807be used internally by the daemon's build hook." 810be used internally by the daemon's build hook."
@@ -809,9 +812,12 @@ be used internally by the daemon's build hook."
809 (catch 'system-error 812 (catch 'system-error
810 (lambda () 813 (lambda ()
811 (let ((pipe (apply open-pipe* OPEN_WRITE %guix-register-program 814 (let ((pipe (apply open-pipe* OPEN_WRITE %guix-register-program
812 (if prefix 815 `(,@(if prefix
813 `("--prefix" ,prefix) 816 `("--prefix" ,prefix)
814 '())))) 817 '())
818 ,@(if state-directory
819 `("--state-directory" ,state-directory)
820 '())))))
815 (and pipe 821 (and pipe
816 (begin 822 (begin
817 (format pipe "~a~%~a~%~a~%" 823 (format pipe "~a~%~a~%~a~%"
diff --git a/nix/guix-register/guix-register.cc b/nix/guix-register/guix-register.cc
index 4aee4fde34d..ed5ab23e411 100644
--- a/nix/guix-register/guix-register.cc
+++ b/nix/guix-register/guix-register.cc
@@ -56,10 +56,14 @@ from an existing store. It updates the new store's database with \
56information about which store files are valid, and what their \ 56information about which store files are valid, and what their \
57references are."; 57references are.";
58 58
59#define GUIX_OPT_STATE_DIRECTORY 1
60
59static const struct argp_option options[] = 61static const struct argp_option options[] =
60 { 62 {
61 { "prefix", 'p', "DIRECTORY", 0, 63 { "prefix", 'p', "DIRECTORY", 0,
62 "Open the store that lies under DIRECTORY" }, 64 "Open the store that lies under DIRECTORY" },
65 { "state-directory", GUIX_OPT_STATE_DIRECTORY, "DIRECTORY", 0,
66 "Use DIRECTORY as the state directory of the target store" },
63 { 0, 0, 0, 0, 0 } 67 { 0, 0, 0, 0, 0 }
64 }; 68 };
65 69
@@ -84,6 +88,15 @@ parse_opt (int key, char *arg, struct argp_state *state)
84 break; 88 break;
85 } 89 }
86 90
91 case GUIX_OPT_STATE_DIRECTORY:
92 {
93 string state_dir = canonPath (arg);
94
95 settings.nixStateDir = state_dir;
96 settings.nixDBPath = state_dir + "/db";
97 break;
98 }
99
87 case ARGP_KEY_ARG: 100 case ARGP_KEY_ARG:
88 { 101 {
89 std::ifstream *file; 102 std::ifstream *file;
diff --git a/tests/guix-register.sh b/tests/guix-register.sh
index 28b799b5c19..e258ec1244f 100644
--- a/tests/guix-register.sh
+++ b/tests/guix-register.sh
@@ -79,34 +79,48 @@ guix-register -p "$new_store" < "$closure"
79# Doing it a second time shouldn't hurt. 79# Doing it a second time shouldn't hurt.
80guix-register --prefix "$new_store" "$closure" 80guix-register --prefix "$new_store" "$closure"
81 81
82# Now make sure this is recognized as valid. 82# Same, but with the database stored in a different place.
83 83guix-register -p "$new_store" \
84NIX_STORE_DIR="$new_store_dir" 84 --state-directory "$new_store/chbouib" "$closure"
85NIX_STATE_DIR="$new_store$localstatedir"
86NIX_LOG_DIR="$new_store$localstatedir/log/guix"
87NIX_DB_DIR="$new_store$localstatedir/guix/db"
88
89export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \
90 NIX_LOG_DIR NIX_DB_DIR
91
92guix-daemon --disable-chroot &
93subdaemon_pid=$!
94exit_hook="kill $subdaemon_pid"
95 85
96final_name="$storedir/`basename $to_copy`" 86# Now make sure this is recognized as valid.
97 87
98# At this point the copy in $new_store must be valid, and unreferenced. 88ls -R "$new_store"
99# The database under $new_store uses the $final_name, but we can't use 89for state_dir in "$new_store$localstatedir/guix" "$new_store/chbouib"
100# that name in a 'valid-path?' query because 'assertStorePath' would kill 90do
101# us because of the wrong prefix. So we just list dead paths instead. 91 NIX_STORE_DIR="$new_store_dir"
102guile -c " 92 NIX_STATE_DIR="$new_store$state_dir"
103 (use-modules (guix store)) 93 NIX_LOG_DIR="$new_store$state_dir/log/guix"
104 (define s (open-connection)) 94 NIX_DB_DIR="$new_store$state_dir/db"
105 (exit (equal? (list \"$copied\") (dead-paths s)))" 95
106 96 export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \
107# When 'sqlite3' is available, check the name in the database. 97 NIX_LOG_DIR NIX_DB_DIR
108if type -P sqlite3 98
109then 99 guix-daemon --disable-chroot &
110 echo "select * from ValidPaths where path=\"$final_name\";" | \ 100 subdaemon_pid=$!
111 sqlite3 $NIX_DB_DIR/db.sqlite 101 exit_hook="kill $subdaemon_pid"
112fi 102
103 final_name="$storedir/`basename $to_copy`"
104
105 # At this point the copy in $new_store must be valid, and unreferenced.
106 # The database under $NIX_DB_DIR uses the $final_name, but we can't use
107 # that name in a 'valid-path?' query because 'assertStorePath' would kill
108 # us because of the wrong prefix. So we just list dead paths instead.
109 guile -c "
110 (use-modules (guix store))
111 (define s (open-connection))
112 (exit (equal? (list \"$copied\") (dead-paths s)))"
113
114 # Kill the daemon so we can access the database below (otherwise we may
115 # get "database is locked" errors.)
116 kill $subdaemon_pid
117 exit_hook=":"
118 while kill -0 $subdaemon_pid ; do sleep 0.5 ; done
119
120 # When 'sqlite3' is available, check the name in the database.
121 if type -P sqlite3
122 then
123 echo "select * from ValidPaths where path=\"$final_name\";" | \
124 sqlite3 "$NIX_DB_DIR/db.sqlite"
125 fi
126done