Mirror of GNU Guix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1365 lines
57 KiB

monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
9 years ago
monads: Move '%store-monad' and related procedures where they belong. This turns (guix monads) into a generic module for monads, and moves the store monad and related monadic procedures in their corresponding module. * guix/monads.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file, package-file, package->derivation, package->cross-derivation, origin->derivation, imported-modules, compiled, modules, built-derivations, run-with-store): Move to... * guix/store.scm (store-return, store-bind, %store-monad, store-lift, text-file, interned-file): ... here. (%guile-for-build): New variable. (run-with-store): Moved from monads.scm. Remove default value for #:guile-for-build. * guix/packages.scm (default-guile): Export. (set-guile-for-build): New procedure. (package-file, package->derivation, package->cross-derivation, origin->derivation): Moved from monads.scm. * guix/derivations.scm (%guile-for-build): Remove. (imported-modules): Rename to... (%imported-modules): ... this. (compiled-modules): Rename to... (%compiled-modules): ... this. (built-derivations, imported-modules, compiled-modules): New procedures. * gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm, gnu/services/dmd.scm, gnu/services/networking.scm, gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm, gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm, guix/gexp.scm, guix/git-download.scm, guix/profiles.scm, guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly. * guix/monad-repl.scm (default-guile-derivation): New procedure. (store-monad-language, run-in-store): Use it. * build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit 'set-guile-for-build' call. * guix/scripts/archive.scm (derivation-from-expression): Likewise. * guix/scripts/build.scm (options/resolve-packages): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * doc/guix.texi (The Store Monad): Adjust module names accordingly.
7 years ago
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix derivations)
  19. #:use-module (srfi srfi-1)
  20. #:use-module (srfi srfi-9)
  21. #:use-module (srfi srfi-9 gnu)
  22. #:use-module (srfi srfi-26)
  23. #:use-module (srfi srfi-34)
  24. #:use-module (srfi srfi-35)
  25. #:use-module (rnrs io ports)
  26. #:use-module (rnrs bytevectors)
  27. #:use-module (ice-9 match)
  28. #:use-module (ice-9 rdelim)
  29. #:use-module (ice-9 vlist)
  30. #:use-module (guix store)
  31. #:use-module (guix utils)
  32. #:use-module (guix monads)
  33. #:use-module (guix hash)
  34. #:use-module (guix base32)
  35. #:use-module (guix records)
  36. #:use-module (guix sets)
  37. #:export (<derivation>
  38. derivation?
  39. derivation-outputs
  40. derivation-inputs
  41. derivation-sources
  42. derivation-system
  43. derivation-builder
  44. derivation-builder-arguments
  45. derivation-builder-environment-vars
  46. derivation-file-name
  47. derivation-prerequisites
  48. derivation-prerequisites-to-build
  49. <derivation-output>
  50. derivation-output?
  51. derivation-output-path
  52. derivation-output-hash-algo
  53. derivation-output-hash
  54. derivation-output-recursive?
  55. <derivation-input>
  56. derivation-input?
  57. derivation-input-path
  58. derivation-input-sub-derivations
  59. derivation-input-output-paths
  60. valid-derivation-input?
  61. &derivation-error
  62. derivation-error?
  63. derivation-error-derivation
  64. &derivation-missing-output-error
  65. derivation-missing-output-error?
  66. derivation-missing-output
  67. derivation-name
  68. derivation-output-names
  69. fixed-output-derivation?
  70. offloadable-derivation?
  71. substitutable-derivation?
  72. substitution-oracle
  73. derivation-hash
  74. read-derivation
  75. write-derivation
  76. derivation->output-path
  77. derivation->output-paths
  78. derivation-path->output-path
  79. derivation-path->output-paths
  80. derivation
  81. graft
  82. graft?
  83. graft-origin
  84. graft-replacement
  85. graft-origin-output
  86. graft-replacement-output
  87. graft-derivation
  88. map-derivation
  89. build-derivations
  90. built-derivations
  91. %graft?
  92. set-grafting
  93. build-expression->derivation)
  94. ;; Re-export it from here for backward compatibility.
  95. #:re-export (%guile-for-build))
  96. ;;;
  97. ;;; Error conditions.
  98. ;;;
  99. (define-condition-type &derivation-error &nix-error
  100. derivation-error?
  101. (derivation derivation-error-derivation))
  102. (define-condition-type &derivation-missing-output-error &derivation-error
  103. derivation-missing-output-error?
  104. (output derivation-missing-output))
  105. ;;;
  106. ;;; Nix derivations, as implemented in Nix's `derivations.cc'.
  107. ;;;
  108. (define-record-type <derivation>
  109. (make-derivation outputs inputs sources system builder args env-vars
  110. file-name)
  111. derivation?
  112. (outputs derivation-outputs) ; list of name/<derivation-output> pairs
  113. (inputs derivation-inputs) ; list of <derivation-input>
  114. (sources derivation-sources) ; list of store paths
  115. (system derivation-system) ; string
  116. (builder derivation-builder) ; store path
  117. (args derivation-builder-arguments) ; list of strings
  118. (env-vars derivation-builder-environment-vars) ; list of name/value pairs
  119. (file-name derivation-file-name)) ; the .drv file name
  120. (define-record-type <derivation-output>
  121. (make-derivation-output path hash-algo hash recursive?)
  122. derivation-output?
  123. (path derivation-output-path) ; store path
  124. (hash-algo derivation-output-hash-algo) ; symbol | #f
  125. (hash derivation-output-hash) ; bytevector | #f
  126. (recursive? derivation-output-recursive?)) ; Boolean
  127. (define-record-type <derivation-input>
  128. (make-derivation-input path sub-derivations)
  129. derivation-input?
  130. (path derivation-input-path) ; store path
  131. (sub-derivations derivation-input-sub-derivations)) ; list of strings
  132. (set-record-type-printer! <derivation>
  133. (lambda (drv port)
  134. (format port "#<derivation ~a => ~a ~a>"
  135. (derivation-file-name drv)
  136. (string-join
  137. (map (match-lambda
  138. ((_ . output)
  139. (derivation-output-path output)))
  140. (derivation-outputs drv)))
  141. (number->string (object-address drv) 16))))
  142. (define (derivation-name drv)
  143. "Return the base name of DRV."
  144. (let ((base (store-path-package-name (derivation-file-name drv))))
  145. (string-drop-right base 4)))
  146. (define (derivation-output-names drv)
  147. "Return the names of the outputs of DRV."
  148. (match (derivation-outputs drv)
  149. (((names . _) ...)
  150. names)))
  151. (define (fixed-output-derivation? drv)
  152. "Return #t if DRV is a fixed-output derivation, such as the result of a
  153. download with a fixed hash (aka. `fetchurl')."
  154. (match drv
  155. (($ <derivation>
  156. (("out" . ($ <derivation-output> _ (? symbol?) (? bytevector?)))))
  157. #t)
  158. (_ #f)))
  159. (define (derivation-input-output-paths input)
  160. "Return the list of output paths corresponding to INPUT, a
  161. <derivation-input>."
  162. (match input
  163. (($ <derivation-input> path sub-drvs)
  164. (map (cut derivation-path->output-path path <>)
  165. sub-drvs))))
  166. (define (valid-derivation-input? store input)
  167. "Return true if INPUT is valid--i.e., if all the outputs it requests are in
  168. the store."
  169. (every (cut valid-path? store <>)
  170. (derivation-input-output-paths input)))
  171. (define* (derivation-prerequisites drv #:optional (cut? (const #f)))
  172. "Return the list of derivation-inputs required to build DRV, recursively.
  173. CUT? is a predicate that is passed a derivation-input and returns true to
  174. eliminate the given input and its dependencies from the search. An example of
  175. search a predicate is 'valid-derivation-input?'; when it is used as CUT?, the
  176. result is the set of prerequisites of DRV not already in valid."
  177. (let loop ((drv drv)
  178. (result '())
  179. (input-set (set)))
  180. (let ((inputs (remove (lambda (input)
  181. (or (set-contains? input-set input)
  182. (cut? input)))
  183. (derivation-inputs drv))))
  184. (fold2 loop
  185. (append inputs result)
  186. (fold set-insert input-set inputs)
  187. (map (lambda (i)
  188. (call-with-input-file (derivation-input-path i)
  189. read-derivation))
  190. inputs)))))
  191. (define (offloadable-derivation? drv)
  192. "Return true if DRV can be offloaded, false otherwise."
  193. (match (assoc "preferLocalBuild"
  194. (derivation-builder-environment-vars drv))
  195. (("preferLocalBuild" . "1") #f)
  196. (_ #t)))
  197. (define (substitutable-derivation? drv)
  198. "Return #t if DRV can be substituted."
  199. (match (assoc "allowSubstitutes"
  200. (derivation-builder-environment-vars drv))
  201. (("allowSubstitutes" . value)
  202. (string=? value "1"))
  203. (_ #t)))
  204. (define (derivation-output-paths drv sub-drvs)
  205. "Return the output paths of outputs SUB-DRVS of DRV."
  206. (match drv
  207. (($ <derivation> outputs)
  208. (map (lambda (sub-drv)
  209. (derivation-output-path (assoc-ref outputs sub-drv)))
  210. sub-drvs))))
  211. (define* (substitution-oracle store drv
  212. #:key (mode (build-mode normal)))
  213. "Return a one-argument procedure that, when passed a store file name,
  214. returns #t if it's substitutable and #f otherwise. The returned procedure
  215. knows about all substitutes for all the derivations listed in DRV, *except*
  216. those that are already valid (that is, it won't bother checking whether an
  217. item is substitutable if it's already on disk); it also knows about their
  218. prerequisites, unless they are themselves substitutable.
  219. Creating a single oracle (thus making a single 'substitutable-paths' call) and
  220. reusing it is much more efficient than calling 'has-substitutes?' or similar
  221. repeatedly, because it avoids the costs associated with launching the
  222. substituter many times."
  223. (define valid?
  224. (cut valid-path? store <>))
  225. (define valid-input?
  226. (cut valid-derivation-input? store <>))
  227. (define (dependencies drv)
  228. ;; Skip prerequisite sub-trees of DRV whose root is valid. This allows us
  229. ;; to ask the substituter for just as much as needed, instead of asking it
  230. ;; for the whole world, which can be significantly faster when substitute
  231. ;; info is not already in cache.
  232. (append-map derivation-input-output-paths
  233. (derivation-prerequisites drv valid-input?)))
  234. (let* ((paths (delete-duplicates
  235. (concatenate
  236. (fold (lambda (drv result)
  237. (let ((self (match (derivation->output-paths drv)
  238. (((names . paths) ...)
  239. paths))))
  240. (cond ((eqv? mode (build-mode check))
  241. (cons (dependencies drv) result))
  242. ((every valid? self)
  243. result)
  244. (else
  245. (cons* self (dependencies drv) result)))))
  246. '()
  247. drv))))
  248. (subst (list->set (substitutable-paths store paths))))
  249. (cut set-contains? subst <>)))
  250. (define* (derivation-prerequisites-to-build store drv
  251. #:key
  252. (mode (build-mode normal))
  253. (outputs
  254. (derivation-output-names drv))
  255. (substitutable?
  256. (substitution-oracle store
  257. (list drv)
  258. #:mode mode)))
  259. "Return two values: the list of derivation-inputs required to build the
  260. OUTPUTS of DRV and not already available in STORE, recursively, and the list
  261. of required store paths that can be substituted. SUBSTITUTABLE? must be a
  262. one-argument procedure similar to that returned by 'substitution-oracle'."
  263. (define built?
  264. (cut valid-path? store <>))
  265. (define input-built?
  266. (compose (cut any built? <>) derivation-input-output-paths))
  267. (define input-substitutable?
  268. ;; Return true if and only if all of SUB-DRVS are subsitutable. If at
  269. ;; least one is missing, then everything must be rebuilt.
  270. (compose (cut every substitutable? <>) derivation-input-output-paths))
  271. (define (derivation-built? drv* sub-drvs)
  272. ;; In 'check' mode, assume that DRV is not built.
  273. (and (not (and (eqv? mode (build-mode check))
  274. (eq? drv* drv)))
  275. (every built? (derivation-output-paths drv* sub-drvs))))
  276. (define (derivation-substitutable? drv sub-drvs)
  277. (and (substitutable-derivation? drv)
  278. (every substitutable? (derivation-output-paths drv sub-drvs))))
  279. (let loop ((drv drv)
  280. (sub-drvs outputs)
  281. (build '())
  282. (substitute '()))
  283. (cond ((derivation-built? drv sub-drvs)
  284. (values build substitute))
  285. ((derivation-substitutable? drv sub-drvs)
  286. (values build
  287. (append (derivation-output-paths drv sub-drvs)
  288. substitute)))
  289. (else
  290. (let ((build (if (substitutable-derivation? drv)
  291. build
  292. (cons (make-derivation-input
  293. (derivation-file-name drv) sub-drvs)
  294. build)))
  295. (inputs (remove (lambda (i)
  296. (or (member i build) ; XXX: quadratic
  297. (input-built? i)
  298. (input-substitutable? i)))
  299. (derivation-inputs drv))))
  300. (fold2 loop
  301. (append inputs build)
  302. (append (append-map (lambda (input)
  303. (if (and (not (input-built? input))
  304. (input-substitutable? input))
  305. (derivation-input-output-paths
  306. input)
  307. '()))
  308. (derivation-inputs drv))
  309. substitute)
  310. (map (lambda (i)
  311. (call-with-input-file (derivation-input-path i)
  312. read-derivation))
  313. inputs)
  314. (map derivation-input-sub-derivations inputs)))))))
  315. (define (%read-derivation drv-port)
  316. ;; Actually read derivation from DRV-PORT.
  317. (define comma (string->symbol ","))
  318. (define (ununquote x)
  319. (match x
  320. (('unquote x) (ununquote x))
  321. ((x ...) (map ununquote x))
  322. (_ x)))
  323. (define (outputs->alist x)
  324. (fold-right (lambda (output result)
  325. (match output
  326. ((name path "" "")
  327. (alist-cons name
  328. (make-derivation-output path #f #f #f)
  329. result))
  330. ((name path hash-algo hash)
  331. ;; fixed-output
  332. (let* ((rec? (string-prefix? "r:" hash-algo))
  333. (algo (string->symbol
  334. (if rec?
  335. (string-drop hash-algo 2)
  336. hash-algo)))
  337. (hash (base16-string->bytevector hash)))
  338. (alist-cons name
  339. (make-derivation-output path algo
  340. hash rec?)
  341. result)))))
  342. '()
  343. x))
  344. (define (make-input-drvs x)
  345. (fold-right (lambda (input result)
  346. (match input
  347. ((path (sub-drvs ...))
  348. (cons (make-derivation-input path sub-drvs)
  349. result))))
  350. '()
  351. x))
  352. ;; The contents of a derivation are typically ASCII, but choosing
  353. ;; UTF-8 allows us to take the fast path for Guile's `scm_getc'.
  354. (set-port-encoding! drv-port "UTF-8")
  355. (let loop ((exp (read drv-port))
  356. (result '()))
  357. (match exp
  358. ((? eof-object?)
  359. (let ((result (reverse result)))
  360. (match result
  361. (('Derive ((outputs ...) (input-drvs ...)
  362. (input-srcs ...)
  363. (? string? system)
  364. (? string? builder)
  365. ((? string? args) ...)
  366. ((var value) ...)))
  367. (make-derivation (outputs->alist outputs)
  368. (make-input-drvs input-drvs)
  369. input-srcs
  370. system builder args
  371. (fold-right alist-cons '() var value)
  372. (port-filename drv-port)))
  373. (_
  374. (error "failed to parse derivation" drv-port result)))))
  375. ((? (cut eq? <> comma))
  376. (loop (read drv-port) result))
  377. (_
  378. (loop (read drv-port)
  379. (cons (ununquote exp) result))))))
  380. (define read-derivation
  381. (let ((cache (make-weak-value-hash-table 200)))
  382. (lambda (drv-port)
  383. "Read the derivation from DRV-PORT and return the corresponding
  384. <derivation> object."
  385. ;; Memoize that operation because `%read-derivation' is quite expensive,
  386. ;; and because the same argument is read more than 15 times on average
  387. ;; during something like (package-derivation s gdb).
  388. (let ((file (and=> (port-filename drv-port) basename)))
  389. (or (and file (hash-ref cache file))
  390. (let ((drv (%read-derivation drv-port)))
  391. (hash-set! cache file drv)
  392. drv))))))
  393. (define-inlinable (write-sequence lst write-item port)
  394. ;; Write each element of LST with WRITE-ITEM to PORT, separating them with a
  395. ;; comma.
  396. (match lst
  397. (()
  398. #t)
  399. ((prefix (... ...) last)
  400. (for-each (lambda (item)
  401. (write-item item port)
  402. (display "," port))
  403. prefix)
  404. (write-item last port))))
  405. (define-inlinable (write-list lst write-item port)
  406. ;; Write LST as a derivation list to PORT, using WRITE-ITEM to write each
  407. ;; element.
  408. (display "[" port)
  409. (write-sequence lst write-item port)
  410. (display "]" port))
  411. (define-inlinable (write-tuple lst write-item port)
  412. ;; Same, but write LST as a tuple.
  413. (display "(" port)
  414. (write-sequence lst write-item port)
  415. (display ")" port))
  416. (define (write-derivation drv port)
  417. "Write the ATerm-like serialization of DRV to PORT. See Section 2.4 of
  418. Eelco Dolstra's PhD dissertation for an overview of a previous version of
  419. that form."
  420. ;; Make sure we're using the faster implementation.
  421. (define format simple-format)
  422. (define (write-string-list lst)
  423. (write-list lst write port))
  424. (define (coalesce-duplicate-inputs inputs)
  425. ;; Return a list of inputs, such that when INPUTS contains the same DRV
  426. ;; twice, they are coalesced, with their sub-derivations merged. This is
  427. ;; needed because Nix itself keeps only one of them.
  428. (fold (lambda (input result)
  429. (match input
  430. (($ <derivation-input> path sub-drvs)
  431. ;; XXX: quadratic
  432. (match (find (match-lambda
  433. (($ <derivation-input> p s)
  434. (string=? p path)))
  435. result)
  436. (#f
  437. (cons input result))
  438. ((and dup ($ <derivation-input> _ sub-drvs2))
  439. ;; Merge DUP with INPUT.
  440. (let ((sub-drvs (delete-duplicates
  441. (append sub-drvs sub-drvs2))))
  442. (cons (make-derivation-input path sub-drvs)
  443. (delq dup result))))))))
  444. '()
  445. inputs))
  446. (define (write-output output port)
  447. (match output
  448. ((name . ($ <derivation-output> path hash-algo hash recursive?))
  449. (write-tuple (list name path
  450. (if hash-algo
  451. (string-append (if recursive? "r:" "")
  452. (symbol->string hash-algo))
  453. "")
  454. (or (and=> hash bytevector->base16-string)
  455. ""))
  456. write
  457. port))))
  458. (define (write-input input port)
  459. (match input
  460. (($ <derivation-input> path sub-drvs)
  461. (display "(" port)
  462. (write path port)
  463. (display "," port)
  464. (write-string-list (sort sub-drvs string<?))
  465. (display ")" port))))
  466. (define (write-env-var env-var port)
  467. (match env-var
  468. ((name . value)
  469. (display "(" port)
  470. (write name port)
  471. (display "," port)
  472. (write value port)
  473. (display ")" port))))
  474. ;; Note: lists are sorted alphabetically, to conform with the behavior of
  475. ;; C++ `std::map' in Nix itself.
  476. (match drv
  477. (($ <derivation> outputs inputs sources
  478. system builder args env-vars)
  479. (display "Derive(" port)
  480. (write-list (sort outputs
  481. (lambda (o1 o2)
  482. (string<? (car o1) (car o2))))
  483. write-output
  484. port)
  485. (display "," port)
  486. (write-list (sort (coalesce-duplicate-inputs inputs)
  487. (lambda (i1 i2)
  488. (string<? (derivation-input-path i1)
  489. (derivation-input-path i2))))
  490. write-input
  491. port)
  492. (display "," port)
  493. (write-string-list (sort sources string<?))
  494. (format port ",~s,~s," system builder)
  495. (write-string-list args)
  496. (display "," port)
  497. (write-list (sort env-vars
  498. (lambda (e1 e2)
  499. (string<? (car e1) (car e2))))
  500. write-env-var
  501. port)
  502. (display ")" port))))
  503. (define derivation->string
  504. (memoize
  505. (lambda (drv)
  506. "Return the external representation of DRV as a string."
  507. (with-fluids ((%default-port-encoding "UTF-8"))
  508. (call-with-output-string
  509. (cut write-derivation drv <>))))))
  510. (define* (derivation->output-path drv #:optional (output "out"))
  511. "Return the store path of its output OUTPUT. Raise a
  512. '&derivation-missing-output-error' condition if OUTPUT is not an output of
  513. DRV."
  514. (let ((output* (assoc-ref (derivation-outputs drv) output)))
  515. (if output*
  516. (derivation-output-path output*)
  517. (raise (condition (&derivation-missing-output-error
  518. (derivation drv)
  519. (output output)))))))
  520. (define (derivation->output-paths drv)
  521. "Return the list of name/path pairs of the outputs of DRV."
  522. (map (match-lambda
  523. ((name . output)
  524. (cons name (derivation-output-path output))))
  525. (derivation-outputs drv)))
  526. (define derivation-path->output-path
  527. ;; This procedure is called frequently, so memoize it.
  528. (memoize
  529. (lambda* (path #:optional (output "out"))
  530. "Read the derivation from PATH (`/gnu/store/xxx.drv'), and return the store
  531. path of its output OUTPUT."
  532. (derivation->output-path (call-with-input-file path read-derivation)
  533. output))))
  534. (define (derivation-path->output-paths path)
  535. "Read the derivation from PATH (`/gnu/store/xxx.drv'), and return the
  536. list of name/path pairs of its outputs."
  537. (derivation->output-paths (call-with-input-file path read-derivation)))
  538. ;;;
  539. ;;; Derivation primitive.
  540. ;;;
  541. (define (compressed-hash bv size) ; `compressHash'
  542. "Given the hash stored in BV, return a compressed version thereof that fits
  543. in SIZE bytes."
  544. (define new (make-bytevector size 0))
  545. (define old-size (bytevector-length bv))
  546. (let loop ((i 0))
  547. (if (= i old-size)
  548. new
  549. (let* ((j (modulo i size))
  550. (o (bytevector-u8-ref new j)))
  551. (bytevector-u8-set! new j
  552. (logxor o (bytevector-u8-ref bv i)))
  553. (loop (+ 1 i))))))
  554. (define derivation-path->base16-hash
  555. (memoize
  556. (lambda (file)
  557. "Return a string containing the base16 representation of the hash of the
  558. derivation at FILE."
  559. (call-with-input-file file
  560. (compose bytevector->base16-string
  561. derivation-hash
  562. read-derivation)))))
  563. (define derivation-hash ; `hashDerivationModulo' in derivations.cc
  564. (memoize
  565. (lambda (drv)
  566. "Return the hash of DRV, modulo its fixed-output inputs, as a bytevector."
  567. (match drv
  568. (($ <derivation> ((_ . ($ <derivation-output> path
  569. (? symbol? hash-algo) (? bytevector? hash)
  570. (? boolean? recursive?)))))
  571. ;; A fixed-output derivation.
  572. (sha256
  573. (string->utf8
  574. (string-append "fixed:out:"
  575. (if recursive? "r:" "")
  576. (symbol->string hash-algo)
  577. ":" (bytevector->base16-string hash)
  578. ":" path))))
  579. (($ <derivation> outputs inputs sources
  580. system builder args env-vars)
  581. ;; A regular derivation: replace the path of each input with that
  582. ;; input's hash; return the hash of serialization of the resulting
  583. ;; derivation.
  584. (let* ((inputs (map (match-lambda
  585. (($ <derivation-input> path sub-drvs)
  586. (let ((hash (derivation-path->base16-hash path)))
  587. (make-derivation-input hash sub-drvs))))
  588. inputs))
  589. (drv (make-derivation outputs inputs sources
  590. system builder args env-vars
  591. #f)))
  592. ;; XXX: At this point this remains faster than `port-sha256', because
  593. ;; the SHA256 port's `write' method gets called for every single
  594. ;; character.
  595. (sha256
  596. (string->utf8 (derivation->string drv)))))))))
  597. (define (store-path type hash name) ; makeStorePath
  598. "Return the store path for NAME/HASH/TYPE."
  599. (let* ((s (string-append type ":sha256:"
  600. (bytevector->base16-string hash) ":"
  601. (%store-prefix) ":" name))
  602. (h (sha256 (string->utf8 s)))
  603. (c (compressed-hash h 20)))
  604. (string-append (%store-prefix) "/"
  605. (bytevector->nix-base32-string c) "-"
  606. name)))
  607. (define (output-path output hash name) ; makeOutputPath
  608. "Return an output path for OUTPUT (the name of the output as a string) of
  609. the derivation called NAME with hash HASH."
  610. (store-path (string-append "output:" output) hash
  611. (if (string=? output "out")
  612. name
  613. (string-append name "-" output))))
  614. (define (fixed-output-path output hash-algo hash recursive? name)
  615. "Return an output path for the fixed output OUTPUT defined by HASH of type
  616. HASH-ALGO, of the derivation NAME. RECURSIVE? has the same meaning as for
  617. 'add-to-store'."
  618. (if (and recursive? (eq? hash-algo 'sha256))
  619. (store-path "source" hash name)
  620. (let ((tag (string-append "fixed:" output ":"
  621. (if recursive? "r:" "")
  622. (symbol->string hash-algo) ":"
  623. (bytevector->base16-string hash) ":")))
  624. (store-path (string-append "output:" output)
  625. (sha256 (string->utf8 tag))
  626. name))))
  627. (define* (derivation store name builder args
  628. #:key
  629. (system (%current-system)) (env-vars '())
  630. (inputs '()) (outputs '("out"))
  631. hash hash-algo recursive?
  632. references-graphs allowed-references
  633. leaked-env-vars local-build?
  634. (substitutable? #t))
  635. "Build a derivation with the given arguments, and return the resulting
  636. <derivation> object. When HASH and HASH-ALGO are given, a
  637. fixed-output derivation is created---i.e., one whose result is known in
  638. advance, such as a file download. If, in addition, RECURSIVE? is true, then
  639. that fixed output may be an executable file or a directory and HASH must be
  640. the hash of an archive containing this output.
  641. When REFERENCES-GRAPHS is true, it must be a list of file name/store path
  642. pairs. In that case, the reference graph of each store path is exported in
  643. the build environment in the corresponding file, in a simple text format.
  644. When ALLOWED-REFERENCES is true, it must be a list of store items or outputs
  645. that the derivation's output may refer to.
  646. When LEAKED-ENV-VARS is true, it must be a list of strings denoting
  647. environment variables that are allowed to \"leak\" from the daemon's
  648. environment to the build environment. This is only applicable to fixed-output
  649. derivations--i.e., when HASH is true. The main use is to allow variables such
  650. as \"http_proxy\" to be passed to derivations that download files.
  651. When LOCAL-BUILD? is true, declare that the derivation is not a good candidate
  652. for offloading and should rather be built locally. This is the case for small
  653. derivations where the costs of data transfers would outweigh the benefits.
  654. When SUBSTITUTABLE? is false, declare that substitutes of the derivation's
  655. output should not be used."
  656. (define (add-output-paths drv)
  657. ;; Return DRV with an actual store path for each of its output and the
  658. ;; corresponding environment variable.
  659. (match drv
  660. (($ <derivation> outputs inputs sources
  661. system builder args env-vars)
  662. (let* ((drv-hash (derivation-hash drv))
  663. (outputs (map (match-lambda
  664. ((output-name . ($ <derivation-output>
  665. _ algo hash rec?))
  666. (let ((path (if hash
  667. (fixed-output-path output-name
  668. algo hash
  669. rec? name)
  670. (output-path output-name
  671. drv-hash name))))
  672. (cons output-name
  673. (make-derivation-output path algo
  674. hash rec?)))))
  675. outputs)))
  676. (make-derivation outputs inputs sources system builder args
  677. (map (match-lambda
  678. ((name . value)
  679. (cons name
  680. (or (and=> (assoc-ref outputs name)
  681. derivation-output-path)
  682. value))))
  683. env-vars)
  684. #f)))))
  685. (define (user+system-env-vars)
  686. ;; Some options are passed to the build daemon via the env. vars of
  687. ;; derivations (urgh!). We hide that from our API, but here is the place
  688. ;; where we kludgify those options.
  689. (let ((env-vars `(,@(if local-build?
  690. `(("preferLocalBuild" . "1"))
  691. '())
  692. ,@(if (not substitutable?)
  693. `(("allowSubstitutes" . "0"))
  694. '())
  695. ,@(if allowed-references
  696. `(("allowedReferences"
  697. . ,(string-join allowed-references)))
  698. '())
  699. ,@(if leaked-env-vars
  700. `(("impureEnvVars"
  701. . ,(string-join leaked-env-vars)))
  702. '())
  703. ,@env-vars)))
  704. (match references-graphs
  705. (((file . path) ...)
  706. (let ((value (map (cut string-append <> " " <>)
  707. file path)))
  708. ;; XXX: This all breaks down if an element of FILE or PATH contains
  709. ;; white space.
  710. `(("exportReferencesGraph" . ,(string-join value " "))
  711. ,@env-vars)))
  712. (#f
  713. env-vars))))
  714. (define (env-vars-with-empty-outputs env-vars)
  715. ;; Return a variant of ENV-VARS where each OUTPUTS is associated with an
  716. ;; empty string, even outputs that do not appear in ENV-VARS.
  717. (let ((e (map (match-lambda
  718. ((name . val)
  719. (if (member name outputs)
  720. (cons name "")
  721. (cons name val))))
  722. env-vars)))
  723. (fold (lambda (output-name env-vars)
  724. (if (assoc output-name env-vars)
  725. env-vars
  726. (append env-vars `((,output-name . "")))))
  727. e
  728. outputs)))
  729. (define (set-file-name drv file)
  730. ;; Set FILE as the 'file-name' field of DRV.
  731. (match drv
  732. (($ <derivation> outputs inputs sources system builder
  733. args env-vars)
  734. (make-derivation outputs inputs sources system builder
  735. args env-vars file))))
  736. (let* ((outputs (map (lambda (name)
  737. ;; Return outputs with an empty path.
  738. (cons name
  739. (make-derivation-output "" hash-algo
  740. hash recursive?)))
  741. outputs))
  742. (inputs (map (match-lambda
  743. (((? derivation? drv))
  744. (make-derivation-input (derivation-file-name drv)
  745. '("out")))
  746. (((? derivation? drv) sub-drvs ...)
  747. (make-derivation-input (derivation-file-name drv)
  748. sub-drvs))
  749. (((? direct-store-path? input))
  750. (make-derivation-input input '("out")))
  751. (((? direct-store-path? input) sub-drvs ...)
  752. (make-derivation-input input sub-drvs))
  753. ((input . _)
  754. (let ((path (add-to-store store
  755. (basename input)
  756. #t "sha256" input)))
  757. (make-derivation-input path '()))))
  758. (delete-duplicates inputs)))
  759. (env-vars (env-vars-with-empty-outputs (user+system-env-vars)))
  760. (drv-masked (make-derivation outputs
  761. (filter (compose derivation-path?
  762. derivation-input-path)
  763. inputs)
  764. (filter-map (lambda (i)
  765. (let ((p (derivation-input-path i)))
  766. (and (not (derivation-path? p))
  767. p)))
  768. inputs)
  769. system builder args env-vars #f))
  770. (drv (add-output-paths drv-masked)))
  771. (let ((file (add-text-to-store store (string-append name ".drv")
  772. (derivation->string drv)
  773. (map derivation-input-path
  774. inputs))))
  775. (set-file-name drv file))))
  776. (define* (map-derivation store drv mapping
  777. #:key (system (%current-system)))
  778. "Given MAPPING, a list of pairs of derivations, return a derivation based on
  779. DRV where all the 'car's of MAPPING have been replaced by its 'cdr's,
  780. recursively."
  781. (define (substitute str initial replacements)
  782. (fold (lambda (path replacement result)
  783. (string-replace-substring result path
  784. replacement))
  785. str
  786. initial replacements))
  787. (define (substitute-file file initial replacements)
  788. (define contents
  789. (with-fluids ((%default-port-encoding #f))
  790. (call-with-input-file file get-string-all)))
  791. (let ((updated (substitute contents initial replacements)))
  792. (if (string=? updated contents)
  793. file
  794. ;; XXX: permissions aren't preserved.
  795. (add-text-to-store store (store-path-package-name file)
  796. updated))))
  797. (define input->output-paths
  798. (match-lambda
  799. (((? derivation? drv))
  800. (list (derivation->output-path drv)))
  801. (((? derivation? drv) sub-drvs ...)
  802. (map (cut derivation->output-path drv <>)
  803. sub-drvs))
  804. ((file)
  805. (list file))))
  806. (let ((mapping (fold (lambda (pair result)
  807. (match pair
  808. (((? derivation? orig) . replacement)
  809. (vhash-cons (derivation-file-name orig)
  810. replacement result))
  811. ((file . replacement)
  812. (vhash-cons file replacement result))))
  813. vlist-null
  814. mapping)))
  815. (define rewritten-input
  816. ;; Rewrite the given input according to MAPPING, and return an input
  817. ;; in the format used in 'derivation' calls.
  818. (memoize
  819. (lambda (input loop)
  820. (match input
  821. (($ <derivation-input> path (sub-drvs ...))
  822. (match (vhash-assoc path mapping)
  823. ((_ . (? derivation? replacement))
  824. (cons replacement sub-drvs))
  825. ((_ . replacement)
  826. (list replacement))
  827. (#f
  828. (let* ((drv (loop (call-with-input-file path read-derivation))))
  829. (cons drv sub-drvs)))))))))
  830. (let loop ((drv drv))
  831. (let* ((inputs (map (cut rewritten-input <> loop)
  832. (derivation-inputs drv)))
  833. (initial (append-map derivation-input-output-paths
  834. (derivation-inputs drv)))
  835. (replacements (append-map input->output-paths inputs))
  836. ;; Sources typically refer to the output directories of the
  837. ;; original inputs, INITIAL. Rewrite them by substituting
  838. ;; REPLACEMENTS.
  839. (sources (map (lambda (source)
  840. (match (vhash-assoc source mapping)
  841. ((_ . replacement)
  842. replacement)
  843. (#f
  844. (substitute-file source
  845. initial replacements))))
  846. (derivation-sources drv)))
  847. ;; Now augment the lists of initials and replacements.
  848. (initial (append (derivation-sources drv) initial))
  849. (replacements (append sources replacements))
  850. (name (store-path-package-name
  851. (string-drop-right (derivation-file-name drv)
  852. 4))))
  853. (derivation store name
  854. (substitute (derivation-builder drv)
  855. initial replacements)
  856. (map (cut substitute <> initial replacements)
  857. (derivation-builder-arguments drv))
  858. #:system system
  859. #:env-vars (map (match-lambda
  860. ((var . value)
  861. `(,var
  862. . ,(substitute value initial
  863. replacements))))
  864. (derivation-builder-environment-vars drv))
  865. #:inputs (append (map list sources) inputs)
  866. #:outputs (derivation-output-names drv)
  867. #:hash (match (derivation-outputs drv)
  868. ((($ <derivation-output> _ algo hash))
  869. hash)
  870. (_ #f))
  871. #:hash-algo (match (derivation-outputs drv)
  872. ((($ <derivation-output> _ algo hash))
  873. algo)
  874. (_ #f)))))))
  875. ;;;
  876. ;;; Store compatibility layer.
  877. ;;;
  878. (define (build-derivations store derivations)
  879. "Build DERIVATIONS, a list of <derivation> objects or .drv file names."
  880. (build-things store (map (match-lambda
  881. ((? string? file) file)
  882. ((and drv ($ <derivation>))
  883. (derivation-file-name drv)))
  884. derivations)))
  885. ;;;
  886. ;;; Guile-based builders.
  887. ;;;
  888. (define (parent-directories file-name)
  889. "Return the list of parent dirs of FILE-NAME, in the order in which an
  890. `mkdir -p' implementation would make them."
  891. (let ((not-slash (char-set-complement (char-set #\/))))
  892. (reverse
  893. (fold (lambda (dir result)
  894. (match result
  895. (()
  896. (list dir))
  897. ((prev _ ...)
  898. (cons (string-append prev "/" dir)
  899. result))))
  900. '()
  901. (remove (cut string=? <> ".")
  902. (string-tokenize (dirname file-name) not-slash))))))
  903. (define* (imported-files store files ;deprecated
  904. #:key (name "file-import")
  905. (system (%current-system))
  906. (guile (%guile-for-build)))
  907. "Return a derivation that imports FILES into STORE. FILES must be a list
  908. of (FINAL-PATH . FILE-NAME) pairs; each FILE-NAME is read from the file
  909. system, imported, and appears under FINAL-PATH in the resulting store path."
  910. (let* ((files (map (match-lambda
  911. ((final-path . file-name)
  912. (list final-path
  913. (add-to-store store (basename final-path) #f
  914. "sha256" file-name))))
  915. files))
  916. (builder
  917. `(begin
  918. (mkdir %output) (chdir %output)
  919. ,@(append-map (match-lambda
  920. ((final-path store-path)
  921. (append (match (parent-directories final-path)
  922. (() '())
  923. ((head ... tail)
  924. (append (map (lambda (d)
  925. `(false-if-exception
  926. (mkdir ,d)))
  927. head)
  928. `((or (file-exists? ,tail)
  929. (mkdir ,tail))))))
  930. `((symlink ,store-path ,final-path)))))
  931. files))))
  932. (build-expression->derivation store name builder
  933. #:system system
  934. #:inputs files
  935. #:guile-for-build guile
  936. #:local-build? #t)))
  937. (define search-path*
  938. ;; A memoizing version of 'search-path' so 'imported-modules' does not end
  939. ;; up looking for the same files over and over again.
  940. (memoize search-path))
  941. (define* (%imported-modules store modules ;deprecated
  942. #:key (name "module-import")
  943. (system (%current-system))
  944. (guile (%guile-for-build))
  945. (module-path %load-path))
  946. "Return a derivation that contains the source files of MODULES, a list of
  947. module names such as `(ice-9 q)'. All of MODULES must be in the MODULE-PATH
  948. search path."
  949. ;; TODO: Determine the closure of MODULES, build the `.go' files,
  950. ;; canonicalize the source files through read/write, etc.
  951. (let ((files (map (lambda (m)
  952. (let ((f (string-append
  953. (string-join (map symbol->string m) "/")
  954. ".scm")))
  955. (cons f (search-path* module-path f))))
  956. modules)))
  957. (imported-files store files #:name name #:system system
  958. #:guile guile)))
  959. (define* (%compiled-modules store modules ;deprecated
  960. #:key (name "module-import-compiled")
  961. (system (%current-system))
  962. (guile (%guile-for-build))
  963. (module-path %load-path))
  964. "Return a derivation that builds a tree containing the `.go' files
  965. corresponding to MODULES. All the MODULES are built in a context where
  966. they can refer to each other."
  967. (let* ((module-drv (%imported-modules store modules
  968. #:system system
  969. #:guile guile
  970. #:module-path module-path))
  971. (module-dir (derivation->output-path module-drv))
  972. (files (map (lambda (m)
  973. (let ((f (string-join (map symbol->string m)
  974. "/")))
  975. (cons (string-append f ".go")
  976. (string-append module-dir "/" f ".scm"))))
  977. modules)))
  978. (define builder
  979. `(begin
  980. (use-modules (system base compile))
  981. (let ((out (assoc-ref %outputs "out")))
  982. (mkdir out)
  983. (chdir out))
  984. (set! %load-path
  985. (cons ,module-dir %load-path))
  986. ,@(map (match-lambda
  987. ((output . input)
  988. (let ((make-parent-dirs (map (lambda (dir)
  989. `(unless (file-exists? ,dir)
  990. (mkdir ,dir)))
  991. (parent-directories output))))
  992. `(begin
  993. ,@make-parent-dirs
  994. (compile-file ,input
  995. #:output-file ,output
  996. #:opts %auto-compilation-options)))))
  997. files)))
  998. (build-expression->derivation store name builder
  999. #:inputs `(("modules" ,module-drv))
  1000. #:system system
  1001. #:guile-for-build guile
  1002. #:local-build? #t)))
  1003. (define-record-type* <graft> graft make-graft
  1004. graft?
  1005. (origin graft-origin) ;derivation | store item
  1006. (origin-output graft-origin-output ;string | #f
  1007. (default "out"))
  1008. (replacement graft-replacement) ;derivation | store item
  1009. (replacement-output graft-replacement-output ;string | #f
  1010. (default "out")))
  1011. (define* (graft-derivation store name drv grafts
  1012. #:key (guile (%guile-for-build))
  1013. (system (%current-system)))
  1014. "Return a derivation called NAME, based on DRV but with all the GRAFTS
  1015. applied."
  1016. ;; XXX: Someday rewrite using gexps.
  1017. (define mapping
  1018. ;; List of store item pairs.
  1019. (map (match-lambda
  1020. (($ <graft> source source-output target target-output)
  1021. (cons (if (derivation? source)
  1022. (derivation->output-path source source-output)
  1023. source)
  1024. (if (derivation? target)
  1025. (derivation->output-path target target-output)
  1026. target))))
  1027. grafts))
  1028. (define outputs
  1029. (match (derivation-outputs drv)
  1030. (((names . outputs) ...)
  1031. (map derivation-output-path outputs))))
  1032. (define output-names
  1033. (match (derivation-outputs drv)
  1034. (((names . outputs) ...)
  1035. names)))
  1036. (define build
  1037. `(begin
  1038. (use-modules (guix build graft)
  1039. (guix build utils)
  1040. (ice-9 match))
  1041. (let ((mapping ',mapping))
  1042. (for-each (lambda (input output)
  1043. (format #t "grafting '~a' -> '~a'...~%" input output)
  1044. (force-output)
  1045. (rewrite-directory input output
  1046. `((,input . ,output)
  1047. ,@mapping)))
  1048. ',outputs
  1049. (match %outputs
  1050. (((names . files) ...)
  1051. files))))))
  1052. (define add-label
  1053. (cut cons "x" <>))
  1054. (match grafts
  1055. ((($ <graft> sources source-outputs targets target-outputs) ...)
  1056. (let ((sources (zip sources source-outputs))
  1057. (targets (zip targets target-outputs)))
  1058. (build-expression->derivation store name build
  1059. #:system system
  1060. #:guile-for-build guile
  1061. #:modules '((guix build graft)
  1062. (guix build utils))
  1063. #:inputs `(,@(map (lambda (out)
  1064. `("x" ,drv ,out))
  1065. output-names)
  1066. ,@(append (map add-label sources)
  1067. (map add-label targets)))
  1068. #:outputs output-names
  1069. #:local-build? #t)))))
  1070. (define* (build-expression->derivation store name exp ;deprecated
  1071. #:key
  1072. (system (%current-system))
  1073. (inputs '())
  1074. (outputs '("out"))
  1075. hash hash-algo recursive?
  1076. (env-vars '())
  1077. (modules '())
  1078. guile-for-build
  1079. references-graphs
  1080. allowed-references
  1081. local-build? (substitutable? #t))
  1082. "Return a derivation that executes Scheme expression EXP as a builder
  1083. for derivation NAME. INPUTS must be a list of (NAME DRV-PATH SUB-DRV)
  1084. tuples; when SUB-DRV is omitted, \"out\" is assumed. MODULES is a list
  1085. of names of Guile modules from the current search path to be copied in
  1086. the store, compiled, and made available in the load path during the
  1087. execution of EXP.
  1088. EXP is evaluated in an environment where %OUTPUT is bound to the main
  1089. output path, %OUTPUTS is bound to a list of output/path pairs, and where
  1090. %BUILD-INPUTS is bound to an alist of string/output-path pairs made from
  1091. INPUTS. Optionally, ENV-VARS is a list of string pairs specifying the
  1092. name and value of environment variables visible to the builder. The
  1093. builder terminates by passing the result of EXP to `exit'; thus, when
  1094. EXP returns #f, the build is considered to have failed.
  1095. EXP is built using GUILE-FOR-BUILD (a derivation). When GUILE-FOR-BUILD is
  1096. omitted or is #f, the value of the `%guile-for-build' fluid is used instead.
  1097. See the `derivation' procedure for the meaning of REFERENCES-GRAPHS,
  1098. ALLOWED-REFERENCES, LOCAL-BUILD?, and SUBSTITUTABLE?."
  1099. (define guile-drv
  1100. (or guile-for-build (%guile-for-build)))
  1101. (define guile
  1102. (string-append (derivation->output-path guile-drv)
  1103. "/bin/guile"))
  1104. (define module-form?
  1105. (match-lambda
  1106. (((or 'define-module 'use-modules) _ ...) #t)
  1107. (_ #f)))
  1108. (define source-path
  1109. ;; When passed an input that is a source, return its path; otherwise
  1110. ;; return #f.
  1111. (match-lambda
  1112. ((_ (? derivation?) _ ...)
  1113. #f)
  1114. ((_ path _ ...)
  1115. (and (not (derivation-path? path))
  1116. path))))
  1117. (let* ((prologue `(begin
  1118. ,@(match exp
  1119. ((_ ...)
  1120. ;; Module forms must appear at the top-level so
  1121. ;; that any macros they export can be expanded.
  1122. (filter module-form? exp))
  1123. (_ `(,exp)))
  1124. (define %output (getenv "out"))
  1125. (define %outputs
  1126. (map (lambda (o)
  1127. (cons o (getenv o)))
  1128. ',outputs))
  1129. (define %build-inputs
  1130. ',(map (match-lambda
  1131. ((name drv . rest)
  1132. (let ((sub (match rest
  1133. (() "out")
  1134. ((x) x))))
  1135. (cons name
  1136. (cond
  1137. ((derivation? drv)
  1138. (derivation->output-path drv sub))
  1139. ((derivation-path? drv)
  1140. (derivation-path->output-path drv
  1141. sub))
  1142. (else drv))))))
  1143. inputs))
  1144. ,@(if (null? modules)
  1145. '()
  1146. ;; Remove our own settings.
  1147. '((unsetenv "GUILE_LOAD_COMPILED_PATH")))
  1148. ;; Guile sets it, but remove it to avoid conflicts when
  1149. ;; building Guile-using packages.
  1150. (unsetenv "LD_LIBRARY_PATH")))
  1151. (builder (add-text-to-store store
  1152. (string-append name "-guile-builder")
  1153. ;; Explicitly use UTF-8 for determinism,
  1154. ;; and also because UTF-8 output is faster.
  1155. (with-fluids ((%default-port-encoding
  1156. "UTF-8"))
  1157. (call-with-output-string
  1158. (lambda (port)
  1159. (write prologue port)
  1160. (write
  1161. `(exit
  1162. ,(match exp
  1163. ((_ ...)
  1164. (remove module-form? exp))
  1165. (_ `(,exp))))
  1166. port))))
  1167. ;; The references don't really matter
  1168. ;; since the builder is always used in
  1169. ;; conjunction with the drv that needs
  1170. ;; it. For clarity, we add references
  1171. ;; to the subset of INPUTS that are
  1172. ;; sources, avoiding references to other
  1173. ;; .drv; otherwise, BUILDER's hash would
  1174. ;; depend on those, even if they are
  1175. ;; fixed-output.
  1176. (filter-map source-path inputs)))
  1177. (mod-drv (and (pair? modules)
  1178. (%imported-modules store modules
  1179. #:guile guile-drv
  1180. #:system system)))
  1181. (mod-dir (and mod-drv
  1182. (derivation->output-path mod-drv)))
  1183. (go-drv (and (pair? modules)
  1184. (%compiled-modules store modules
  1185. #:guile guile-drv
  1186. #:system system)))
  1187. (go-dir (and go-drv
  1188. (derivation->output-path go-drv))))
  1189. (derivation store name guile
  1190. `("--no-auto-compile"
  1191. ,@(if mod-dir `("-L" ,mod-dir) '())
  1192. ,builder)
  1193. #:system system
  1194. #:inputs `((,(or guile-for-build (%guile-for-build)))
  1195. (,builder)
  1196. ,@(map cdr inputs)
  1197. ,@(if mod-drv `((,mod-drv) (,go-drv)) '()))
  1198. ;; When MODULES is non-empty, shamelessly clobber
  1199. ;; $GUILE_LOAD_COMPILED_PATH.
  1200. #:env-vars (if go-dir
  1201. `(("GUILE_LOAD_COMPILED_PATH" . ,go-dir)
  1202. ,@(alist-delete "GUILE_LOAD_COMPILED_PATH"
  1203. env-vars))
  1204. env-vars)
  1205. #:hash hash #:hash-algo hash-algo
  1206. #:recursive? recursive?
  1207. #:outputs outputs
  1208. #:references-graphs references-graphs
  1209. #:allowed-references allowed-references
  1210. #:local-build? local-build?
  1211. #:substitutable? substitutable?)))
  1212. ;;;
  1213. ;;; Monadic interface.
  1214. ;;;
  1215. (define built-derivations
  1216. (store-lift build-derivations))</