Skip to content

Commit

Permalink
move agda derivation to a separate file
Browse files Browse the repository at this point in the history
fix mkAgdaDerivation

prettify mkAgdaDerivation
  • Loading branch information
liesnikov committed Jan 12, 2024
1 parent 63c8749 commit 9bff018
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
31 changes: 1 addition & 30 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
32 changes: 32 additions & 0 deletions nix/mkAgdaDerivation.nix
Original file line number Diff line number Diff line change
@@ -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
''
;}))

0 comments on commit 9bff018

Please sign in to comment.