Skip to content

Commit

Permalink
make the nix development compatible with flake-less nix
Browse files Browse the repository at this point in the history
  • Loading branch information
liesnikov authored and jespercockx committed Dec 18, 2024
1 parent 84c0c36 commit 69a47fd
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 111 deletions.
29 changes: 0 additions & 29 deletions agda2hs.nix

This file was deleted.

72 changes: 23 additions & 49 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,57 +1,31 @@
{
description = "Agda2hs";

inputs.nixpkgs.url = github:NixOS/nixpkgs;
inputs.flake-utils.url = github:numtide/flake-utils;
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = {self, nixpkgs, flake-utils}:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {inherit system;};

agda2hs-lib = pkgs.agdaPackages.mkDerivation
{ pname = "agda2hs";
meta = {};
version = "1.3";
preBuild = ''
echo "{-# OPTIONS --sized-types #-}" > Everything.agda
echo "module Everything where" >> Everything.agda
find lib -name '*.agda' | sed -e 's/lib\///;s/\//./g;s/\.agda$//;s/^/import /' >> Everything.agda
'';
src = ./.;
};
# options provides a way to jailbreak for packages that use agda2hs
agda2hs-pkg = options:
pkgs.haskellPackages.haskellSrc2nix {
name = "agda2hs";
src = ./.;
extraCabal2nixOptions = options; #"--jailbreak"
};
agda2hs-hs = pkgs.haskellPackages.callPackage (agda2hs-pkg "") {};
agda2hs-expr = import ./agda2hs.nix;
agda2hs = pkgs.callPackage agda2hs-expr {
inherit self;
agda2hs = agda2hs-hs;
inherit (pkgs.haskellPackages) ghcWithPackages;
};
in {
packages = {
inherit agda2hs-lib;
inherit (agda2hs) agda2hs;
default = agda2hs.agda2hs;
};
lib = {
inherit (agda2hs) withPackages;
inherit agda2hs-pkg agda2hs-hs agda2hs-expr;
pkgs = import nixpkgs { inherit system; };
packages = import ./nix/default.nix { inherit pkgs; };
lib = import ./nix/lib.nix { inherit pkgs; };
in
{
packages = packages // {
default = packages.agda2hs;
};
devShells.default = pkgs.haskellPackages.shellFor {
packages = p: [agda2hs-hs];
buildInputs = with pkgs.haskellPackages; [
cabal-install
cabal2nix
haskell-language-server
pkgs.agda
];
inherit lib;
devShells.default = import ./nix/shell.nix {
inherit pkgs;
inherit (lib) agda2hs-hs;
};
});
}
);
}
47 changes: 47 additions & 0 deletions nix/agda2hs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

{
stdenv,
lib,
self,
agda2hs,
runCommandNoCC,
makeWrapper,
writeText,
mkShell,
ghcWithPackages,
}:
with lib.strings;
let
withPackages' =
{
pkgs,
ghc ? ghcWithPackages (p: with p; [ ieee754 ]),
}:
let
pkgs' = if builtins.isList pkgs then pkgs else pkgs self;
library-file = writeText "libraries" ''
${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
'';
pname = "agda2hsWithPackages";
version = agda2hs.version;
in
runCommandNoCC "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [ makeWrapper ];
passthru.unwrapped = agda2hs;
}
''
mkdir -p $out/bin
makeWrapper ${agda2hs}/bin/agda2hs $out/bin/agda2hs \
--add-flags "--with-compiler=${ghc}/bin/ghc" \
--add-flags "--library-file=${library-file}" \
--add-flags "--local-interfaces"
''; # Local interfaces has been added for now: See https://github.com/agda/agda/issues/4526
withPackages =
arg: if builtins.isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
in
{
inherit withPackages;
agda2hs = withPackages [ ];
}
23 changes: 23 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
pkgs ? import <nixpkgs> { },
...
}:
let
lib = import ./lib.nix { inherit pkgs; };
version = "1.3";
agdalib = pkgs.agdaPackages.mkDerivation {
pname = "agda2hs";
meta = { };
version = version;
preBuild = ''
echo "{-# OPTIONS --sized-types #-}" > Everything.agda
echo "module Everything where" >> Everything.agda
find lib -name '*.agda' | sed -e 's/lib\///;s/\//./g;s/\.agda$//;s/^/import /' >> Everything.agda
'';
src = ../.;
};
in
{
inherit (lib) agda2hs;
agda2hs-lib = agdalib;
}
29 changes: 29 additions & 0 deletions nix/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
pkgs ? import <nixpkgs> { },
...
}:
let
hsrc =
options:
pkgs.haskellPackages.haskellSrc2nix {
name = "agda2hs";
src = ../.;
extraCabal2nixOptions = options; # "--jailbreak"
};
hpkg = pkgs.haskellPackages.callPackage (hsrc "") { };
expr = import ./agda2hs.nix;
agda2hs = pkgs.lib.makeScope pkgs.newScope (
self:
pkgs.callPackage expr {
agda2hs = hpkg;
inherit self;
inherit (pkgs.haskellPackages) ghcWithPackages;
}
);
in
{
agda2hs-pkg = hsrc;
agda2hs-hs = hpkg;
agda2hs-expr = expr;
inherit (agda2hs) agda2hs withPackages;
}
10 changes: 10 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ pkgs, agda2hs-hs }:
pkgs.haskellPackages.shellFor {
packages = p: [ agda2hs-hs ];
buildInputs = with pkgs.haskellPackages; [
cabal-install
cabal2nix
haskell-language-server
pkgs.agda
];
}
33 changes: 0 additions & 33 deletions shell.nix

This file was deleted.

0 comments on commit 69a47fd

Please sign in to comment.