Skip to content

Commit

Permalink
[ refactor ] Add a nix overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchmindtree committed Sep 28, 2024
1 parent 0e83d6c commit 5db7fdd
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 44 deletions.
52 changes: 13 additions & 39 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,18 @@
description = "A custom Idris 2 package with dependencies";
};
defaultTemplate = templates.pkg;
overlays.default = import ./nix/overlay.nix {
inherit idris2Version;
shortRev = self.shortRev;
};
version = idris2Version;
};
per-system = { config ? { }, overlays ? [ ] }:
system:
let
pkgs = import nixpkgs { inherit config system overlays; };
chezSupportsSystem = (system == "x86_64-linux")
|| (pkgs.lib.versionAtLeast pkgs.chez.version "10.0.0");
chez = if chezSupportsSystem then
pkgs.chez
else
pkgs.chez-racket;
idris2Support = pkgs.callPackage ./nix/support.nix { inherit idris2Version; };
idris2Bootstrap = pkgs.callPackage ./nix/package.nix {
inherit idris2Version chez;
idris2Bootstrap = null;
support = idris2Support;
srcRev = self.shortRev or "dirty";
};
idris2Pkg = pkgs.callPackage ./nix/package.nix {
inherit idris2Version chez idris2Bootstrap;
support = idris2Support;
srcRev = self.shortRev or "dirty";
};
buildIdris = pkgs.callPackage ./nix/buildIdris.nix {
inherit idris2Version;
idris2 = idris2Pkg;
support = idris2Support;
};
idris2ApiPkg = buildIdris {
src = ./.;
ipkgName = "idris2api";
version = idris2Version;
idrisLibraries = [ ];
preBuild = ''
export IDRIS2_PREFIX=$out/lib
make src/IdrisPaths.idr
'';
pkgs = import nixpkgs {
inherit config system;
overlays = overlays ++ [ self.overlays.default ];
};
stdenv' = with pkgs; if stdenv.isDarwin then overrideSDK stdenv "11.0" else stdenv;
in {
Expand All @@ -69,16 +43,16 @@
idris = self;
};
packages = rec {
support = idris2Support;
idris2 = idris2Pkg;
idris2Api = idris2ApiPkg.library { withSource = true; };
inherit (pkgs.idris2Packages) support idris2;
idris2Api = pkgs.idris2Packages.idris2Api.library { withSource = true; };
default = idris2;
} // (import ./nix/text-editor.nix {
inherit pkgs idris-emacs-src idris2Pkg;
inherit (pkgs) idris2;
inherit pkgs idris-emacs-src;
});
inherit buildIdris;
inherit (pkgs.idris2Packages) buildIdris;
devShells.default = pkgs.mkShell.override { stdenv = stdenv'; } {
packages = idris2Pkg.buildInputs;
packages = pkgs.idris2.buildInputs;
};
};
in lib.mkOvrOptsFlake
Expand Down
3 changes: 2 additions & 1 deletion nix/buildIdris.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, idris2Version, idris2, jq, support, makeWrapper }:
{ stdenv, lib, idris2Version, idris2Packages, jq, makeWrapper }:
# Usage: let
# pkg = idris2Pkg.buildIdris {
# src = ...;
Expand All @@ -20,6 +20,7 @@ let
# loop over idrisLibraries and normalize them by turning any that are
# direct outputs of the buildIdris function into the `.library {}`
# property.
inherit (idris2Packages) idris2 support;
idrisLibraryLibs = map (idrisLib:
if lib.isDerivation idrisLib
then idrisLib
Expand Down
11 changes: 11 additions & 0 deletions nix/idris2Api.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ buildIdris, idris2Version }:
buildIdris {
src = ./..;
ipkgName = "idris2api";
version = idris2Version;
idrisLibraries = [ ];
preBuild = ''
export IDRIS2_PREFIX=$out/lib
make src/IdrisPaths.idr
'';
}
26 changes: 26 additions & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ idris2Version, shortRev ? null }:
final: prev:
let
chezSupportsSystem = (prev.system == "x86_64-linux")
|| (prev.lib.versionAtLeast prev.chez.version "10.0.0");
chez = if chezSupportsSystem then prev.chez else prev.chez-racket;
idris2Bootstrap = prev.callPackage ./package.nix {
inherit chez idris2Version;
inherit (final.idris2Packages) support;
idris2Bootstrap = null;
srcRev = if shortRev == null then "dirty" else shortRev;
};
in
{
idris2Packages = prev.idris2Packages // {
support = prev.callPackage ./support.nix { inherit idris2Version; };
idris2 = prev.callPackage ./package.nix {
inherit chez idris2Bootstrap idris2Version;
inherit (final.idris2Packages) support;
srcRev = if shortRev == null then "dirty" else shortRev;
};
buildIdris = final.callPackage ./buildIdris.nix { inherit idris2Version; };
idris2Api = final.callPackage ./idris2Api.nix { inherit idris2Version; };
};
idris2 = final.idris2Packages.idris2;
}
4 changes: 2 additions & 2 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ stdenv, lib, chez, clang, gmp, makeWrapper, installShellFiles, support, idris2Version
, srcRev, gambit, nodejs, zsh, idris2Bootstrap ? null }:
{ stdenv, lib, chez, clang, gmp, makeWrapper, installShellFiles, idris2Version
, srcRev, gambit, nodejs, support, zsh, idris2Bootstrap ? null }:

# Uses scheme to bootstrap the build of idris2
let
Expand Down
4 changes: 2 additions & 2 deletions nix/text-editor.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, idris-emacs-src, idris2Pkg }:
{ pkgs, idris-emacs-src, idris2 }:
with pkgs;
let
init-file = ./init.el;
Expand All @@ -19,7 +19,7 @@ in rec {
idris-emacs = emacsWithPackages [ idris2-mode ];
emacs-dev = makeEmacsWrapper "emacs-dev" idris-emacs init-file;
emacs-with-idris = writeShellScriptBin "emacs-with-idris" ''
export PATH=${idris2Pkg}/bin:$PATH
export PATH=${idris2}/bin:$PATH
${emacs-dev}/bin/emacs-dev $@
'';
}

0 comments on commit 5db7fdd

Please sign in to comment.