diff --git a/flake.nix b/flake.nix index c799949..deb8a34 100644 --- a/flake.nix +++ b/flake.nix @@ -19,39 +19,10 @@ outputs = {self, nixpkgs, flake-utils, agda2hs-src, scope-src}: let - getAttrOrDefault = atr: def: set: - if builtins.hasAttr atr set then builtins.getAttr atr set else def; in (flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; - agdaDerivation = args: - pkgs.agdaPackages.mkDerivation - (args // (if # don't override if Everything is present - args ? everythingFile || - # don't override if there's an explicit buildPhase - (getAttrOrDefault "buildPhase" null args != null) || - # do override if either tcFiles or tcDir is present - ! (args ? tcFiles || args ? tcDir) - then builtins.trace "not overriding" {} - else - {buildPhase = - let ipaths = getAttrOrDefault "includePaths" [] args; - concatMapStrings = pkgs.lib.strings.concatMapStrings; - iarg = concatMapStrings (path: "-i" + path + " ") ipaths; - in if args ? tcFiles - then - '' - runHook preBuild - ${concatMapStrings (f: "agda " + iarg + f + ";") args.tcFiles} - runHook postBuild - '' - else - '' - runHook preBuild - find "${args.tcDir}" -type f -name "*.agda" -print0 | xargs -0 -n1 ${"agda" + iarg} - runHook postBuild - '' - ;})); + agdaDerivation = pkgs.callPackage ./nix/mkAgdaDerivation.nix {}; agda2hslib = agdaDerivation { pname = "agda2hs"; meta = {}; diff --git a/nix/mkAgdaDerivation.nix b/nix/mkAgdaDerivation.nix new file mode 100644 index 0000000..0113cf1 --- /dev/null +++ b/nix/mkAgdaDerivation.nix @@ -0,0 +1,32 @@ +{agdaPackages, lib}: args: +with lib.strings; +let + getAttrOrDefault = atr: def: set: + if builtins.hasAttr atr set then builtins.getAttr atr set else def; +in +agdaPackages.mkDerivation (args // + (if # don't override if Everything.agda is present + args ? everythingFile || + # don't override if there's an explicit buildPhase + (getAttrOrDefault "buildPhase" null args != null) || + # do override if either tcFiles or tcDir is present + ! (args ? tcFiles || args ? tcDir) + then builtins.trace "not overriding" {} + else + {buildPhase = + let ipaths = getAttrOrDefault "includePaths" [] args; + iarg = concatMapStrings (path: "-i" + path + " ") ipaths; + in if args ? tcFiles + then + '' + runHook preBuild + ${concatMapStrings (f: "agda " + iarg + f + ";") args.tcFiles} + runHook postBuild + '' + else + '' + runHook preBuild + find "${args.tcDir}" -type f -name "*.agda" -print0 | xargs -0 -n1 -t ${"agda" + iarg} + runHook postBuild + '' + ;}))