Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a non-overlay API for defining a config #183

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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