Commit b09ba65a authored by Mathew Polzin's avatar Mathew Polzin
Browse files

idris2Packages: run nixfmt

parent f438260b
Loading
Loading
Loading
Loading
+44 −26
Original line number Diff line number Diff line
{ stdenv, lib, idris2, makeWrapper
{
  stdenv,
  lib,
  idris2,
  makeWrapper,
}:
# Usage: let
#          pkg = idris2Packages.buildIdris {
@@ -11,46 +15,54 @@
#          bin = pkg.executable;
#        }
#
{ src
, ipkgName
, version ? "unversioned"
, idrisLibraries # Other libraries built with buildIdris
, ... }@attrs:
{
  src,
  ipkgName,
  version ? "unversioned",
  idrisLibraries, # Other libraries built with buildIdris
  ...
}@attrs:

let
  # loop over idrisLibraries and normalize them by turning any that are
  # direct outputs of the buildIdris function into the `.library {}`
  # property.
  idrisLibraryLibs = map (idrisLib:
    if lib.isDerivation idrisLib
    then idrisLib
    else if builtins.isFunction idrisLib
    then idrisLib {}
    else if (builtins.isAttrs idrisLib && idrisLib ? "library")
    then idrisLib.library {}
    else throw "Found an Idris2 library dependency that was not the result of the buildIdris function"
  idrisLibraryLibs = map (
    idrisLib:
    if lib.isDerivation idrisLib then
      idrisLib
    else if builtins.isFunction idrisLib then
      idrisLib { }
    else if (builtins.isAttrs idrisLib && idrisLib ? "library") then
      idrisLib.library { }
    else
      throw "Found an Idris2 library dependency that was not the result of the buildIdris function"
  ) idrisLibraries;

  propagate = libs: lib.unique (lib.concatMap (nextLib: [nextLib] ++ nextLib.propagatedIdrisLibraries) libs);
  propagate =
    libs: lib.unique (lib.concatMap (nextLib: [ nextLib ] ++ nextLib.propagatedIdrisLibraries) libs);
  ipkgFileName = ipkgName + ".ipkg";
  idrName = "idris2-${idris2.version}";
  libSuffix = "lib/${idrName}";
  propagatedIdrisLibraries = propagate idrisLibraryLibs;
  libDirs =
    (lib.makeSearchPath libSuffix propagatedIdrisLibraries) +
    ":${idris2}/${idrName}";
  libDirs = (lib.makeSearchPath libSuffix propagatedIdrisLibraries) + ":${idris2}/${idrName}";
  supportDir = "${idris2}/${idrName}/lib";
  drvAttrs = builtins.removeAttrs attrs [
    "ipkgName"
    "idrisLibraries"
  ];

  derivation = stdenv.mkDerivation (finalAttrs:
    drvAttrs // {
  derivation = stdenv.mkDerivation (
    finalAttrs:
    drvAttrs
    // {
      pname = ipkgName;
      inherit version;
      src = src;
      nativeBuildInputs = [ idris2 makeWrapper ] ++ attrs.nativeBuildInputs or [];
      nativeBuildInputs = [
        idris2
        makeWrapper
      ] ++ attrs.nativeBuildInputs or [ ];
      buildInputs = propagatedIdrisLibraries ++ attrs.buildInputs or [ ];

      IDRIS2_PACKAGE_PATH = libDirs;
@@ -71,7 +83,8 @@ let
    }
  );

in {
in
{
  executable = derivation.overrideAttrs {
    installPhase = ''
      runHook preInstall
@@ -97,9 +110,14 @@ in {
    '';
  };

  library = { withSource ? false }:
    let installCmd = if withSource then "--install-with-src" else "--install";
    in derivation.overrideAttrs {
  library =
    {
      withSource ? false,
    }:
    let
      installCmd = if withSource then "--install-with-src" else "--install";
    in
    derivation.overrideAttrs {
      installPhase = ''
        runHook preInstall
        mkdir -p $out/${libSuffix}
+13 −13
Original line number Diff line number Diff line
{ callPackage
, idris2Packages
}:
{ callPackage, idris2Packages }:

let
in {
in
{
  idris2 = callPackage ./idris2.nix { };
  idris2Lsp = callPackage ./idris2-lsp.nix { };

  buildIdris = callPackage ./build-idris.nix { };

  idris2Api = (idris2Packages.buildIdris {
  idris2Api =
    (idris2Packages.buildIdris {
      inherit (idris2Packages.idris2) src version;
      ipkgName = "idris2api";
      idrisLibraries = [ ];
+30 −19
Original line number Diff line number Diff line
{ lib, fetchFromGitHub, idris2Packages, makeWrapper }:
{
  lib,
  fetchFromGitHub,
  idris2Packages,
  makeWrapper,
}:

let
  globalLibraries = let
  globalLibraries =
    let
      idrName = "idris2-${idris2Packages.idris2.version}";
      libSuffix = "lib/${idrName}";
  in [
    in
    [
      "\\$HOME/.nix-profile/lib/${idrName}"
      "/run/current-system/sw/lib/${idrName}"
      "${idris2Packages.idris2}/${idrName}"
@@ -33,7 +40,10 @@ let
      rev = "a77ef2d563418925aa274fa29f06880dde43f4ec";
      hash = "sha256-zjfVfkpiQS9AdmTfq0hYRSelJq5Caa9VGTuFLtSvl5o=";
    };
    idrisLibraries = [idris2Api lspLib];
    idrisLibraries = [
      idris2Api
      lspLib
    ];

    nativeBuildInputs = [ makeWrapper ];
    postInstall = ''
@@ -49,4 +59,5 @@ let
      maintainers = with maintainers; [ mattpolzin ];
    };
  };
in lspPkg.executable
in
lspPkg.executable
+74 −56
Original line number Diff line number Diff line
# Almost 1:1 copy of idris2's nix/package.nix. Some work done in their flake.nix
# we do here instead.
{ stdenv
, lib
, chez
, chez-racket
, clang
, gmp
, fetchFromGitHub
, makeWrapper
, gambit
, nodejs
, zsh
, callPackage
{
  stdenv,
  lib,
  chez,
  chez-racket,
  clang,
  gmp,
  fetchFromGitHub,
  makeWrapper,
  gambit,
  nodejs,
  zsh,
  callPackage,
}:

# NOTICE: An `idris2WithPackages` is available at: https://github.com/claymager/idris2-pkgs

let
  platformChez =
    if (stdenv.system == "x86_64-linux") || (lib.versionAtLeast chez.version "10.0.0")
      then
    if (stdenv.system == "x86_64-linux") || (lib.versionAtLeast chez.version "10.0.0") then
      chez
    else
      chez-racket;
in stdenv.mkDerivation rec {
in
stdenv.mkDerivation rec {
  pname = "idris2";
  version = "0.7.0";

@@ -35,27 +36,39 @@ in stdenv.mkDerivation rec {
  };

  strictDeps = true;
  nativeBuildInputs = [ makeWrapper clang platformChez ]
    ++ lib.optionals stdenv.isDarwin [ zsh ];
  buildInputs = [ platformChez gmp ];
  nativeBuildInputs = [
    makeWrapper
    clang
    platformChez
  ] ++ lib.optionals stdenv.isDarwin [ zsh ];
  buildInputs = [
    platformChez
    gmp
  ];

  prePatch = ''
    patchShebangs --build tests
  '';

  makeFlags = [ "PREFIX=$(out)" ]
    ++ lib.optional stdenv.isDarwin "OS=";
  makeFlags = [ "PREFIX=$(out)" ] ++ lib.optional stdenv.isDarwin "OS=";

  # The name of the main executable of pkgs.chez is `scheme`
  buildFlags = [ "bootstrap" "SCHEME=scheme" ];
  buildFlags = [
    "bootstrap"
    "SCHEME=scheme"
  ];

  checkTarget = "test";
  nativeCheckInputs = [ gambit nodejs ]; # racket ];
  nativeCheckInputs = [
    gambit
    nodejs
  ]; # racket ];
  checkFlags = [ "INTERACTIVE=" ];

  # TODO: Move this into its own derivation, such that this can be changed
  #       without having to recompile idris2 every time.
  postInstall = let
  postInstall =
    let
      name = "${pname}-${version}";
      globalLibraries = [
        "\\$HOME/.nix-profile/lib/${name}"
@@ -63,7 +76,8 @@ in stdenv.mkDerivation rec {
        "$out/${name}"
      ];
      globalLibrariesPath = builtins.concatStringsSep ":" globalLibraries;
  in ''
    in
    ''
      # Remove existing idris2 wrapper that sets incorrect LD_LIBRARY_PATH
      rm $out/bin/idris2
      # The only thing we need from idris2_app is the actual binary
@@ -94,7 +108,11 @@ in stdenv.mkDerivation rec {
    mainProgram = "idris2";
    homepage = "https://github.com/idris-lang/Idris2";
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ fabianhjr wchresta mattpolzin ];
    maintainers = with lib.maintainers; [
      fabianhjr
      wchresta
      mattpolzin
    ];
    inherit (chez.meta) platforms;
  };
}
+19 −4
Original line number Diff line number Diff line
{ stdenv, lib, pname, idris2, zsh }:
{
  stdenv,
  lib,
  pname,
  idris2,
  zsh,
}:

let
  testCompileAndRun = {testName, code, want, packages ? []}: let
  testCompileAndRun =
    {
      testName,
      code,
      want,
      packages ? [ ],
    }:
    let
      packageString = builtins.concatStringsSep " " (map (p: "--package " + p) packages);
    in stdenv.mkDerivation {
    in
    stdenv.mkDerivation {
      name = "${pname}-${testName}";
      meta.timeout = 60;

@@ -34,7 +48,8 @@ let
        touch $out
      '';
    };
in {
in
{
  # Simple hello world compiles, runs and outputs as expected
  hello-world = testCompileAndRun {
    testName = "hello-world";