diff options
Diffstat (limited to 'gnu/services/base.scm')
| -rw-r--r-- | gnu/services/base.scm | 105 |
1 files changed, 39 insertions, 66 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm index af9dcc1bf60..0e4f6233311 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm | |||
| @@ -1881,6 +1881,34 @@ GID." | |||
| 1881 | (('gnu rest ...) #t) | 1881 | (('gnu rest ...) #t) |
| 1882 | (rest #f))) | 1882 | (rest #f))) |
| 1883 | 1883 | ||
| 1884 | (define (guix-configuration-file-installation name file) | ||
| 1885 | "Return a gexp that create a symlink '/etc/guix/NAME' to FILE." | ||
| 1886 | (with-imported-modules '((guix build utils)) | ||
| 1887 | #~(begin | ||
| 1888 | (use-modules (guix build utils)) | ||
| 1889 | |||
| 1890 | (let* ((target #$(string-append "/etc/guix/" name)) | ||
| 1891 | (install (lambda () | ||
| 1892 | ;; Installed the declared channels. | ||
| 1893 | (symlink #+file target)))) | ||
| 1894 | (catch 'system-error | ||
| 1895 | install | ||
| 1896 | (lambda args | ||
| 1897 | (cond ((= (system-error-errno args) EEXIST) | ||
| 1898 | ;; If NAME already exists, move it out of the way. | ||
| 1899 | ;; Create a backup if it's a regular file: it's likely | ||
| 1900 | ;; that the user manually defined it. | ||
| 1901 | (if (and (symbolic-link? target) | ||
| 1902 | (store-file-name? (readlink target))) | ||
| 1903 | (delete-file target) | ||
| 1904 | (rename-file target (string-append target ".bak"))) | ||
| 1905 | (install)) ;retry | ||
| 1906 | ((= (system-error-errno args) ENOENT) | ||
| 1907 | (mkdir-p "/etc/guix") | ||
| 1908 | (install)) ;retry | ||
| 1909 | (else | ||
| 1910 | (apply throw args))))))))) | ||
| 1911 | |||
| 1884 | (define (substitute-key-authorization keys guix) | 1912 | (define (substitute-key-authorization keys guix) |
| 1885 | "Return a gexp with code to register KEYS, a list of files containing 'guix | 1913 | "Return a gexp with code to register KEYS, a list of files containing 'guix |
| 1886 | archive' public keys, with GUIX." | 1914 | archive' public keys, with GUIX." |
| @@ -1907,27 +1935,7 @@ archive' public keys, with GUIX." | |||
| 1907 | (write-acl (public-keys->acl keys) | 1935 | (write-acl (public-keys->acl keys) |
| 1908 | port)))))))) | 1936 | port)))))))) |
| 1909 | 1937 | ||
| 1910 | (with-imported-modules '((guix build utils)) | 1938 | (guix-configuration-file-installation "acl" default-acl)) |
| 1911 | #~(begin | ||
| 1912 | (use-modules (guix build utils) | ||
| 1913 | (ice-9 match)) | ||
| 1914 | (define acl-file #$%acl-file) | ||
| 1915 | ;; If the ACL already exists, move it out of the way. Create a backup | ||
| 1916 | ;; if it's a regular file: it's likely that the user manually updated | ||
| 1917 | ;; it with 'guix archive --authorize'. | ||
| 1918 | (match (and=> (false-if-exception (lstat acl-file)) stat:type) | ||
| 1919 | (#f #f) ;file doesn't exist | ||
| 1920 | ('symlink ;delete symlink pointing to store, backup otherwise. | ||
| 1921 | (if (or (store-file-name? (readlink acl-file)) ;store symlink | ||
| 1922 | (not (file-exists? acl-file))) ;dangling symlink | ||
| 1923 | (delete-file acl-file) | ||
| 1924 | (rename-file acl-file (string-append acl-file ".bak")))) | ||
| 1925 | (_ ;backup | ||
| 1926 | (rename-file acl-file (string-append acl-file ".bak")))) | ||
| 1927 | (mkdir-p (dirname acl-file)) | ||
| 1928 | |||
| 1929 | ;; Installed the declared ACL. | ||
| 1930 | (symlink #+default-acl acl-file)))) | ||
| 1931 | 1939 | ||
| 1932 | (define (install-channels-file channels) | 1940 | (define (install-channels-file channels) |
| 1933 | "Return a gexp with code to install CHANNELS, a list of channels, in | 1941 | "Return a gexp with code to install CHANNELS, a list of channels, in |
| @@ -1940,23 +1948,7 @@ archive' public keys, with GUIX." | |||
| 1940 | `(list ,@(map channel->code channels)) | 1948 | `(list ,@(map channel->code channels)) |
| 1941 | port))))) | 1949 | port))))) |
| 1942 | 1950 | ||
| 1943 | (with-imported-modules '((guix build utils)) | 1951 | (guix-configuration-file-installation "channels.scm" channels-file)) |
| 1944 | #~(begin | ||
| 1945 | (use-modules (guix build utils)) | ||
| 1946 | |||
| 1947 | ;; If channels.scm already exists, move it out of the way. Create a | ||
| 1948 | ;; backup if it's a regular file: it's likely that the user | ||
| 1949 | ;; manually defined it. | ||
| 1950 | (if (file-exists? "/etc/guix/channels.scm") | ||
| 1951 | (if (and (symbolic-link? "/etc/guix/channels.scm") | ||
| 1952 | (store-file-name? (readlink "/etc/guix/channels.scm"))) | ||
| 1953 | (delete-file "/etc/guix/channels.scm") | ||
| 1954 | (rename-file "/etc/guix/channels.scm" | ||
| 1955 | "/etc/guix/channels.scm.bak")) | ||
| 1956 | (mkdir-p "/etc/guix")) | ||
| 1957 | |||
| 1958 | ;; Installed the declared channels. | ||
| 1959 | (symlink #+channels-file "/etc/guix/channels.scm")))) | ||
| 1960 | 1952 | ||
| 1961 | (define %default-authorized-guix-keys | 1953 | (define %default-authorized-guix-keys |
| 1962 | ;; List of authorized substitute keys. | 1954 | ;; List of authorized substitute keys. |
| @@ -1966,34 +1958,15 @@ archive' public keys, with GUIX." | |||
| 1966 | (define (guix-machines-files-installation machines) | 1958 | (define (guix-machines-files-installation machines) |
| 1967 | "Return a gexp to install MACHINES, a list of gexps, as | 1959 | "Return a gexp to install MACHINES, a list of gexps, as |
| 1968 | /etc/guix/machines.scm, which is used for offloading." | 1960 | /etc/guix/machines.scm, which is used for offloading." |
| 1969 | (with-imported-modules '((guix build utils)) | 1961 | (guix-configuration-file-installation |
| 1970 | #~(begin | 1962 | "machines.scm" |
| 1971 | (use-modules (guix build utils)) | 1963 | (scheme-file "machines.scm" |
| 1972 | 1964 | #~((@ (srfi srfi-1) append-map) | |
| 1973 | (define machines-file | 1965 | (lambda (entry) |
| 1974 | "/etc/guix/machines.scm") | 1966 | (if (build-machine? entry) |
| 1975 | 1967 | (list entry) | |
| 1976 | ;; If MACHINES-FILE already exists, move it out of the way. | 1968 | entry)) |
| 1977 | ;; Create a backup if it's a regular file: it's likely that the | 1969 | #$machines)))) |
| 1978 | ;; user manually updated it. | ||
| 1979 | (let ((stat (false-if-exception (lstat machines-file)))) | ||
| 1980 | (if stat | ||
| 1981 | (if (and (eq? 'symlink (stat:type stat)) | ||
| 1982 | (store-file-name? (readlink machines-file))) | ||
| 1983 | (delete-file machines-file) | ||
| 1984 | (rename-file machines-file | ||
| 1985 | (string-append machines-file ".bak"))) | ||
| 1986 | (mkdir-p (dirname machines-file)))) | ||
| 1987 | |||
| 1988 | ;; Installed the declared machines file. | ||
| 1989 | (symlink #+(scheme-file "machines.scm" | ||
| 1990 | #~((@ (srfi srfi-1) append-map) | ||
| 1991 | (lambda (entry) | ||
| 1992 | (if (build-machine? entry) | ||
| 1993 | (list entry) | ||
| 1994 | entry)) | ||
| 1995 | #$machines)) | ||
| 1996 | machines-file)))) | ||
| 1997 | 1970 | ||
| 1998 | (define (run-with-writable-store) | 1971 | (define (run-with-writable-store) |
| 1999 | "Return a wrapper that runs the given command under the specified UID and | 1972 | "Return a wrapper that runs the given command under the specified UID and |
