Skip to content

Commit b902368

Browse files
committed
make the nix development compatible with flake-less nix
1 parent 84c0c36 commit b902368

File tree

7 files changed

+132
-111
lines changed

7 files changed

+132
-111
lines changed

agda2hs.nix

Lines changed: 0 additions & 29 deletions
This file was deleted.

flake.nix

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,31 @@
11
{
22
description = "Agda2hs";
33

4-
inputs.nixpkgs.url = github:NixOS/nixpkgs;
5-
inputs.flake-utils.url = github:numtide/flake-utils;
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
5+
inputs.flake-utils.url = "github:numtide/flake-utils";
66

7-
outputs = {self, nixpkgs, flake-utils}:
8-
flake-utils.lib.eachDefaultSystem (system:
7+
outputs =
8+
{
9+
self,
10+
nixpkgs,
11+
flake-utils,
12+
}:
13+
flake-utils.lib.eachDefaultSystem (
14+
system:
915
let
10-
pkgs = import nixpkgs {inherit system;};
11-
12-
agda2hs-lib = pkgs.agdaPackages.mkDerivation
13-
{ pname = "agda2hs";
14-
meta = {};
15-
version = "1.3";
16-
preBuild = ''
17-
echo "{-# OPTIONS --sized-types #-}" > Everything.agda
18-
echo "module Everything where" >> Everything.agda
19-
find lib -name '*.agda' | sed -e 's/lib\///;s/\//./g;s/\.agda$//;s/^/import /' >> Everything.agda
20-
'';
21-
src = ./.;
22-
};
23-
# options provides a way to jailbreak for packages that use agda2hs
24-
agda2hs-pkg = options:
25-
pkgs.haskellPackages.haskellSrc2nix {
26-
name = "agda2hs";
27-
src = ./.;
28-
extraCabal2nixOptions = options; #"--jailbreak"
29-
};
30-
agda2hs-hs = pkgs.haskellPackages.callPackage (agda2hs-pkg "") {};
31-
agda2hs-expr = import ./agda2hs.nix;
32-
agda2hs = pkgs.callPackage agda2hs-expr {
33-
inherit self;
34-
agda2hs = agda2hs-hs;
35-
inherit (pkgs.haskellPackages) ghcWithPackages;
36-
};
37-
in {
38-
packages = {
39-
inherit agda2hs-lib;
40-
inherit (agda2hs) agda2hs;
41-
default = agda2hs.agda2hs;
42-
};
43-
lib = {
44-
inherit (agda2hs) withPackages;
45-
inherit agda2hs-pkg agda2hs-hs agda2hs-expr;
16+
pkgs = import nixpkgs { inherit system; };
17+
packages = import ./nix/default.nix { inherit pkgs; };
18+
lib = import ./nix/lib.nix { inherit pkgs; };
19+
in
20+
{
21+
packages = packages // {
22+
default = packages.agda2hs;
4623
};
47-
devShells.default = pkgs.haskellPackages.shellFor {
48-
packages = p: [agda2hs-hs];
49-
buildInputs = with pkgs.haskellPackages; [
50-
cabal-install
51-
cabal2nix
52-
haskell-language-server
53-
pkgs.agda
54-
];
24+
inherit lib;
25+
devShells.default = import ./nix/shell.nix {
26+
inherit pkgs;
27+
inherit (lib) agda2hs-hs;
5528
};
56-
});
29+
}
30+
);
5731
}

nix/agda2hs.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
{
3+
stdenv,
4+
lib,
5+
self,
6+
agda2hs,
7+
runCommandNoCC,
8+
makeWrapper,
9+
writeText,
10+
mkShell,
11+
ghcWithPackages,
12+
}:
13+
with lib.strings;
14+
let
15+
withPackages' =
16+
{
17+
pkgs,
18+
ghc ? ghcWithPackages (p: with p; [ ieee754 ]),
19+
}:
20+
let
21+
pkgs' = if builtins.isList pkgs then pkgs else pkgs self;
22+
library-file = writeText "libraries" ''
23+
${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
24+
'';
25+
pname = "agda2hsWithPackages";
26+
version = agda2hs.version;
27+
in
28+
runCommandNoCC "${pname}-${version}"
29+
{
30+
inherit pname version;
31+
nativeBuildInputs = [ makeWrapper ];
32+
passthru.unwrapped = agda2hs;
33+
}
34+
''
35+
mkdir -p $out/bin
36+
makeWrapper ${agda2hs}/bin/agda2hs $out/bin/agda2hs \
37+
--add-flags "--with-compiler=${ghc}/bin/ghc" \
38+
--add-flags "--library-file=${library-file}" \
39+
--add-flags "--local-interfaces"
40+
''; # Local interfaces has been added for now: See https://github.com/agda/agda/issues/4526
41+
withPackages =
42+
arg: if builtins.isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
43+
in
44+
{
45+
inherit withPackages;
46+
agda2hs = withPackages [ ];
47+
}

nix/default.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
pkgs ? import <nixpkgs> { },
3+
...
4+
}:
5+
let
6+
lib = import ./lib.nix { inherit pkgs; };
7+
version = "1.3";
8+
agdalib = pkgs.agdaPackages.mkDerivation {
9+
pname = "agda2hs";
10+
meta = { };
11+
version = version;
12+
preBuild = ''
13+
echo "{-# OPTIONS --sized-types #-}" > Everything.agda
14+
echo "module Everything where" >> Everything.agda
15+
find lib -name '*.agda' | sed -e 's/lib\///;s/\//./g;s/\.agda$//;s/^/import /' >> Everything.agda
16+
'';
17+
src = ../.;
18+
};
19+
in
20+
{
21+
inherit (lib) agda2hs;
22+
agda2hs-lib = agdalib;
23+
}

nix/lib.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
pkgs ? import <nixpkgs> { },
3+
...
4+
}:
5+
let
6+
hsrc =
7+
options:
8+
pkgs.haskellPackages.haskellSrc2nix {
9+
name = "agda2hs";
10+
src = ../.;
11+
extraCabal2nixOptions = options; # "--jailbreak"
12+
};
13+
hpkg = pkgs.haskellPackages.callPackage (hsrc "") { };
14+
expr = import ./agda2hs.nix;
15+
agda2hs = pkgs.lib.makeScope pkgs.newScope (
16+
self:
17+
pkgs.callPackage expr {
18+
agda2hs = hpkg;
19+
inherit self;
20+
inherit (pkgs.haskellPackages) ghcWithPackages;
21+
}
22+
);
23+
in
24+
{
25+
agda2hs-pkg = hsrc;
26+
agda2hs-hs = hpkg;
27+
agda2hs-expr = expr;
28+
inherit (agda2hs) agda2hs withPackages;
29+
}

nix/shell.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ pkgs, agda2hs-hs }:
2+
pkgs.haskellPackages.shellFor {
3+
packages = p: [ agda2hs-hs ];
4+
buildInputs = with pkgs.haskellPackages; [
5+
cabal-install
6+
cabal2nix
7+
haskell-language-server
8+
pkgs.agda
9+
];
10+
}

shell.nix

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)