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 (guix records) |
| 26 | #:use-module (ice-9 match) |
| 27 | #:use-module (home build utils) |
| 28 | #:export (use-home-modules |
| 29 | home |
| 30 | home? |
| 31 | home-data-directory |
| 32 | home-guix-symlink |
| 33 | home-guix-config-symlink |
| 34 | home-local-symlink |
| 35 | home-cache-symlink |
| 36 | home->derivation)) |
| 37 | |
| 38 | (define-syntax use-home-modules |
| 39 | (syntax-rules () |
| 40 | ((_ modules ...) |
| 41 | (use-modules (home modules) ...)))) |
| 42 | |
| 43 | (define-record-type* <home> home |
| 44 | make-home |
| 45 | home? |
| 46 | (data-directory home-data-directory) |
| 47 | (guix-symlink home-guix-symlink (thunked) |
| 48 | (default (string-append |
| 49 | (home-data-directory this-record) |
| 50 | "/.guix-profile"))) |
| 51 | (guix-config-symlink home-guix-config-symlink (thunked) |
| 52 | (default (string-append |
| 53 | (home-data-directory this-record) |
| 54 | "/.config/guix"))) |
| 55 | (local-symlink home-local-symlink (thunked) |
| 56 | (default (string-append |
| 57 | (home-data-directory this-record) |
| 58 | "/.local"))) |
| 59 | (cache-symlink home-cache-symlink (thunked) |
| 60 | (default (string-append |
| 61 | (home-data-directory this-record) |
| 62 | "/.cache"))) |
| 63 | (configurations home-configurations |
| 64 | (default '()))) |
| 65 | |
| 66 | (define (home->derivation home) |
| 67 | (define builder |
| 68 | (with-imported-modules |
| 69 | '((guix build utils) (home build utils)) |
| 70 | #~(begin |
| 71 | (use-modules (guix build utils) (home build utils)) |
| 72 | (mkdir-p (home-file #$output ".config")) |
| 73 | ;; For guix |
| 74 | (symlink #$(home-guix-config-symlink home) (home-file #$output ".config/guix")) |
| 75 | (symlink #$(home-guix-symlink home) (home-file #$output ".guix-profile")) |
| 76 | ;; symlink writeable directories |
| 77 | (symlink #$(home-local-symlink home) (home-file #$output ".local")) |
| 78 | (symlink #$(home-cache-symlink home) (home-file #$output ".cache")) |
| 79 | ;; rest of the files |
| 80 | (for-each |
| 81 | (lambda (config) |
| 82 | (with-directory-excursion config |
| 83 | (for-each |
| 84 | (lambda (f) |
| 85 | (mkdir-p (home-file #$output (dirname f))) |
| 86 | (symlink (home-file config f) |
| 87 | (home-file #$output f))) |
| 88 | (find-files "." ".")))) |
| 89 | (list #$@(home-configurations home)))))) |
| 90 | (gexp->derivation "home" builder |
| 91 | #:substitutable? #f |
| 92 | #:local-build? #t)) |
| 93 |