Skip to content

Commit

Permalink
refactor: favor packages over overlays (#425)
Browse files Browse the repository at this point in the history
* refactor: favor packages over overlays

* ci: remove duplicate check job
  • Loading branch information
terlar authored Nov 18, 2024
1 parent 5ba2e16 commit 766a108
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 99 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,6 @@ jobs:
- name: Check
run: nix flake check

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: DeterminateSystems/nix-installer-action@da36cb69b1c3247ad7a1f931ebfd954a1105ef14 # v14
with:
nix-package-url: https://releases.nixos.org/nix/nix-2.18.2/nix-2.18.2-x86_64-linux.tar.xz
extra-conf: |
http-connections = 50
max-jobs = auto
diagnostic-endpoint: ''

- uses: cachix/cachix-action@ad2ddac53f961de1989924296a1f236fcfbaa4fc # v15
with:
useDaemon: true
name: terlar
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
extraPullNames: nix-community

- name: Check
run: nix flake check

build:
strategy:
matrix:
Expand Down
21 changes: 21 additions & 0 deletions dev/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@
};

packages = {
default = pkgs.writeShellApplication {
name = "test-emacs-config";
runtimeInputs = [
config.packages.emacs-env
pkgs.xorg.lndir
];
text = ''
XDG_DATA_DIRS="$XDG_DATA_DIRS:${
builtins.concatStringsSep ":" (map (x: "${x}/share") config.packages.emacs-config.buildInputs)
}"
EMACS_DIR="$(mktemp -td emacs.XXXXXXXXXX)"
lndir -silent ${config.packages.emacs-config} "$EMACS_DIR"
emacs --init-directory "$EMACS_DIR" "$@"
'';
};

reloadEmacsConfig = pkgs.writeShellApplication {
name = "reload-emacs-config";
text = ''
Expand Down Expand Up @@ -92,5 +108,10 @@
'';
};
};

checks = {
build-config = config.packages.emacs-config;
build-env = config.packages.emacs-env;
};
};
}
4 changes: 2 additions & 2 deletions dev/test-home-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ in
modules = [
rootConfig.flake.homeManagerModules.emacsConfig
{
nixpkgs.overlays = [ rootConfig.flake.overlays.default ];

home = {
stateVersion = "22.05";
username = "test";
Expand All @@ -24,6 +22,8 @@ in

custom.emacsConfig = {
enable = true;
package = config.packages.emacs-env;
configPackage = config.packages.emacs-config;
erc = pkgs.writeText "ercrc.el" ''
;; Testing testing
'';
Expand Down
113 changes: 42 additions & 71 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,98 +53,69 @@

partitions.dev = {
extraInputsFlake = ./dev;
module = {
imports = [ ./dev/flake-module.nix ];
};
module.imports = [ ./dev/flake-module.nix ];
};

flake = {
overlays.default = inputs.nixpkgs.lib.composeManyExtensions [
inputs.emacs-overlay.overlays.emacs
inputs.org-babel.overlays.default
inputs.twist.overlays.default
homeManagerModules.emacsConfig = import ./nix/home-manager.nix;
};

(
final: prev:
perSystem =
{
config,
pkgs,
inputs',
...
}:
{
packages =
let
emacsPackage = final.emacs-git;
inherit (inputs.nixpkgs) lib;

initEl = lib.pipe ./init.org [
builtins.readFile
(inputs.org-babel.lib.tangleOrgBabel { })
(builtins.toFile "init.el")
];

packageOverrides = _: prev: {
elispPackages = prev.elispPackages.overrideScope (
pkgs.callPackage ./nix/packageOverrides.nix { inherit (prev) emacs; }
);
};
in
{
emacs = inputs'.emacs-overlay.packages.emacs-git;
emacs-env =
(final.emacsTwist {
inherit emacsPackage;

initFiles = [ (final.tangleOrgBabelFile "init.el" ./init.org { }) ];
(inputs.twist.lib.makeEnv {
inherit pkgs;
emacsPackage = config.packages.emacs;

initFiles = [ initEl ];
lockDir = ./lock;

registries = import ./nix/registries.nix {
inherit inputs;
emacsSrc = emacsPackage.src;
emacsSrc = config.packages.emacs.src;
};
inputOverrides = import ./nix/inputOverrides.nix { inherit (inputs.nixpkgs) lib; };

inputOverrides = import ./nix/inputOverrides.nix { inherit lib; };
}).overrideScope
(
_: tprev: {
elispPackages = tprev.elispPackages.overrideScope (
prev.callPackage ./nix/packageOverrides.nix { inherit (tprev) emacs; }
);
}
);

emacs-config = prev.callPackage inputs.self {
buildElispPackage = (inputs.twist.lib.buildElispPackage final).override {
emacs = emacsPackage;
packageOverrides;

emacs-config = pkgs.callPackage inputs.self {
buildElispPackage = (inputs.twist.lib.buildElispPackage pkgs).override {
inherit (config.packages) emacs;
};

elispInputs = prev.lib.pipe final.emacs-env.elispPackages [
elispInputs = lib.pipe config.packages.emacs-env.elispPackages [
builtins.attrValues
(builtins.filter prev.lib.isDerivation)
(builtins.filter lib.isDerivation)
];
};
}
)
];
homeManagerModules = {
emacsConfig = import ./nix/home-manager.nix;
};
};

perSystem =
{
config,
pkgs,
inputs',
...
}:
{
_module.args.pkgs = inputs'.nixpkgs.legacyPackages.extend inputs.self.overlays.default;

packages = {
inherit (pkgs) emacs-config emacs-env;

default = pkgs.writeShellApplication {
name = "test-emacs-config";
runtimeInputs = [
pkgs.emacs-env
pkgs.xorg.lndir
];
text = ''
XDG_DATA_DIRS="$XDG_DATA_DIRS:${
builtins.concatStringsSep ":" (map (x: "${x}/share") pkgs.emacs-config.buildInputs)
}"
EMACS_DIR="$(mktemp -td emacs.XXXXXXXXXX)"
lndir -silent ${pkgs.emacs-config} "$EMACS_DIR"
emacs --init-directory "$EMACS_DIR" "$@"
'';
};
};

checks = {
build-config = config.packages.emacs-config;
build-env = config.packages.emacs-env;
};

apps = pkgs.emacs-env.makeApps { lockDirName = "lock"; };
apps = config.packages.emacs-env.makeApps { lockDirName = "lock"; };
};
};
}
4 changes: 0 additions & 4 deletions nix/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ in

package = mkOption {
type = types.package;
default = pkgs.emacs-env;
defaultText = literalExample "pkgs.emacs-env";
description = "The default Emacs derivation to use.";
};

configPackage = mkOption {
type = types.package;
default = pkgs.emacs-config;
defaultText = literalExample "pkgs.emacs-config";
description = "The default Emacs config derivation to use.";
};

Expand Down

0 comments on commit 766a108

Please sign in to comment.