From c1f5748983ab0e71af4421030a40ac424e666b45 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 30 May 2015 15:10:30 +0000 Subject: [PATCH 1/4] agda: Provide a `.env` like Haskell instead of `.extras` --- pkgs/build-support/agda/default.nix | 32 ++++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/pkgs/build-support/agda/default.nix b/pkgs/build-support/agda/default.nix index 69c4897d1a4b..a404bbcf6349 100644 --- a/pkgs/build-support/agda/default.nix +++ b/pkgs/build-support/agda/default.nix @@ -22,9 +22,6 @@ in propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs; propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs; everythingFile = if x.everythingFile == "" then "Everything.agda" else x.everythingFile; - - passthru = { inherit (x) extras; }; - extras = null; }; defaults = self : { @@ -81,22 +78,19 @@ in runHook postInstall ''; - # Optionally-built conveniences - extras = { - # Makes a wrapper available to the user. Very useful in - # nix-shell where all dependencies are -i'd. - agdaWrapper = writeScriptBin "agda" '' - ${self.agdaWithArgs} "$@" - ''; - - # Use this to stick `agdaWrapper` at the front of the PATH: - # - # agda.mkDerivation (self: { PATH = self.extras.agdaWrapperPATH; }) - # - # Not sure this is the best way to handle conflicts.... - agdaWrapperPATH = "${self.extras.agdaWrapper}/bin:$PATH"; - - AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda; + passthru = { + env = stdenv.mkDerivation { + name = "interactive-${self.name}"; + inherit (self) LANG LOCALE_ARCHIVE; + AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda; + buildInputs = let + # Makes a wrapper available to the user. Very useful in + # nix-shell where all dependencies are -i'd. + agdaWrapper = writeScriptBin "agda" '' + ${self.agdaWithArgs} "$@" + ''; + in [agdaWrapper] ++ self.buildDepends; + }; }; }; in stdenv.mkDerivation From 21b10ab44fa8f28f36990085853d9d2708d694db Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 30 May 2015 19:22:32 +0000 Subject: [PATCH 2/4] agda: `postprocess` and `defaults` need not be in the scope of args --- pkgs/build-support/agda/default.nix | 163 ++++++++++++++-------------- 1 file changed, 81 insertions(+), 82 deletions(-) diff --git a/pkgs/build-support/agda/default.nix b/pkgs/build-support/agda/default.nix index a404bbcf6349..74debe79efc6 100644 --- a/pkgs/build-support/agda/default.nix +++ b/pkgs/build-support/agda/default.nix @@ -14,87 +14,86 @@ let concatMapStrings = stdenv.lib.strings.concatMapStrings; unwords = stdenv.lib.strings.concatStringsSep " "; mapInside = xs: unwords (map (x: x + "/*") xs); + + defaults = self : { + # There is no Hackage for Agda so we require src. + inherit (self) src name; + + isAgdaPackage = true; + + buildInputs = [ Agda ] ++ self.buildDepends; + buildDepends = []; + + buildDependsAgda = filter + (dep: dep ? isAgdaPackage && dep.isAgdaPackage) + self.buildDepends; + buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda; + + # Not much choice here ;) + LANG = "en_US.UTF-8"; + LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive"; + + everythingFile = "Everything.agda"; + + propagatedBuildInputs = self.buildDependsAgda; + propagatedUserEnvPkgs = self.buildDependsAgda; + + # 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" ]; + + # FIXME: `dirOf self.everythingFile` is what we really want, not hardcoded "./" + includeDirs = self.buildDependsAgdaShareAgda + ++ self.sourceDirectories ++ self.topSourceDirectories + ++ [ "." ]; + buildFlags = unwords (map (x: "-i " + x) self.includeDirs); + + agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}"; + + buildPhase = '' + runHook preBuild + ${self.agdaWithArgs} ${self.everythingFile} + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/share/agda + cp -pR ${unwords self.sourceDirectories} ${mapInside self.topSourceDirectories} $out/share/agda + runHook postInstall + ''; + + passthru = { + env = stdenv.mkDerivation { + name = "interactive-${self.name}"; + inherit (self) LANG LOCALE_ARCHIVE; + AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda; + buildInputs = let + # Makes a wrapper available to the user. Very useful in + # nix-shell where all dependencies are -i'd. + agdaWrapper = writeScriptBin "agda" '' + ${self.agdaWithArgs} "$@" + ''; + in [agdaWrapper] ++ self.buildDepends; + }; + }; + }; + + postprocess = x: x // { + sourceDirectories = filter (y: !(y == null)) x.sourceDirectories; + propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs; + propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs; + everythingFile = if x.everythingFile == "" then "Everything.agda" else x.everythingFile; + }; 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; - 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; - - isAgdaPackage = true; - - buildInputs = [ Agda ] ++ self.buildDepends; - buildDepends = []; - - buildDependsAgda = filter - (dep: dep ? isAgdaPackage && dep.isAgdaPackage) - self.buildDepends; - buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda; - - # Not much choice here ;) - LANG = "en_US.UTF-8"; - LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive"; - - everythingFile = "Everything.agda"; - - propagatedBuildInputs = self.buildDependsAgda; - propagatedUserEnvPkgs = self.buildDependsAgda; - - # 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" ]; - - # FIXME: `dirOf self.everythingFile` is what we really want, not hardcoded "./" - includeDirs = self.buildDependsAgdaShareAgda - ++ self.sourceDirectories ++ self.topSourceDirectories - ++ [ "." ]; - buildFlags = unwords (map (x: "-i " + x) self.includeDirs); - - agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}"; - - buildPhase = '' - runHook preBuild - ${self.agdaWithArgs} ${self.everythingFile} - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - mkdir -p $out/share/agda - cp -pR ${unwords self.sourceDirectories} ${mapInside self.topSourceDirectories} $out/share/agda - runHook postInstall - ''; - - passthru = { - env = stdenv.mkDerivation { - name = "interactive-${self.name}"; - inherit (self) LANG LOCALE_ARCHIVE; - AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda; - buildInputs = let - # Makes a wrapper available to the user. Very useful in - # nix-shell where all dependencies are -i'd. - agdaWrapper = writeScriptBin "agda" '' - ${self.agdaWithArgs} "$@" - ''; - in [agdaWrapper] ++ self.buildDepends; - }; - }; - }; - in stdenv.mkDerivation - (postprocess (let super = defaults self // args self; - self = super // extension self super; - in self)); +{ mkDerivation = args: let + super = defaults self // args self; + self = super // extension self super; + in stdenv.mkDerivation (postprocess self); } From 9b31a07b0de58b5996ecc6b953350af3838d1706 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 30 May 2015 19:30:24 +0000 Subject: [PATCH 3/4] agda: Just `with` all of the string helper functions --- pkgs/build-support/agda/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/agda/default.nix b/pkgs/build-support/agda/default.nix index 74debe79efc6..0bdc049934a7 100644 --- a/pkgs/build-support/agda/default.nix +++ b/pkgs/build-support/agda/default.nix @@ -7,12 +7,12 @@ , extension ? (self: super: {}) }: +with stdenv.lib.strings; + let optionalString = stdenv.lib.optionalString; filter = stdenv.lib.filter; - concatMapStringsSep = stdenv.lib.strings.concatMapStringsSep; - concatMapStrings = stdenv.lib.strings.concatMapStrings; - unwords = stdenv.lib.strings.concatStringsSep " "; + unwords = concatStringsSep " "; mapInside = xs: unwords (map (x: x + "/*") xs); defaults = self : { From be2cba690ce6614768cae065d37ffffb9d4181d7 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 30 May 2015 19:33:20 +0000 Subject: [PATCH 4/4] agda: Remove unused/uneeded abstractions, including `postprocess` --- pkgs/build-support/agda/default.nix | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/pkgs/build-support/agda/default.nix b/pkgs/build-support/agda/default.nix index 0bdc049934a7..8a871cfeb51a 100644 --- a/pkgs/build-support/agda/default.nix +++ b/pkgs/build-support/agda/default.nix @@ -10,11 +10,6 @@ with stdenv.lib.strings; let - optionalString = stdenv.lib.optionalString; - filter = stdenv.lib.filter; - unwords = concatStringsSep " "; - mapInside = xs: unwords (map (x: x + "/*") xs); - defaults = self : { # There is no Hackage for Agda so we require src. inherit (self) src name; @@ -24,14 +19,16 @@ let buildInputs = [ Agda ] ++ self.buildDepends; buildDepends = []; - buildDependsAgda = filter + buildDependsAgda = stdenv.lib.filter (dep: dep ? isAgdaPackage && dep.isAgdaPackage) self.buildDepends; buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda; # Not much choice here ;) LANG = "en_US.UTF-8"; - LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive"; + LOCALE_ARCHIVE = stdenv.lib.optionalString + stdenv.isLinux + "${glibcLocales}/lib/locale/locale-archive"; everythingFile = "Everything.agda"; @@ -52,7 +49,7 @@ let includeDirs = self.buildDependsAgdaShareAgda ++ self.sourceDirectories ++ self.topSourceDirectories ++ [ "." ]; - buildFlags = unwords (map (x: "-i " + x) self.includeDirs); + buildFlags = concatStringsSep " " (map (x: "-i " + x) self.includeDirs); agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}"; @@ -62,10 +59,13 @@ let runHook postBuild ''; - installPhase = '' + installPhase = let + srcFiles = self.sourceDirectories + ++ map (x: x + "/*") self.topSourceDirectories; + in '' runHook preInstall mkdir -p $out/share/agda - cp -pR ${unwords self.sourceDirectories} ${mapInside self.topSourceDirectories} $out/share/agda + cp -pR ${concatStringsSep " " srcFiles} $out/share/agda runHook postInstall ''; @@ -84,16 +84,9 @@ 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; - everythingFile = if x.everythingFile == "" then "Everything.agda" else x.everythingFile; - }; in { mkDerivation = args: let super = defaults self // args self; self = super // extension self super; - in stdenv.mkDerivation (postprocess self); + in stdenv.mkDerivation self; }