guix-home-manager/home.scm

home.scm

1
;;; Guix Home Manager.
2
;;;
3
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
4
;;;
5
;;; This program is free software: you can redistribute it and/or modify
6
;;; it under the terms of the GNU General Public License as published by
7
;;; the Free Software Foundation, either version 3 of the License, or
8
;;; (at your option) any later version.
9
;;;
10
;;; This program is distributed in the hope that it will be useful,
11
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;; GNU General Public License for more details.
14
;;;
15
;;; You should have received a copy of the GNU General Public License
16
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
(define-module (home)
19
  #:use-module (guix build union)
20
  #:use-module (guix build utils)
21
  #:use-module (guix build-system trivial)
22
  #:use-module (guix gexp)
23
  #:use-module (guix licenses)
24
  #:use-module (guix packages)
25
  #:use-module (home build utils)
26
  #:export (home
27
            use-home-modules))
28
29
(define-syntax use-home-modules
30
  (syntax-rules ()
31
    ((_ modules ...)
32
     (use-modules (home modules) ...))))
33
34
(define* (home basedir inputs #:key
35
               (guix-symlink (string-append basedir "/.guix-profile"))
36
               (guix-config-symlink (string-append basedir "/.config/guix"))
37
               (local-symlink (string-append basedir "/.local"))
38
               (cache-symlink (string-append basedir "/.cache")))
39
  (define union
40
    (computed-file "home"
41
      #~(begin
42
          (use-modules (guix build union))
43
          (union-build #$output '#$inputs))
44
      #:options
45
      '(#:local-build? #t
46
        #:modules ((guix build union)))))
47
  (package
48
    (name "guix-home")
49
    (version "0")
50
    (source #f)
51
    (build-system trivial-build-system)
52
    (arguments
53
     `(#:modules ((guix build utils) (home build utils))
54
       #:builder
55
       (begin
56
         (use-modules (guix build utils) (home build utils))
57
         (mkdir-p (home-file %outputs ".config"))
58
         ;; For guix
59
         (symlink ,guix-config-symlink (home-file %outputs ".config/guix"))
60
         (symlink ,guix-symlink (home-file %outputs ".guix-profile"))
61
         ;; symlink writeable directories
62
         (symlink ,local-symlink (home-file %outputs ".local"))
63
         (symlink ,cache-symlink (home-file %outputs ".cache"))
64
         ;; rest of the files
65
         (with-directory-excursion (assoc-ref %build-inputs "union")
66
         (for-each
67
           (lambda (f)
68
             (mkdir-p (home-file %outputs (dirname f)))
69
             (symlink (string-append (assoc-ref %build-inputs "union") "/" f)
70
                      (home-file %outputs f)))
71
           (find-files "." ".*"))))))
72
    (inputs
73
     `(("union" ,union)))
74
    (home-page "")
75
    (synopsis "")
76
    (description "")
77
    (license gpl3+)))