Skip to content

Commit

Permalink
manage spacemacs
Browse files Browse the repository at this point in the history
  • Loading branch information
dszakallas committed Jan 27, 2025
1 parent 8ff7528 commit 407d863
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 20 deletions.
5 changes: 4 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ rec {
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
poetry2nix.url = "github:nix-community/poetry2nix";
poetry2nix.inputs.nixpkgs.follows = "nixpkgs";
davids-dotfiles-private.url = "github:dszakallas/davids-dotfiles-private";
davids-dotfiles-private.inputs.nixpkgs.follows = "nixpkgs";
davids-dotfiles-private.inputs.flake-utils.follows = "flake-utils";
davids-dotfiles-private.inputs.poetry2nix.follows = "poetry2nix";
};

Expand All @@ -37,6 +39,7 @@ rec {
home-manager,
davids-dotfiles-private,
poetry2nix,
flake-utils,
...
}:
let
Expand Down Expand Up @@ -75,6 +78,16 @@ rec {
systemModules = importChildren ./modules/system;
homeModules = importChildren ./modules/home;
users = importChildren ./users;
packages = (
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
packages = lib.callPackageDirWith ./pkgs (inputs // pkgs);
in
packages
)
);
};
darwinConfigurations = {
Jellyfish = mkDarwin {
Expand Down
40 changes: 39 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, ... }:
with lib;
{
rec {
# List immediate subdirectories of a directory
subDirs =
d:
Expand All @@ -21,4 +21,42 @@ with lib;
${content}
${comment-char} +end ${name}
'';

# Return the list of importable names in a directory.
# Importable name is either
# - a regular file with the nix extension
# - or a directory containing default.nix.
importables =
root:
let
children = builtins.readDir root;
in
(builtins.attrNames (
lib.attrsets.filterAttrs (
n: t:
(t == "regular" && (builtins.match ".+\\.nix$" n) != null)
|| (t == "directory" && builtins.pathExists (root + "/${n}/default.nix"))
) children
));

# Like callPackageWith but for a while directory.
# The directory should contain nix files, or directories containing default.nix files that define packages.
# The packages are imported with their file basename as the attribute name.
callPackageDirWith =
root: ins:
let
callPkg = lib.callPackageWith all;
outs = builtins.listToAttrs (
builtins.map (f: {
name =
let
m = (builtins.match "(.+)\\.nix$" f);
in
if m != null then builtins.head m else f;
value = callPkg (root + ("/" + f)) { };
}) (importables root)
);
all = ins // outs;
in
outs;
}
22 changes: 4 additions & 18 deletions modules/home/default/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,21 @@ in
type = types.submodule {
options = {
enable = mkEnableOption "Enable Spacemacs management";
rev = mkOption {
default = "11aaddf3ad7e5e3dd3b494d56221efe7b882fd72";
type = types.str;
description = "Spacemacs revision to check out";
};
hash = mkOption {
default = "sha256-uozaV6igLIufvFzPrbt9En1VStDZDkSRRyxH62elK+8=";
type = types.str;
description = "Content hash";
};
};
};
};
};
};
config = mkIf config.davids.emacs.enable (
let
spacemacs = pkgs.fetchFromGitHub {
owner = "syl20bnr";
repo = "spacemacs";
rev = config.davids.emacs.spacemacs.rev;
hash = config.davids.emacs.spacemacs.hash;
};
spacemacs = davids-dotfiles.packages.spacemacs.${system};
loadSpacemacsInit = f: ''
(setq spacemacs-start-directory "~/.emacs.d/")
(load-file (concat "${spacemacs.out}/" "${f}"))
(setq spacemacs-start-directory "${spacemacs.out}/share/spacemacs/")
(load-file (concat spacemacs-start-directory "${f}"))
'';
in
{
home.packages = [ spacemacs ];
home.file.".files/bin/ect" = {
text = ''
#!/bin/sh
Expand Down
24 changes: 24 additions & 0 deletions pkgs/spacemacs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
stdenvNoCC,
fetchFromGitHub,
...
}:
stdenvNoCC.mkDerivation {
pname = "spacemacs";
version = "2024-01-20-develop";
src = fetchFromGitHub {
owner = "syl20bnr";
repo = "spacemacs";
rev = "11aaddf3ad7e5e3dd3b494d56221efe7b882fd72";
hash = "sha256-uozaV6igLIufvFzPrbt9En1VStDZDkSRRyxH62elK+8=";
};

patches = [
./elpa-in-userdir.diff
];

installPhase = ''
mkdir -p $out/share/spacemacs
cp -r * .lock $out/share/spacemacs
'';
}
13 changes: 13 additions & 0 deletions pkgs/spacemacs/elpa-in-userdir.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/core/core-configuration-layer.el b/core/core-configuration-layer.el
index 42224cff9..2ba1aa0d4 100644
--- a/core/core-configuration-layer.el
+++ b/core/core-configuration-layer.el
@@ -136,7 +136,7 @@ subdirectory of ROOT is used."
"Hook executed at the end of configuration loading.")

(defconst configuration-layer--elpa-root-directory
- (concat spacemacs-start-directory "elpa/")
+ (concat user-emacs-directory "elpa/")
"Spacemacs ELPA root directory.")

(defconst configuration-layer--rollback-root-directory

0 comments on commit 407d863

Please sign in to comment.