home/modules/baremacs:init

move emacs to home-manager
This commit is contained in:
2022-03-18 01:50:43 +05:30
parent ed3bf181ef
commit e2e9d5ec0f
12 changed files with 367 additions and 195 deletions

72
flake.lock generated
View File

@@ -18,11 +18,11 @@
},
"emacs": {
"locked": {
"lastModified": 1647162387,
"narHash": "sha256-TK3jhGCsQkzlz43iKwUYk5c1xDZm2LkPn9LxpWczYs8=",
"lastModified": 1647335267,
"narHash": "sha256-O//CN+V9b7dbnDmWRdrMFVk2Uq0COMLh8PryN4W7fIc=",
"owner": "nix-community",
"repo": "emacs-overlay",
"rev": "43fa2ef6dc8e0f9dbbbb26564b22b75478b7ef0b",
"rev": "d43b200ed5675bf912440975435dd7a7363f9481",
"type": "github"
},
"original": {
@@ -97,11 +97,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1647174789,
"narHash": "sha256-baXTzUZDx3KQ6PH5SvuiurgCnE417S+Za3q5FtSZiPo=",
"lastModified": 1647210221,
"narHash": "sha256-mUWwEq+ReRQjIqj28ClqmBDyKV4fr6C5ufqlXLzZFsk=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "5d4327cff4a5e54be8ca33d7c8a8dce6bdb64b93",
"rev": "8eb7c009f09f1f7b1ec151e5d537104acf42213a",
"type": "github"
},
"original": {
@@ -151,11 +151,11 @@
},
"master": {
"locked": {
"lastModified": 1647176932,
"narHash": "sha256-822tW7LLmC/eoR70szNeyvsHIje24brAgbfixp37iuk=",
"lastModified": 1647362511,
"narHash": "sha256-eVJNniAVP8RSH9EWcAnj1td9jJkY+J257QD6wfd7FLQ=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d853dc52d87692619412a074846144262d6a48b3",
"rev": "d1b993abaa6dc6df5014bb70fd1111f39f310bec",
"type": "github"
},
"original": {
@@ -194,11 +194,11 @@
},
"locked": {
"dir": "contrib",
"lastModified": 1647152497,
"narHash": "sha256-KNqAdyM0DQPSqb/low6Py9eUBQjfga0KAHAF6naMd7Y=",
"lastModified": 1647310800,
"narHash": "sha256-DvKvdwXp1K8dtxk+IIGK/HxurmMRhkuTdfj44rDRsdw=",
"owner": "neovim",
"repo": "neovim",
"rev": "c9b94188d5f96349566372e8a0ce94e14fd6b549",
"rev": "bef7552f7088ff411bd68fc236cfd7b269ad157e",
"type": "github"
},
"original": {
@@ -229,11 +229,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1646955661,
"narHash": "sha256-AYLta1PubJnrkv15+7G+6ErW5m9NcI9wSdJ+n7pKAe0=",
"lastModified": 1647350163,
"narHash": "sha256-OcMI+PFEHTONthXuEQNddt16Ml7qGvanL3x8QOl2Aao=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e9545762b032559c27d8ec9141ed63ceca1aa1ac",
"rev": "3eb07eeafb52bcbf02ce800f032f18d666a9498d",
"type": "github"
},
"original": {
@@ -243,11 +243,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1646955661,
"narHash": "sha256-AYLta1PubJnrkv15+7G+6ErW5m9NcI9wSdJ+n7pKAe0=",
"lastModified": 1647350163,
"narHash": "sha256-OcMI+PFEHTONthXuEQNddt16Ml7qGvanL3x8QOl2Aao=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e9545762b032559c27d8ec9141ed63ceca1aa1ac",
"rev": "3eb07eeafb52bcbf02ce800f032f18d666a9498d",
"type": "github"
},
"original": {
@@ -302,11 +302,11 @@
},
"nixpkgs_6": {
"locked": {
"lastModified": 1646955661,
"narHash": "sha256-AYLta1PubJnrkv15+7G+6ErW5m9NcI9wSdJ+n7pKAe0=",
"lastModified": 1647350163,
"narHash": "sha256-OcMI+PFEHTONthXuEQNddt16Ml7qGvanL3x8QOl2Aao=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e9545762b032559c27d8ec9141ed63ceca1aa1ac",
"rev": "3eb07eeafb52bcbf02ce800f032f18d666a9498d",
"type": "github"
},
"original": {
@@ -318,11 +318,11 @@
},
"nixpkgs_7": {
"locked": {
"lastModified": 1646939531,
"narHash": "sha256-bxOjVqcsccCNm+jSmEh/bm0tqfE3SdjwS+p+FZja3ho=",
"lastModified": 1647125019,
"narHash": "sha256-PXA76/iIqtbrA0ydCyc7Wpdw7TQTnfEowM87YtTXfB4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "fcd48a5a0693f016a5c370460d0c2a8243b882dc",
"rev": "b0e141e3fe13ec21f50429773d2e3890e02a80da",
"type": "github"
},
"original": {
@@ -350,11 +350,11 @@
},
"nur": {
"locked": {
"lastModified": 1647175668,
"narHash": "sha256-6AKGFi5BI6/u4Ux9a66hXTZ7jNmDdmlVZS71lL6EWL4=",
"lastModified": 1647319391,
"narHash": "sha256-aP33NF1dw0keAsRcT6f416NMR6sqyoMiRmFz3YgTWsM=",
"owner": "nix-community",
"repo": "NUR",
"rev": "528c18d44723070591ac643a2ad1885b86a48904",
"rev": "b8be7192aa2050aadfd06cd14c776f0478e9a146",
"type": "github"
},
"original": {
@@ -370,11 +370,11 @@
"nixpkgs": "nixpkgs_7"
},
"locked": {
"lastModified": 1647159229,
"narHash": "sha256-aGawpstqvThlV5OWqCAFIFBc8apYvMT/Qwig111coSo=",
"lastModified": 1647332154,
"narHash": "sha256-fCZWPR53MfOHhVC4VEjYeIWPzJbCo/lLOubNoswfTS0=",
"owner": "nix-community",
"repo": "neovim-nightly-overlay",
"rev": "4cf0e4a5738fb247f191a35c7c3900c4f06caca3",
"rev": "0817ca26e18dbf5eb8dc61a7e68f9d7f6b3fbe68",
"type": "github"
},
"original": {
@@ -423,11 +423,11 @@
"nixpkgs": "nixpkgs_8"
},
"locked": {
"lastModified": 1647138040,
"narHash": "sha256-rG9G4ND7hoG7VVIe614s0s76jEcZjhFm1JO1m5EiSsI=",
"lastModified": 1647311412,
"narHash": "sha256-QS/7FRv48jCp/5t9jAgJL+Psx+wuUdwu5g35XHLmpDw=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "c984623eb0584a2aadeca505dd85ec68a3f5a576",
"rev": "e005f7e14ce46b4309ac723ba2c8acbc6c6cee61",
"type": "github"
},
"original": {
@@ -438,11 +438,11 @@
},
"stable": {
"locked": {
"lastModified": 1646933238,
"narHash": "sha256-RZJnLN0o4B35eTnUc2tEAD12X5TNeeJhhvH3Fd6Pmdo=",
"lastModified": 1647282937,
"narHash": "sha256-K8Oo6QyFCfiEWTRpQVfzcwI3YNMKlz6Tu8rr+o3rzRQ=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "bacbfd713b4781a4a82c1f390f8fe21ae3b8b95b",
"rev": "64fc73bd74f04d3e10cb4e70e1c65b92337e76db",
"type": "github"
},
"original": {

View File

@@ -59,7 +59,6 @@
./modules/nvidia-offload.nix
./modules/sound.nix
./modules/xorg.nix
./modules/emacs
];
commonModules = [
./modules/nvim
@@ -71,6 +70,7 @@
];
homeModules = [
./home/modules/secret.nix
./home/modules/baremacs.nix
];
builders = [ ./modules/x86builder.nix ];
in

View File

@@ -4,14 +4,9 @@ echo "You're about to switch your home-manager configuration as '$USER'"
read -p "Continue (y/n)?" conf
if [[ ${conf,,} =~ ^(y|yes)$ ]]; then
read -p "Do you want to use sudo instead of doas? (y/n)" conf2
elev="doas"
if [[ ${conf2,,} =~ ^(y|yes)$ ]]; then
elev="sudo"
fi
$elev nix build .\#hm-configs.$USER.activationPackage -o hm-result
nix build .\#hm-configs.$USER.activationPackage -o hm-result &&
./hm-result/activate
$elev unlink hm-result
unlink hm-result
else
echo "If this is not you, then log into your profile first!"
exit 1

164
home/modules/baremacs.nix Normal file
View File

@@ -0,0 +1,164 @@
#modified version of home-manager emacs service module for personal use
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.baremacs;
emacsCfg = config.programs.emacs;
emacsBinPath = "${cfg.package}/bin";
# Match the default socket path for the Emacs version so emacsclient continues
# to work without wrapping it.
socketDir = "%t/emacs";
socketPath = "${socketDir}/server";
in
{
options.services.baremacs = {
enable = mkEnableOption "the Emacs daemon";
package = mkOption {
type = types.package;
default = pkgs.emacs;
defaultText = literalExpression ''
pkgs.emacs
'';
description = "The Emacs package to use.";
};
socketActivation = {
enable = mkEnableOption "systemd socket activation for the Emacs service";
};
defaultEditor = {
enable = mkOption rec {
type = types.bool;
default = false;
example = !default;
description = "Whether to change the EDITOR environment variable or not";
};
editor = mkOption rec {
type = types.enum [ "emacs" "emacsclient" ];
default = null;
example = "emacsclient";
description = "Whether to change the EDITOR environment variable or not";
};
};
copyConfigFiles = {
enable = mkOption rec {
type = types.bool;
default = false;
example = !default;
description = "Whether to copy the config files to ~/.emacs.d or not";
};
files = mkOption rec {
type = types.attrsOf types.path;
default = { };
example = { "init.el" = ./init.el; };
description = "What files to copy under what name";
};
};
};
config = mkIf cfg.enable (mkMerge [
{
assertions = [
(lib.hm.assertions.assertPlatform "services.emacs" pkgs
lib.platforms.linux)
{
assertion = cfg.defaultEditor.enable -> cfg.defaultEditor.editor != null;
message = ''
services.baremacs.defaultEditor.enable requires services.baremacs.defaultEditor.editor to be set
'';
}
];
systemd.user.services.emacs = {
Unit = {
Description = "Emacs text editor";
Documentation =
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
# Avoid killing the Emacs session, which may be full of
# unsaved buffers.
X-RestartIfChanged = false;
} // optionalAttrs (cfg.socketActivation.enable) {
# Emacs deletes its socket when shutting down, which systemd doesn't
# handle, resulting in a server without a socket.
# See https://github.com/nix-community/home-manager/issues/2018
RefuseManualStart = true;
};
Service = {
Type = "notify";
# We wrap ExecStart in a login shell so Emacs starts with the user's
# environment, most importantly $PATH and $NIX_PROFILES. It may be
# worth investigating a more targeted approach for user services to
# iport the user environment.
ExecStart = ''
${pkgs.runtimeShell} -l -c "${emacsBinPath}/emacs --fg-daemon${
# In case the user sets 'server-directory' or 'server-name' in
# their Emacs config, we want to specify the socket path explicitly
# so launching 'emacs.service' manually doesn't break emacsclient
# when using socket activation.
optionalString cfg.socketActivation.enable
"=${escapeShellArg socketPath}"
}"'';
# Emacs will exit with status 15 after having received SIGTERM, which
# is the default "KillSignal" value systemd uses to stop services.
SuccessExitStatus = 15;
Restart = "on-failure";
} // optionalAttrs (cfg.socketActivation.enable) {
# Use read-only directory permissions to prevent emacs from
# deleting systemd's socket file before exiting.
ExecStartPost =
"${pkgs.coreutils}/bin/chmod --changes -w ${socketDir}";
ExecStopPost =
"${pkgs.coreutils}/bin/chmod --changes +w ${socketDir}";
};
} // optionalAttrs (!cfg.socketActivation.enable) {
Install = { WantedBy = [ "default.target" ]; };
};
home = {
sessionVariables = mkIf cfg.defaultEditor.enable {
EDITOR = let editor = cfg.defaultEditor.editor; in
getBin (pkgs.writeShellScript "editor" ''
exec ${
getBin cfg.package
}/bin/'' + editor + head (optional (editor == "emacsclient") '' "''${@:---create-frame}"''));
};
file = mkIf cfg.copyConfigFiles.enable
(mapAttrs'
(n: v:
attrsets.nameValuePair (".emacs.d/" + n) { source = v; })
cfg.copyConfigFiles.files);
};
}
(mkIf cfg.socketActivation.enable {
systemd.user.sockets.emacs = {
Unit = {
Description = "Emacs text editor";
Documentation =
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
};
Socket = {
ListenStream = socketPath;
FileDescriptorName = "server";
SocketMode = "0600";
DirectoryMode = "0700";
};
Install = { WantedBy = [ "sockets.target" ]; };
};
})
]);
}

View File

@@ -1 +1 @@
../../../modules/emacs/init.el
../../../../overlays/emacs/init.el

View File

@@ -4,6 +4,18 @@ let
in
{
services = {
baremacs = {
enable = true;
package = pkgs.mymacs;
defaultEditor = {
enable = true;
editor = "emacsclient";
};
copyConfigFiles = {
enable = true;
files = { "init.el" = ./config/emacs/init.el; };
};
};
picom = {
experimentalBackends = true;
enable = true;

View File

@@ -55,6 +55,12 @@
fcitx.engines = with pkgs.fcitx-engines; [ m17n mozc ];
};
};
virtualisation.docker.enable = true;
virtualisation = {
docker.enable = true;
podman = {
enable = true;
enableNvidia = true;
};
};
gtk.iconCache.enable = true;
}

View File

@@ -1,65 +0,0 @@
{ pkgs, ... }:
{
services.emacs = {
enable = true;
package = with pkgs; emacsWithPackagesFromUsePackage {
config = ./init.el;
package = emacsGcc;
alwaysEnsure = true;
extraEmacsPackages = epkgs: with epkgs; [
use-package
tsc
];
#https://github.com/NixOS/nixpkgs/issues/108089
override = epkgs: epkgs // {
tsc = epkgs.melpaPackages.tsc.overrideAttrs (oa:
let
version = "0.18.0";
tsc-dyn = fetchurl {
url = "https://github.com/emacs-tree-sitter/elisp-tree-sitter/releases/download/${version}/tsc-dyn.so";
sha256 = "sha256-97KDzdYNJN4ceJeuQxZtQ/7iU0CYXEp6gcSM9rNwlyE=";
};
in
{
postInstall = ''
cp ${tsc-dyn} $out/share/emacs/site-lisp/elpa/tsc-${oa.version}/tsc-dyn.so
echo -n ${version} > $out/share/emacs/site-lisp/elpa/tsc-${oa.version}/DYN-VERSION
'';
});
tree-sitter-langs = epkgs.melpaPackages.tree-sitter-langs.overrideAttrs (oa:
let
version = "0.11.3";
tree-sitter-grammars = super.stdenv.mkDerivation rec {
inherit version;
name = "tree-sitter-grammars";
src = fetchzip {
url = "https://github.com/emacs-tree-sitter/tree-sitter-langs/releases/download/${version}/tree-sitter-grammars-linux-${version}.tar.gz";
sha256 = "sha256-85Yy6NuEVnibehmalz2qr0pCENYwmxsyyIf0TUYnDY8=";
stripRoot = false;
};
installPhase = ''
install -d $out/langs/bin
echo -n "${version}" > $out/langs/bin/BUNDLE-VERSION
install -m444 * $out/langs/bin
'';
};
in
{
src = fetchFromGitHub {
owner = "emacs-tree-sitter";
repo = "tree-sitter-langs";
rev = version;
sha256 = "sha256-Br+ON7a8FWoU75ySPSP2DkiyHjj80TP5XvcMMJrU9+k=";
};
postPatch = ''
substituteInPlace ./tree-sitter-langs-build.el \
--replace "tree-sitter-langs-grammar-dir tree-sitter-langs--dir" "tree-sitter-langs-grammar-dir \"${tree-sitter-grammars}/langs\""
'';
});
gruvbox-theme = epkgs.melpaPackages.gruvbox-theme.overrideAttrs (_: { patches = [ ./gruvbox-el.patch ]; });
};
};
};
}

View File

@@ -0,0 +1,59 @@
{ emacsWithPackagesFromUsePackage, stdenv, fetchzip, fetchurl, fetchFromGitHub, emacsGcc, ... }:
emacsWithPackagesFromUsePackage {
config = ./init.el;
package = emacsGcc;
alwaysEnsure = true;
extraEmacsPackages = epkgs: with epkgs; [
use-package
tsc
];
#https://github.com/NixOS/nixpkgs/issues/108089
override = epkgs: epkgs // {
tsc = epkgs.melpaPackages.tsc.overrideAttrs (oa:
let
version = "0.18.0";
tsc-dyn = fetchurl {
url = "https://github.com/emacs-tree-sitter/elisp-tree-sitter/releases/download/${version}/tsc-dyn.so";
sha256 = "sha256-97KDzdYNJN4ceJeuQxZtQ/7iU0CYXEp6gcSM9rNwlyE=";
};
in
{
postInstall = ''
cp ${tsc-dyn} $out/share/emacs/site-lisp/elpa/tsc-${oa.version}/tsc-dyn.so
echo -n ${version} > $out/share/emacs/site-lisp/elpa/tsc-${oa.version}/DYN-VERSION
'';
});
tree-sitter-langs = epkgs.melpaPackages.tree-sitter-langs.overrideAttrs (oa:
let
version = "0.11.3";
tree-sitter-grammars = stdenv.mkDerivation rec {
inherit version;
name = "tree-sitter-grammars";
src = fetchzip {
url = "https://github.com/emacs-tree-sitter/tree-sitter-langs/releases/download/${version}/tree-sitter-grammars-linux-${version}.tar.gz";
sha256 = "sha256-85Yy6NuEVnibehmalz2qr0pCENYwmxsyyIf0TUYnDY8=";
stripRoot = false;
};
installPhase = ''
install -d $out/langs/bin
echo -n "${version}" > $out/langs/bin/BUNDLE-VERSION
install -m444 * $out/langs/bin
'';
};
in
{
src = fetchFromGitHub {
owner = "emacs-tree-sitter";
repo = "tree-sitter-langs";
rev = version;
sha256 = "sha256-Br+ON7a8FWoU75ySPSP2DkiyHjj80TP5XvcMMJrU9+k=";
};
postPatch = ''
substituteInPlace ./tree-sitter-langs-build.el \
--replace "tree-sitter-langs-grammar-dir tree-sitter-langs--dir" "tree-sitter-langs-grammar-dir \"${tree-sitter-grammars}/langs\""
'';
});
gruvbox-theme = epkgs.melpaPackages.gruvbox-theme.overrideAttrs (_: { patches = [ ./gruvbox-el.patch ]; });
};
}

View File

@@ -2,4 +2,5 @@ final: prev: {
mpd_discord_richpresence = prev.callPackage ./mpd-rpc {};
customscripts = prev.callPackage ./customscripts {};
gruvbox-icons = prev.callPackage ./gruvbox-icons {};
mymacs = prev.callPackage ./emacs {};
}