From d54b62ca6073efd99f1018c768214a2b9483f61e Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Sun, 31 Aug 2014 18:40:11 +0100 Subject: [PATCH 1/2] Add a builder for Agda packages. --- pkgs/build-support/agda/default.nix | 95 +++++++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 8 +++ 2 files changed, 103 insertions(+) create mode 100644 pkgs/build-support/agda/default.nix diff --git a/pkgs/build-support/agda/default.nix b/pkgs/build-support/agda/default.nix new file mode 100644 index 000000000000..f8130b423a20 --- /dev/null +++ b/pkgs/build-support/agda/default.nix @@ -0,0 +1,95 @@ +# Builder for Agda packages. Mostly inspired by the cabal builder. +# +# Contact: stdenv.lib.maintainers.fuuzetsu + +{ stdenv, Agda, glibcLocales +, writeScriptBin +, extension ? (self: super: {}) +}: + +let + optionalString = stdenv.lib.optionalString; + filter = stdenv.lib.filter; + concatMapStringsSep = stdenv.lib.strings.concatMapStringsSep; + concatMapStrings = stdenv.lib.strings.concatMapStrings; + unwords = stdenv.lib.strings.concatStringsSep " "; + mapInside = xs: unwords (map (x: x + "/*") xs); +in +{ mkDerivation = args: + let + postprocess = x: x // { + sourceDirectories = filter (y: !(y == null)) x.sourceDirectories; + propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs; + propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs; + extraBuildFlags = filter (y : ! (y == null)) x.extraBuildFlags; + everythingFile = if x.everythingFile == "" then "Everything.agda" else x.everythingFile; + }; + + defaults = self : { + # There is no Hackage for Agda so we require src. + inherit (self) src name; + + buildInputs = [ Agda ] ++ self.buildDepends; + buildDepends = []; + # Not much choice here ;) + LANG = "en_US.UTF-8"; + LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive"; + + everythingFile = "Everything.agda"; + + propagatedBuildInputs = self.buildDepends ++ self.buildTools; + propagatedUserEnvPkgs = self.buildDepends; + + # Immediate source directories under which modules can be found. + sourceDirectories = [ ]; + + # This is used if we have a top-level element that only serves + # as the container for the source and we only care about its + # contents. The directories put here will have their + # *contents* copied over as opposed to sourceDirectories which + # would make a direct copy of the whole thing. + topSourceDirectories = [ "src" ]; + + buildTools = []; + + # Extra stuff to pass to the Agda binary. + extraBuildFlags = [ "-i ." ]; + buildFlags = let r = map (x: "-i " + x + "/share/agda") self.buildDepends; + d = map (x : "-i " + x) (self.sourceDirectories ++ self.topSourceDirectories); + in unwords (r ++ d ++ self.extraBuildFlags); + + # We expose this as a mere convenience for any tools. + AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDepends; + + # Makes a wrapper available to the user. Very useful in + # nix-shell where all dependencies are -i'd. + agdaWrapper = writeScriptBin "agda" '' + ${Agda}/bin/agda ${self.buildFlags} "$@" + ''; + + # configurePhase is idempotent + configurePhase = '' + eval "$preConfigure" + export AGDA_PACKAGE_PATH=${self.AGDA_PACKAGE_PATH}; + export PATH="${self.agdaWrapper}/bin:$PATH" + eval "$postConfigure" + ''; + + buildPhase = '' + eval "$preBuild" + ${Agda}/bin/agda ${self.buildFlags} ${self.everythingFile} + eval "$postBuild" + ''; + + installPhase = '' + eval "$preInstall" + mkdir -p $out/share/agda + cp -pR ${unwords self.sourceDirectories} ${mapInside self.topSourceDirectories} $out/share/agda + eval "$postInstall" + ''; + }; + in stdenv.mkDerivation + (postprocess (let super = defaults self // args self; + self = super // extension self super; + in self)); +} \ No newline at end of file diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cfc93a8cf45b..9770b178e443 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6526,6 +6526,14 @@ let zziplib = callPackage ../development/libraries/zziplib { }; + ### DEVELOPMENT / LIBRARIES / AGDA + + agda = callPackage ../build-support/agda { + glibcLocales = if pkgs.stdenv.isLinux then pkgs.glibcLocales else null; + extension = self : super : {}; + Agda = haskellPackages.Agda; + inherit writeScriptBin; + }; ### DEVELOPMENT / LIBRARIES / JAVA From 61c17e326f9c0f6fd742889c1b8743df83b79c0f Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Mon, 1 Sep 2014 01:31:17 +0100 Subject: [PATCH 2/2] Use agda builder for stdlib. mv to all-packages --- pkgs/development/compilers/agda/stdlib.nix | 26 +++++++++------------- pkgs/top-level/all-packages.nix | 4 ++++ pkgs/top-level/haskell-packages.nix | 1 - 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pkgs/development/compilers/agda/stdlib.nix b/pkgs/development/compilers/agda/stdlib.nix index d0ae1394f894..2857a7d3d71b 100644 --- a/pkgs/development/compilers/agda/stdlib.nix +++ b/pkgs/development/compilers/agda/stdlib.nix @@ -1,7 +1,10 @@ -{ cabal, fetchurl, filemanip, Agda }: +{ stdenv, agda, fetchurl, ghcWithPackages }: -cabal.mkDerivation (self: rec { - pname = "Agda-stdlib"; +let + ghc = ghcWithPackages (s: [ s.filemanip ]); +in +agda.mkDerivation (self: rec { + name = "Agda-stdlib"; version = "0.8.1"; src = fetchurl { @@ -9,23 +12,16 @@ cabal.mkDerivation (self: rec { sha256 = "0ij4rg4lk0pq01ing285gbmnn23dcf2rhihdcs8bbdpjg52vl4gf"; }; - buildDepends = [ filemanip Agda ]; - - preConfigure = "cd ffi"; - - postInstall = '' - mkdir -p $out/share - cd .. - ${self.ghc.ghc}/bin/runhaskell GenerateEverything - ${Agda}/bin/agda -i . -i src Everything.agda - cp -pR src $out/share/agda + preConfigure = '' + ${ghc}/bin/runhaskell GenerateEverything.hs ''; + topSourceDirectories = [ "src" ]; + meta = { homepage = "http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Libraries.StandardLibrary"; description = "A standard library for use with the Agda compiler."; license = "unknown"; - platforms = self.ghc.meta.platforms; - maintainers = [ self.stdenv.lib.maintainers.jwiegley ]; + maintainers = with stdenv.lib.maintaianers; [ jwiegley ]; }; }) \ No newline at end of file diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9770b178e443..6a0fd08cca7e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6535,6 +6535,10 @@ let inherit writeScriptBin; }; + AgdaStdlib = callPackage ../development/compilers/agda/stdlib.nix { + ghcWithPackages = haskellPackages.ghcWithPackages; + }; + ### DEVELOPMENT / LIBRARIES / JAVA atermjava = callPackage ../development/libraries/java/aterm { diff --git a/pkgs/top-level/haskell-packages.nix b/pkgs/top-level/haskell-packages.nix index b074a6ab48dd..9afe4b715aa3 100644 --- a/pkgs/top-level/haskell-packages.nix +++ b/pkgs/top-level/haskell-packages.nix @@ -2888,7 +2888,6 @@ self : let callPackage = x : y : modifyPrio (newScope self x y); in # Compilers. Agda = callPackage ../development/compilers/agda {}; - AgdaStdlib = callPackage ../development/compilers/agda/stdlib.nix {}; uhc = callPackage ../development/compilers/uhc {};