Move most shell out of Nix string literals
The amount of shell in non-shell files was making me uncomfortable, and two of these previously contained awkward `''$` escapes. Apart from forcing one more step to run locally, this is just moving code around.
This commit is contained in:
parent
9f249ae72f
commit
e69e5ed23e
4 changed files with 152 additions and 91 deletions
37
build-helpers/build-doom-emacs.sh
Normal file
37
build-helpers/build-doom-emacs.sh
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# -*- mode: sh; sh-shell: bash -*-
|
||||||
|
|
||||||
|
# Copyright 2024 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
if [[ -z "$profileName" ]]; then
|
||||||
|
profileArgs=()
|
||||||
|
else
|
||||||
|
profileArgs=(
|
||||||
|
--set DOOMPROFILELOADFILE $doomProfile/loader/init.el
|
||||||
|
--set DOOMPROFILE "$profileName"
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
makeWrapper $emacsWithPackages/bin/emacs $out/bin/doom-emacs \
|
||||||
|
"${profileArgs[@]}" \
|
||||||
|
--set DOOMDIR $doomProfile/doomdir \
|
||||||
|
--set-default DOOMLOCALDIR "$doomLocalDir" \
|
||||||
|
--add-flags "--init-directory=$doomSource"
|
||||||
|
makeWrapper $doomSource/bin/doomscript $out/bin/doomscript \
|
||||||
|
--set EMACS $emacsWithPackages/bin/emacs \
|
||||||
|
--set-default DOOMLOCALDIR "$doomLocalDir"
|
||||||
|
makeWrapper $doomSource/bin/doom $out/bin/doom \
|
||||||
|
--set EMACS $emacsWithPackages/bin/emacs \
|
||||||
|
"${profileArgs[@]}" \
|
||||||
|
--set DOOMDIR $doomProfile/doomdir \
|
||||||
|
--set-default DOOMLOCALDIR "$doomLocalDir"
|
||||||
54
build-helpers/build-doom-profile.sh
Normal file
54
build-helpers/build-doom-profile.sh
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# -*- mode: sh; sh-shell: bash -*-
|
||||||
|
|
||||||
|
# Copyright 2024 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
mkdir $out $out/loader $out/doomdir $out/profile $out/straight
|
||||||
|
ln -s $doomDir/* $out/doomdir/
|
||||||
|
# yasnippet logs an error at startup if snippets/ does not exist.
|
||||||
|
if ! [[ -e $out/doomdir/snippets ]]; then
|
||||||
|
mkdir $out/doomdir/snippets
|
||||||
|
fi
|
||||||
|
rm $out/doomdir/init.el
|
||||||
|
if [[ -z "$profileName" ]]; then
|
||||||
|
maybeSetProfileDir="(setq doom-profile-dir \"$out/profile\")"
|
||||||
|
else
|
||||||
|
maybeSetProfileDir=""
|
||||||
|
fi
|
||||||
|
substitute $initEl $out/doomdir/init.el \
|
||||||
|
--subst-var maybeSetProfileDir \
|
||||||
|
--subst-var profileName \
|
||||||
|
--subst-var-by userInit "$doomDir/init.el" \
|
||||||
|
--subst-var-by straightBaseDir $out
|
||||||
|
ln -sf $doomIntermediates/packages.el $out/doomdir/
|
||||||
|
export DOOMDIR=$out/doomdir
|
||||||
|
|
||||||
|
# DOOMLOCALDIR must be writable, Doom creates some subdirectories.
|
||||||
|
export DOOMLOCALDIR=$(mktemp -d)
|
||||||
|
if [[ -n "$profileName" ]]; then
|
||||||
|
export DOOMPROFILELOADFILE=$out/loader/init.el
|
||||||
|
$runtimeShell $doomSource/bin/doomscript $buildProfileLoader \
|
||||||
|
${noProfileHack:+-u} -n "$profileName" -b "$out"
|
||||||
|
|
||||||
|
# With DOOMPROFILE set, doom-state-dir and friends are HOME-relative.
|
||||||
|
export HOME=$(mktemp -d)
|
||||||
|
export DOOMPROFILE="$profileName";
|
||||||
|
fi
|
||||||
|
$runtimeShell $doomSource/bin/doomscript $buildProfile
|
||||||
|
|
||||||
|
# Similar to audit-tmpdir.sh in nixpkgs.
|
||||||
|
if grep -q -F "$TMPDIR/" -r $out; then
|
||||||
|
echo "Doom profile contains a forbidden reference to $TMPDIR/"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
28
build-helpers/build-emacs-with-doom.sh
Normal file
28
build-helpers/build-emacs-with-doom.sh
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- mode: sh; sh-shell: bash -*-
|
||||||
|
|
||||||
|
# Copyright 2024 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
mkdir -p $out/bin
|
||||||
|
ln -s $emacs/bin/* $out/bin/
|
||||||
|
rm $out/bin/emacs-*
|
||||||
|
ln -sf $doomEmacs/bin/doom-emacs $out/bin/emacs
|
||||||
|
ln -sf $doomEmacs/bin/{doom,doomscript} $out/bin/
|
||||||
|
|
||||||
|
mkdir -p $out/share
|
||||||
|
# Don't link everything: the systemd units would still refer to normal Emacs.
|
||||||
|
# This links the same stuff emacsWithPackages does.
|
||||||
|
for dir in applications icons info man; do
|
||||||
|
ln -s $emacs/share/$dir $out/share/$dir
|
||||||
|
done
|
||||||
124
default.nix
124
default.nix
|
|
@ -46,11 +46,12 @@
|
||||||
git,
|
git,
|
||||||
emacsPackagesFor,
|
emacsPackagesFor,
|
||||||
lib,
|
lib,
|
||||||
runCommand,
|
|
||||||
runCommandLocal,
|
runCommandLocal,
|
||||||
runtimeShell,
|
runtimeShell,
|
||||||
writeText,
|
writeText,
|
||||||
makeBinaryWrapper,
|
makeBinaryWrapper,
|
||||||
|
stdenv,
|
||||||
|
stdenvNoCC,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) optionalAttrs optionalString;
|
inherit (lib) optionalAttrs optionalString;
|
||||||
|
|
@ -304,107 +305,48 @@ let
|
||||||
# - The path to the generated profile is included in the loader
|
# - The path to the generated profile is included in the loader
|
||||||
# - Generating the profile depends on the loader
|
# - Generating the profile depends on the loader
|
||||||
|
|
||||||
# Force local build in case the user init.el does something weird.
|
doomProfile = stdenvNoCC.mkDerivation {
|
||||||
doomProfile = runCommandLocal "doom-profile"
|
name = "doom-profile";
|
||||||
{
|
buildCommandPath = ./build-helpers/build-doom-profile.sh;
|
||||||
inherit doomDir doomIntermediates doomSource noProfileHack profileName runtimeShell;
|
|
||||||
buildProfileLoader = ./build-helpers/build-profile-loader;
|
|
||||||
buildProfile = ./build-helpers/build-profile;
|
|
||||||
initEl = ./init.el;
|
|
||||||
EMACS = lib.getExe emacsWithPackages;
|
|
||||||
# Enable this to troubleshoot failures at this step.
|
|
||||||
#DEBUG = "1";
|
|
||||||
# Required to avoid Doom erroring out at startup.
|
|
||||||
nativeBuildInputs = [ git ];
|
|
||||||
} ''
|
|
||||||
mkdir $out $out/loader $out/doomdir $out/profile $out/straight
|
|
||||||
ln -s $doomDir/* $out/doomdir/
|
|
||||||
# yasnippet logs an error at startup if snippets/ does not exist.
|
|
||||||
if ! [[ -e $out/doomdir/snippets ]]; then
|
|
||||||
mkdir $out/doomdir/snippets
|
|
||||||
fi
|
|
||||||
rm $out/doomdir/init.el
|
|
||||||
if [[ -z "$profileName" ]]; then
|
|
||||||
maybeSetProfileDir="(setq doom-profile-dir \"$out/profile\")"
|
|
||||||
else
|
|
||||||
maybeSetProfileDir=""
|
|
||||||
fi
|
|
||||||
substitute $initEl $out/doomdir/init.el \
|
|
||||||
--subst-var maybeSetProfileDir \
|
|
||||||
--subst-var profileName \
|
|
||||||
--subst-var-by userInit "$doomDir/init.el" \
|
|
||||||
--subst-var-by straightBaseDir $out
|
|
||||||
ln -sf $doomIntermediates/packages.el $out/doomdir/
|
|
||||||
export DOOMDIR=$out/doomdir
|
|
||||||
|
|
||||||
# DOOMLOCALDIR must be writable, Doom creates some subdirectories.
|
inherit doomDir doomIntermediates doomSource noProfileHack profileName runtimeShell;
|
||||||
export DOOMLOCALDIR=$(mktemp -d)
|
buildProfileLoader = ./build-helpers/build-profile-loader;
|
||||||
if [[ -n "$profileName" ]]; then
|
buildProfile = ./build-helpers/build-profile;
|
||||||
export DOOMPROFILELOADFILE=$out/loader/init.el
|
initEl = ./init.el;
|
||||||
$runtimeShell $doomSource/bin/doomscript $buildProfileLoader \
|
EMACS = lib.getExe emacsWithPackages;
|
||||||
''${noProfileHack:+-u} -n "$profileName" -b "$out"
|
# Enable this to troubleshoot failures at this step.
|
||||||
|
#DEBUG = "1";
|
||||||
|
|
||||||
# With DOOMPROFILE set, doom-state-dir and friends are HOME-relative.
|
# Required to avoid Doom erroring out at startup.
|
||||||
export HOME=$(mktemp -d)
|
nativeBuildInputs = [ git ];
|
||||||
export DOOMPROFILE="$profileName";
|
# Force local build in case the user init.el does something weird.
|
||||||
fi
|
preferLocalBuild = true;
|
||||||
$runtimeShell $doomSource/bin/doomscript $buildProfile
|
allowSubstitutes = false;
|
||||||
|
};
|
||||||
# Similar to audit-tmpdir.sh in nixpkgs.
|
|
||||||
if grep -q -F "$TMPDIR/" -r $out; then
|
|
||||||
echo "Doom profile contains a forbidden reference to $TMPDIR/"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Step 6: write wrappers to start the whole thing.
|
# Step 6: write wrappers to start the whole thing.
|
||||||
|
|
||||||
# Use runCommand, not runCommandLocal, because makeBinaryWrapper pulls in a compiler.
|
# makeBinaryWrapper pulls in a compiler, so don't force this one local.
|
||||||
doomEmacs = runCommand "doom-emacs" {
|
doomEmacs = stdenv.mkDerivation {
|
||||||
|
name = "doom-emacs";
|
||||||
|
buildCommandPath = ./build-helpers/build-doom-emacs.sh;
|
||||||
|
|
||||||
# emacsWithPackages also accessed externally (for pushing to Cachix).
|
# emacsWithPackages also accessed externally (for pushing to Cachix).
|
||||||
inherit doomProfile doomLocalDir doomSource emacsWithPackages profileName;
|
inherit doomProfile doomLocalDir doomSource emacsWithPackages profileName;
|
||||||
nativeBuildInputs = [ makeBinaryWrapper ];
|
|
||||||
} ''
|
|
||||||
if [[ -z "$profileName" ]]; then
|
|
||||||
profileArgs=()
|
|
||||||
else
|
|
||||||
profileArgs=(
|
|
||||||
--set DOOMPROFILELOADFILE $doomProfile/loader/init.el
|
|
||||||
--set DOOMPROFILE "$profileName"
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
makeWrapper $emacsWithPackages/bin/emacs $out/bin/doom-emacs \
|
|
||||||
"''${profileArgs[@]}" \
|
|
||||||
--set DOOMDIR $doomProfile/doomdir \
|
|
||||||
--set-default DOOMLOCALDIR "$doomLocalDir" \
|
|
||||||
--add-flags "--init-directory=$doomSource"
|
|
||||||
makeWrapper $doomSource/bin/doomscript $out/bin/doomscript \
|
|
||||||
--set EMACS $emacsWithPackages/bin/emacs \
|
|
||||||
--set-default DOOMLOCALDIR "$doomLocalDir"
|
|
||||||
makeWrapper $doomSource/bin/doom $out/bin/doom \
|
|
||||||
--set EMACS $emacsWithPackages/bin/emacs \
|
|
||||||
"''${profileArgs[@]}" \
|
|
||||||
--set DOOMDIR $doomProfile/doomdir \
|
|
||||||
--set-default DOOMLOCALDIR "$doomLocalDir"
|
|
||||||
'';
|
|
||||||
|
|
||||||
emacsWithDoom = runCommand (lib.appendToName "with-doom" emacs).name {
|
nativeBuildInputs = [ makeBinaryWrapper ];
|
||||||
|
};
|
||||||
|
|
||||||
|
emacsWithDoom = stdenvNoCC.mkDerivation {
|
||||||
|
inherit (lib.appendToName "with-doom" emacs) name;
|
||||||
inherit (emacs) meta;
|
inherit (emacs) meta;
|
||||||
inherit doomEmacs emacs;
|
inherit doomEmacs emacs;
|
||||||
} ''
|
buildCommandPath = ./build-helpers/build-emacs-with-doom.sh;
|
||||||
mkdir -p $out/bin
|
|
||||||
ln -s $emacs/bin/* $out/bin/
|
|
||||||
rm $out/bin/emacs-*
|
|
||||||
ln -sf $doomEmacs/bin/doom-emacs $out/bin/emacs
|
|
||||||
ln -sf $doomEmacs/bin/{doom,doomscript} $out/bin/
|
|
||||||
|
|
||||||
mkdir -p $out/share
|
# Force local build as it's near-trivial.
|
||||||
# Don't link everything: the systemd units would still refer to normal Emacs.
|
preferLocalBuild = true;
|
||||||
# This links the same stuff emacsWithPackages does.
|
allowSubstitutes = false;
|
||||||
for dir in applications icons info man; do
|
};
|
||||||
ln -s $emacs/share/$dir $out/share/$dir
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit doomEmacs emacsWithDoom;
|
inherit doomEmacs emacsWithDoom;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue