;;; Guix Home Manager. ;;; ;;; Copyright © 2019 Julien Lepiller ;;; ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see . (define-module (home) #:use-module (guix build union) #:use-module (guix build utils) #:use-module (guix build-system trivial) #:use-module (guix gexp) #:use-module (guix licenses) #:use-module (guix packages) #:use-module (guix records) #:use-module (ice-9 match) #:use-module (home build utils) #:export (use-home-modules home home? home-data-directory home-guix-symlink home-guix-config-symlink home-local-symlink home-cache-symlink home->derivation)) (define-syntax use-home-modules (syntax-rules () ((_ modules ...) (use-modules (home modules) ...)))) (define-record-type* home make-home home? (data-directory home-data-directory) (guix-symlink home-guix-symlink (thunked) (default (string-append (home-data-directory this-record) "/.guix-profile"))) (guix-config-symlink home-guix-config-symlink (thunked) (default (string-append (home-data-directory this-record) "/.config/guix"))) (local-symlink home-local-symlink (thunked) (default (string-append (home-data-directory this-record) "/.local"))) (cache-symlink home-cache-symlink (thunked) (default (string-append (home-data-directory this-record) "/.cache"))) (configurations home-configurations (default '()))) (define (home->derivation home) (define builder (with-imported-modules '((guix build utils) (home build utils)) #~(begin (use-modules (guix build utils) (home build utils)) (mkdir-p (home-file #$output ".config")) ;; For guix (symlink #$(home-guix-config-symlink home) (home-file #$output ".config/guix")) (symlink #$(home-guix-symlink home) (home-file #$output ".guix-profile")) ;; symlink writeable directories (symlink #$(home-local-symlink home) (home-file #$output ".local")) (symlink #$(home-cache-symlink home) (home-file #$output ".cache")) ;; rest of the files (for-each (lambda (config) (with-directory-excursion config (for-each (lambda (f) (mkdir-p (home-file #$output (dirname f))) (symlink (home-file config f) (home-file #$output f))) (find-files "." ".")))) (list #$@(home-configurations home)))))) (gexp->derivation "home" builder #:substitutable? #f #:local-build? #t))