Skip to content

Commit

Permalink
Improve buildIdris and expose the idris2-api via the Nix flake. (#…
Browse files Browse the repository at this point in the history
…3182)

* Refactor buildIdris slightly and support installing libraries with source. Add the Idris2 API package as an output of the flake.

* update templates and simplify construction of a search path.

* use newer method of specifying default package

* swap out trace function for warn function. fix warnings in template generation
  • Loading branch information
mattpolzin committed Jan 5, 2024
1 parent 3c8fc8b commit 8746f16
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 24 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ This CHANGELOG describes the merged but unreleased changes. Please see [CHANGELO

## [Next version]

### Building/Packaging changes

* The Nix flake's `buildIdris` function now returns a set with `executable` and
`library` attributes. These supersede the now-deprecated `build` and
`installLibrary` attributes. `executable` is the same as `build` and `library`
is a function that takes an argument determining whether the library should be
installed with sourcecode files or not; other than that, `library`
functionally replaces `installLibrary`.

* The Nix flake now exposes the Idris2 API package as `idris2-api` and Idris2's
C support library as `support`.

### Language changes

### Compiler changes
Expand Down
16 changes: 13 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,30 @@
inherit idris2-version;
idris2 = idris2Pkg;
};
in rec {
idris2ApiPkg = buildIdris {
src = ./.;
projectName = "idris2api";
idrisLibraries = [ ];
preBuild = ''
export IDRIS2_PREFIX=$out/lib
make src/IdrisPaths.idr
'';
};
in {
checks = import ./nix/test.nix {
inherit (pkgs) system stdenv runCommand lib;
inherit nixpkgs flake-utils;
idris = self;
};
packages = {
packages = rec {
support = idris2Support;
idris2 = idris2Pkg;
idris2-api = idris2ApiPkg.library { withSource = true; };
default = idris2;
} // (import ./nix/text-editor.nix {
inherit pkgs idris-emacs-src idris2Pkg;
});
inherit buildIdris;
defaultPackage = packages.idris2;
};
in lib.mkOvrOptsFlake
(opts: flake-utils.lib.eachDefaultSystem (per-system opts) // sys-agnostic);
Expand Down
26 changes: 16 additions & 10 deletions nix/buildIdris.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ let
idrName = "idris2-${idris2-version}";
libSuffix = "lib/${idrName}";
lib-dirs =
lib.strings.concatMapStringsSep ":" (p: "${p}/${libSuffix}") idrisLibraries;
lib.strings.makeSearchPath libSuffix idrisLibraries;
drvAttrs = builtins.removeAttrs attrs [ "idrisLibraries" ];
in rec {
build = stdenv.mkDerivation (drvAttrs // {
executable = stdenv.mkDerivation (drvAttrs // {
name = projectName;
src = src;
nativeBuildInputs = [ idris2 ];
Expand All @@ -30,12 +30,18 @@ in rec {
runHook postInstall
'';
});
installLibrary = build.overrideAttrs (_: {
buildPhase = "";
installPhase = ''
mkdir -p $out/${libSuffix}
export IDRIS2_PREFIX=$out/lib
idris2 --install ${ipkgName}
'';
});
library = { withSource ? false }:
let installCmd = if withSource then "--install-with-src" else "--install";
in executable.overrideAttrs (_: {
installPhase = ''
runHook preInstall
mkdir -p $out/${libSuffix}
export IDRIS2_PREFIX=$out/lib
idris2 ${installCmd} ${ipkgName}
runHook postInstall
'';
});
# deprecated aliases:
build = lib.warn "build is a deprecated alias for 'executable'." executable;
installLibrary = lib.warn "installLibrary is a deprecated alias for 'library { }'." (library { });
}
2 changes: 1 addition & 1 deletion nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
"TEST_IDRIS2_SUPPORT_DIR=${supportLibrariesPath}"
];

installTargets = "install-idris2 install-libs";
installTargets = "install-idris2 install-with-src-libs";
installFlags = [ "PREFIX=$(out)" ];

# TODO: Move this into its own derivation, such that this can be changed
Expand Down
4 changes: 2 additions & 2 deletions nix/templates/pkg/flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "My Idris 2 package";
description = "My Idris 2 program";

inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.idris = {
Expand All @@ -21,7 +21,7 @@
};
in rec {
packages = pkgs // idrisPkgs;
defaultPackage = pkgs.build;
defaultPackage = pkgs.executable;
devShell = npkgs.mkShell {
buildInputs = [ idrisPkgs.idris2 npkgs.rlwrap ];
shellHook = ''
Expand Down
9 changes: 5 additions & 4 deletions nix/templates/pkgWithDeps/flake.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
description = "My Idris 2 package";
description = "My Idris 2 program";

inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.idris = {
url = "github:idris-lang/Idris2";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
# some package this project depends on:
inputs.pkg = {
url = "github:idris-lang/pkg";
inputs.flake-utils.follows = "flake-utils";
Expand All @@ -17,17 +18,17 @@
flake-utils.lib.eachDefaultSystem (system:
let
npkgs = import nixpkgs { inherit system; };
my-pkg = pkg.packages.${system}.installLibrary;
my-pkg = pkg.packages.${system}.library { };
idrisPkgs = idris.packages.${system};
buildIdris = idris.buildIdris.${system};
pkgs = buildIdris {
projectName = "pkgWithDeps";
src = ./.;
idrisLibraries = [ pkg ];
idrisLibraries = [ my-pkg ];
};
in rec {
packages = pkgs // idrisPkgs;
defaultPackage = pkgs.build;
defaultPackage = pkgs.executable;
devShell = npkgs.mkShell {
buildInputs = [ idrisPkgs.idris2 npkgs.rlwrap ];
shellHook = ''
Expand Down
8 changes: 4 additions & 4 deletions nix/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ let
templateBuild = template.packages.${system}.${type};
in templateBuild;

templateBuildDefault = createTemplate ./templates/pkg/flake.nix { } "build";
templateBuildDefault = createTemplate ./templates/pkg/flake.nix { } "executable";
templateBuildDefaultLibrary =
createTemplate ./templates/pkg/flake.nix { } "installLibrary";
createTemplate ./templates/pkg/flake.nix { } "library" { };
templateBuildWithDeps = createTemplate ./templates/pkgWithDeps/flake.nix {
pkg = templateBuildDefaultLibrary;
} "build";
} "executable";

testsTemplate = {
checkFoo = ''
Expand All @@ -38,5 +38,5 @@ let
in withTests testsTemplate templateBuildDefault
// withTests testsTemplateWithDeps templateBuildWithDeps // {
idris2Tests =
idris.defaultPackage.${system}.overrideAttrs (a: { doCheck = true; });
idris.packages.${system}.default.overrideAttrs (a: { doCheck = true; });
}

0 comments on commit 8746f16

Please sign in to comment.