default.nix: run nixfmt
This commit is contained in:
239
default.nix
239
default.nix
@@ -1,14 +1,15 @@
|
|||||||
{ # The files would be going to ~/.config/doom (~/.doom.d)
|
{ # The files would be going to ~/.config/doom (~/.doom.d)
|
||||||
doomPrivateDir
|
doomPrivateDir
|
||||||
/* Extra packages to install
|
/* Extra packages to install
|
||||||
|
|
||||||
Useful for non-emacs packages containing emacs bindings (e.g.
|
Useful for non-emacs packages containing emacs bindings (e.g.
|
||||||
mu4e).
|
mu4e).
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
extraPackages = epkgs: [ pkgs.mu ];
|
extraPackages = epkgs: [ pkgs.mu ];
|
||||||
*/
|
*/
|
||||||
, extraPackages ? epkgs: []
|
, extraPackages ? epkgs:
|
||||||
|
[ ]
|
||||||
/* Extra configuration to source during initialization
|
/* Extra configuration to source during initialization
|
||||||
|
|
||||||
Use this to refer other nix derivations.
|
Use this to refer other nix derivations.
|
||||||
@@ -24,18 +25,19 @@
|
|||||||
Only used to get emacs package, if `bundledPackages` is set.
|
Only used to get emacs package, if `bundledPackages` is set.
|
||||||
*/
|
*/
|
||||||
, emacsPackages
|
, emacsPackages
|
||||||
/* Overlay to customize emacs (elisp) dependencies
|
/* Overlay to customize emacs (elisp) dependencies
|
||||||
|
|
||||||
See overrides.nix for addition examples.
|
See overrides.nix for addition examples.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
emacsPackagesOverlay = self: super: {
|
emacsPackagesOverlay = self: super: {
|
||||||
magit-delta = super.magit-delta.overrideAttrs (esuper: {
|
magit-delta = super.magit-delta.overrideAttrs (esuper: {
|
||||||
buildInputs = esuper.buildInputs ++ [ pkgs.git ];
|
buildInputs = esuper.buildInputs ++ [ pkgs.git ];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
, emacsPackagesOverlay ? self: super: { }
|
, emacsPackagesOverlay ? self: super:
|
||||||
|
{ }
|
||||||
/* Use bundled revision of github.com/nix-community/emacs-overlay
|
/* Use bundled revision of github.com/nix-community/emacs-overlay
|
||||||
as `emacsPackages`.
|
as `emacsPackages`.
|
||||||
*/
|
*/
|
||||||
@@ -52,38 +54,31 @@
|
|||||||
"emacs-overlay" = fetchFromGitHub { owner = /* ...*\/; };
|
"emacs-overlay" = fetchFromGitHub { owner = /* ...*\/; };
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
, dependencyOverrides ? { }
|
, dependencyOverrides ? { }, lib, pkgs, stdenv, buildEnv, makeWrapper
|
||||||
, lib
|
, runCommand, fetchFromGitHub, substituteAll, writeShellScript
|
||||||
, pkgs
|
, writeShellScriptBin, writeTextDir }:
|
||||||
, stdenv
|
|
||||||
, buildEnv
|
|
||||||
, makeWrapper
|
|
||||||
, runCommand
|
|
||||||
, fetchFromGitHub
|
|
||||||
, substituteAll
|
|
||||||
, writeShellScript
|
|
||||||
, writeShellScriptBin
|
|
||||||
, writeTextDir }:
|
|
||||||
|
|
||||||
assert (lib.assertMsg (
|
assert (lib.assertMsg ((builtins.isPath doomPrivateDir)
|
||||||
(builtins.isPath doomPrivateDir) ||
|
|| (lib.isDerivation doomPrivateDir) || (lib.isStorePath doomPrivateDir))
|
||||||
(lib.isDerivation doomPrivateDir) ||
|
"doomPrivateDir must be either a path, a derivation or a stringified store path");
|
||||||
(lib.isStorePath doomPrivateDir)) "doomPrivateDir must be either a path, a derivation or a stringified store path");
|
|
||||||
|
|
||||||
let
|
let
|
||||||
flake = import ./flake-compat-helper.nix { src=./.; };
|
flake = import ./flake-compat-helper.nix { src = ./.; };
|
||||||
lock = p: if dependencyOverrides ? ${p}
|
lock = p:
|
||||||
then dependencyOverrides.${p}
|
if dependencyOverrides ? ${p} then
|
||||||
else flake.inputs.${p};
|
dependencyOverrides.${p}
|
||||||
|
else
|
||||||
|
flake.inputs.${p};
|
||||||
# Packages we need to get the default doom configuration run
|
# Packages we need to get the default doom configuration run
|
||||||
overrides = self: super:
|
overrides = self: super:
|
||||||
(pkgs.callPackage ./overrides.nix { inherit lock; } self super) // (emacsPackagesOverlay self super);
|
(pkgs.callPackage ./overrides.nix { inherit lock; } self super)
|
||||||
|
// (emacsPackagesOverlay self super);
|
||||||
|
|
||||||
# Stage 1: prepare source for byte-compilation
|
# Stage 1: prepare source for byte-compilation
|
||||||
doomSrc = stdenv.mkDerivation {
|
doomSrc = stdenv.mkDerivation {
|
||||||
name = "doom-src";
|
name = "doom-src";
|
||||||
src = lock "doom-emacs";
|
src = lock "doom-emacs";
|
||||||
phases = ["unpackPhase" "patchPhase" "installPhase"];
|
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
||||||
patches = [
|
patches = [
|
||||||
(substituteAll {
|
(substituteAll {
|
||||||
src = ./fix-paths.patch;
|
src = ./fix-paths.patch;
|
||||||
@@ -97,80 +92,74 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
fmt = {
|
fmt = {
|
||||||
reset=''\\033[0m'';
|
reset = "\\\\033[0m";
|
||||||
bold=''\\033[1m'';
|
bold = "\\\\033[1m";
|
||||||
red=''\\033[31m'';
|
red = "\\\\033[31m";
|
||||||
green=''\\033[32m'';
|
green = "\\\\033[32m";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Bundled version of `emacs-overlay`
|
# Bundled version of `emacs-overlay`
|
||||||
emacs-overlay = import (lock "emacs-overlay") pkgs pkgs;
|
emacs-overlay = import (lock "emacs-overlay") pkgs pkgs;
|
||||||
|
|
||||||
# Stage 2: install dependencies and byte-compile prepared source
|
# Stage 2: install dependencies and byte-compile prepared source
|
||||||
doomLocal =
|
doomLocal = let
|
||||||
let
|
straight-env = pkgs.callPackage (lock "nix-straight") {
|
||||||
straight-env = pkgs.callPackage (lock "nix-straight") {
|
emacsPackages = if bundledPackages then
|
||||||
emacsPackages =
|
let epkgs = emacs-overlay.emacsPackagesFor emacsPackages.emacs;
|
||||||
if bundledPackages then
|
in epkgs.overrideScope' overrides
|
||||||
let
|
else
|
||||||
epkgs = emacs-overlay.emacsPackagesFor emacsPackages.emacs;
|
emacsPackages.overrideScope' overrides;
|
||||||
in epkgs.overrideScope' overrides
|
emacs = emacsPackages.emacsWithPackages extraPackages;
|
||||||
else
|
emacsLoadFiles = [ ./advice.el ];
|
||||||
emacsPackages.overrideScope' overrides;
|
emacsArgs = [ "--" "install" ];
|
||||||
emacs = emacsPackages.emacsWithPackages extraPackages;
|
|
||||||
emacsLoadFiles = [ ./advice.el ];
|
|
||||||
emacsArgs = [
|
|
||||||
"--"
|
|
||||||
"install"
|
|
||||||
];
|
|
||||||
|
|
||||||
# Need to reference a store path here, as byte-compilation will bake-in
|
# Need to reference a store path here, as byte-compilation will bake-in
|
||||||
# absolute path to source files.
|
# absolute path to source files.
|
||||||
emacsInitFile = "${doomSrc}/bin/doom";
|
emacsInitFile = "${doomSrc}/bin/doom";
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = straight-env.packageList (super: {
|
packages = straight-env.packageList (super: {
|
||||||
phases = [ "installPhase" ];
|
|
||||||
preInstall = ''
|
|
||||||
export DOOMDIR=${doomPrivateDir}
|
|
||||||
export DOOMLOCALDIR=$(mktemp -d)/local/
|
|
||||||
'';
|
|
||||||
});
|
|
||||||
|
|
||||||
# I don't know why but byte-compilation somehow triggers Emacs to look for
|
|
||||||
# the git executable. It does not seem to be executed though...
|
|
||||||
git = writeShellScriptBin "git" ''
|
|
||||||
>&2 echo "Executing git is not allowed; command line:" "$@"
|
|
||||||
exit 127
|
|
||||||
'';
|
|
||||||
in (straight-env.emacsEnv {
|
|
||||||
inherit packages;
|
|
||||||
straightDir = "$DOOMLOCALDIR/straight";
|
|
||||||
}).overrideAttrs (super: {
|
|
||||||
phases = [ "installPhase" ];
|
phases = [ "installPhase" ];
|
||||||
buildInputs = super.buildInputs ++ [ git ];
|
|
||||||
preInstall = ''
|
preInstall = ''
|
||||||
export DOOMDIR=${doomPrivateDir}
|
export DOOMDIR=${doomPrivateDir}
|
||||||
export DOOMLOCALDIR=$out/
|
export DOOMLOCALDIR=$(mktemp -d)/local/
|
||||||
|
|
||||||
# Create a bogus $HOME directory because gccEmacs is known to require
|
|
||||||
# an existing home directory because the async worker process don't
|
|
||||||
# fully respect the value of 'comp-eln-load-path'.
|
|
||||||
export HOME=$(mktemp -d)
|
|
||||||
'';
|
|
||||||
postInstall = ''
|
|
||||||
# If gccEmacs or anything would write in $HOME, fail the build.
|
|
||||||
if [[ -z "$(find $HOME -maxdepth 0 -empty)" ]]; then
|
|
||||||
printf "${fmt.red}${fmt.bold}ERROR:${fmt.reset} "
|
|
||||||
printf "${fmt.red}doom-emacs build resulted in files being written in "'$HOME'" of the build sandbox.\n"
|
|
||||||
printf "Contents of "'$HOME'":\n"
|
|
||||||
find $HOME
|
|
||||||
printf ${fmt.reset}
|
|
||||||
exit 33
|
|
||||||
fi
|
|
||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
# I don't know why but byte-compilation somehow triggers Emacs to look for
|
||||||
|
# the git executable. It does not seem to be executed though...
|
||||||
|
git = writeShellScriptBin "git" ''
|
||||||
|
>&2 echo "Executing git is not allowed; command line:" "$@"
|
||||||
|
exit 127
|
||||||
|
'';
|
||||||
|
in (straight-env.emacsEnv {
|
||||||
|
inherit packages;
|
||||||
|
straightDir = "$DOOMLOCALDIR/straight";
|
||||||
|
}).overrideAttrs (super: {
|
||||||
|
phases = [ "installPhase" ];
|
||||||
|
buildInputs = super.buildInputs ++ [ git ];
|
||||||
|
preInstall = ''
|
||||||
|
export DOOMDIR=${doomPrivateDir}
|
||||||
|
export DOOMLOCALDIR=$out/
|
||||||
|
|
||||||
|
# Create a bogus $HOME directory because gccEmacs is known to require
|
||||||
|
# an existing home directory because the async worker process don't
|
||||||
|
# fully respect the value of 'comp-eln-load-path'.
|
||||||
|
export HOME=$(mktemp -d)
|
||||||
|
'';
|
||||||
|
postInstall = ''
|
||||||
|
# If gccEmacs or anything would write in $HOME, fail the build.
|
||||||
|
if [[ -z "$(find $HOME -maxdepth 0 -empty)" ]]; then
|
||||||
|
printf "${fmt.red}${fmt.bold}ERROR:${fmt.reset} "
|
||||||
|
printf "${fmt.red}doom-emacs build resulted in files being written in "'$HOME'" of the build sandbox.\n"
|
||||||
|
printf "Contents of "'$HOME'":\n"
|
||||||
|
find $HOME
|
||||||
|
printf ${fmt.reset}
|
||||||
|
exit 33
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
|
||||||
# Stage 3: do additional fixups to refer compiled files in the store
|
# Stage 3: do additional fixups to refer compiled files in the store
|
||||||
# and additional files in the users' home
|
# and additional files in the users' home
|
||||||
doom-emacs = stdenv.mkDerivation rec {
|
doom-emacs = stdenv.mkDerivation rec {
|
||||||
@@ -200,14 +189,14 @@ let
|
|||||||
inherit extraConfig;
|
inherit extraConfig;
|
||||||
passAsFile = [ "extraConfig" ];
|
passAsFile = [ "extraConfig" ];
|
||||||
} ''
|
} ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
cp -rL ${doomPrivateDir}/* $out
|
cp -rL ${doomPrivateDir}/* $out
|
||||||
chmod u+w $out/config.el
|
chmod u+w $out/config.el
|
||||||
cat $extraConfigPath > $out/config.extra.el
|
cat $extraConfigPath > $out/config.extra.el
|
||||||
cat > $out/config.el << EOF
|
cat > $out/config.el << EOF
|
||||||
(load "${builtins.toString doomPrivateDir}/config.el")
|
(load "${builtins.toString doomPrivateDir}/config.el")
|
||||||
(load "$out/config.extra.el")
|
(load "$out/config.extra.el")
|
||||||
EOF
|
EOF
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Stage 5: catch-all wrapper capable to run doom-emacs even
|
# Stage 5: catch-all wrapper capable to run doom-emacs even
|
||||||
@@ -220,19 +209,17 @@ let
|
|||||||
(load "${doom-emacs}/early-init.el"))
|
(load "${doom-emacs}/early-init.el"))
|
||||||
(load "${doom-emacs}/init.el")
|
(load "${doom-emacs}/init.el")
|
||||||
'';
|
'';
|
||||||
in (emacsPackages.emacsWithPackages (epkgs: [
|
in (emacsPackages.emacsWithPackages (epkgs: [ load-config-from-site ]));
|
||||||
load-config-from-site
|
|
||||||
]));
|
|
||||||
|
|
||||||
build-summary = writeShellScript "build-summary" ''
|
build-summary = writeShellScript "build-summary" ''
|
||||||
printf "\n${fmt.green}Successfully built nix-doom-emacs!${fmt.reset}\n"
|
printf "\n${fmt.green}Successfully built nix-doom-emacs!${fmt.reset}\n"
|
||||||
printf "${fmt.bold} ==> doom-emacs is installed to ${doom-emacs}${fmt.reset}\n"
|
printf "${fmt.bold} ==> doom-emacs is installed to ${doom-emacs}${fmt.reset}\n"
|
||||||
printf "${fmt.bold} ==> private configuration is installed to ${doomDir}${fmt.reset}\n"
|
printf "${fmt.bold} ==> private configuration is installed to ${doomDir}${fmt.reset}\n"
|
||||||
printf "${fmt.bold} ==> Dependencies are installed to ${doomLocal}${fmt.reset}\n"
|
printf "${fmt.bold} ==> Dependencies are installed to ${doomLocal}${fmt.reset}\n"
|
||||||
'';
|
'';
|
||||||
in
|
in emacs.overrideAttrs (esuper:
|
||||||
emacs.overrideAttrs (esuper:
|
let
|
||||||
let cmd = ''
|
cmd = ''
|
||||||
wrapEmacs() {
|
wrapEmacs() {
|
||||||
wrapProgram $1 \
|
wrapProgram $1 \
|
||||||
--set DOOMDIR ${doomDir} \
|
--set DOOMDIR ${doomDir} \
|
||||||
@@ -262,15 +249,9 @@ emacs.overrideAttrs (esuper:
|
|||||||
ln -s ${esuper.emacs}/share $out
|
ln -s ${esuper.emacs}/share $out
|
||||||
${build-summary}
|
${build-summary}
|
||||||
'';
|
'';
|
||||||
in
|
in if esuper ? buildCommand then {
|
||||||
if esuper ? buildCommand then
|
buildCommand = esuper.buildCommand + cmd;
|
||||||
{
|
} else if esuper ? installPhase then {
|
||||||
buildCommand = esuper.buildCommand + cmd;
|
installPhase = esuper.installPhase + cmd;
|
||||||
}
|
} else
|
||||||
else if esuper ? installPhase then
|
abort "emacsWithPackages uses unknown derivation type")
|
||||||
{
|
|
||||||
installPhase = esuper.installPhase + cmd;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
abort "emacsWithPackages uses unknown derivation type"
|
|
||||||
)
|
|
||||||
|
Reference in New Issue
Block a user