Skip to content

Commit

Permalink
Merge pull request #183 from emacs-twist/non-overlay-api
Browse files Browse the repository at this point in the history
Add a non-overlay API for defining a config
  • Loading branch information
akirak authored Nov 10, 2024
2 parents 97165e9 + 6cfc4a4 commit 4c568bc
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 28 deletions.
6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
inputs.elisp-helpers.url = "github:emacs-twist/elisp-helpers";

outputs = {...} @ inputs: {
# lib is experimental at present, so it may be removed in the future.
# The APIs under lib is unstable at present. It may undergo changes in the
# future.
lib = import ./lib inputs;
# The overlay API is deprecated.
overlays = {
default = import ./pkgs inputs;
default = import ./pkgs/overlay.nix inputs;
};
homeModules = {
emacs-twist = ./modules/home-manager.nix;
Expand Down
4 changes: 4 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let
split
filter
isString
removeAttrs
;
in
{
Expand Down Expand Up @@ -49,4 +50,7 @@ in
inherit inputs pkgs;
};
};

# A non-overlay API that builds a configuration environment.
makeEnv = { pkgs, ... }@args: import ../pkgs { inherit inputs pkgs; } (removeAttrs args [ "pkgs" ]);
}
18 changes: 9 additions & 9 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
inputs: final: prev: let
{ inputs, pkgs }:
let
lib = import ./build-support {
inherit inputs;
pkgs = prev;
inherit pkgs inputs;
};
in {
emacsTwist = lib.makeOverridable (import ./emacs {
inherit final lib;
pkgs = prev;
});
}
in
lib.makeOverridable (
import ./emacs {
inherit lib pkgs;
}
)
2 changes: 1 addition & 1 deletion pkgs/emacs/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
lib,
pkgs,
final,
final ? pkgs
}: {
emacsPackage ? pkgs.emacs,
lockDir,
Expand Down
19 changes: 19 additions & 0 deletions pkgs/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is a deprecated API which adds `emacsTwist` function to nixpkgs.
# It is recommended to use the function provided under lib.
inputs: final: prev:
let
lib = import ./build-support {
inherit inputs;
pkgs = prev;
};
in
{
emacsTwist =
args:
lib.warn "The overlay API of twist is now deprecated." (
lib.makeOverridable (import ./emacs {
inherit final lib;
pkgs = prev;
}) args
);
}
20 changes: 11 additions & 9 deletions test/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
import nixpkgs {
inherit system;
overlays = [
inputs.twist.overlays.default
(final: prev: {
emacsPackage = emacs-ci.packages.${system}.emacs-snapshot;
})
];
}
)
);

inherit (inputs.twist.lib) makeEnv;
in
{
devShells = eachSystemPkgs (pkgs: {
Expand All @@ -69,22 +70,23 @@
});

packages = eachSystemPkgs (pkgs: {
emacs = pkgs.callPackage ./twist.nix {
inherit inputs;
emacs = makeEnv (import ./twist.nix {
inherit inputs pkgs;
inherit (pkgs) emacsPackage;
};
});

# With explicit buitlins
emacs-builtins = pkgs.callPackage ./twist.nix {
inherit inputs;
emacs-builtins = makeEnv (import ./twist.nix {
inherit inputs pkgs;
inherit (pkgs) emacsPackage;
initialLibraries = inputs.emacs-builtins.data.emacs-snapshot.libraries;
};
});

# Another test path to build the whole derivation (not with --dry-run).
emacs-wrapper = pkgs.callPackage ./twist-minimal.nix {
emacs-wrapper = makeEnv (import ./twist-minimal.nix {
inherit pkgs;
inherit (pkgs) emacsPackage;
};
});

# This is an example of interactive Emacs session.
# You can start Emacs by running `nix run .#emacs-interactive`.
Expand Down
10 changes: 5 additions & 5 deletions test/twist-minimal.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
emacsTwist,
pkgs,
emacsPackage,
}:
emacsTwist {
inherit emacsPackage;
initFiles = [];
{
inherit pkgs emacsPackage;
initFiles = [ ];
lockDir = ./lock;
registries = [];
registries = [ ];
}
5 changes: 3 additions & 2 deletions test/twist.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
emacsTwist,
pkgs,
emacsPackage,
inputs,
initialLibraries ? null,
}:
emacsTwist {
{
inherit pkgs;
# Use nix-emacs-ci which is more lightweight than a regular build
inherit emacsPackage;
# In an actual configuration, you would use this:
Expand Down

0 comments on commit 4c568bc

Please sign in to comment.