From 5a260a6ca31f531c958594a376346d64626443d1 Mon Sep 17 00:00:00 2001 From: Zachary Newman Date: Fri, 30 Sep 2022 16:45:50 -0400 Subject: [PATCH 1/3] Add `doomPackageDir` argument. This is a directory used for initializing the straight environment, distinct from `doomPrivateDir`. If not given, `doomPrivateDir` is used. Here it is in action: https://github.com/znewman01/dotfiles/blob/be9f3a24c517a4ff345f213bf1cf7633713c9278/emacs/default.nix#L12-L34 Fixes #297 (there are some ideas for extra sugar in that issue, but this solves the core problem). --- default.nix | 24 ++++++++++++++++++++++-- modules/home-manager.nix | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 3db5fa5..0b712bf 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,23 @@ { # The files would be going to ~/.config/doom (~/.doom.d) doomPrivateDir + /* A Doom configuration directory from which to build the Emacs package environment. + + Can be used, for instance, to prevent rebuilding the Emacs environment + each time the `config.el` changes. + + Can be provided as a directory or derivation. If not given, package + environment is built against `doomPrivateDir`. + + Example: + doomPackageDir = pkgs.linkFarm "my-doom-packages" [ + # straight needs a (possibly empty) `config.el` file to build + { name = "config.el"; path = pkgs.emptyFile; } + { name = "init.el"; path = ./doom.d/init.el; } + { name = "packages.el"; path = pkgs.writeText "(package! inheritenv)"; } + { name = "modules"; path = ./my-doom-module; } + ]; + */ +, doomPackageDir ? null /* Extra packages to install Useful for non-emacs packages containing emacs bindings (e.g. @@ -105,6 +123,8 @@ let # Bundled version of `emacs-overlay` emacs-overlay = import (lock "emacs-overlay") pkgs pkgs; + doomPackageInstallDir = if doomPackageDir == null then doomPrivateDir else doomPackageDir; + # Stage 2: install dependencies and byte-compile prepared source doomLocal = let straight-env = pkgs.callPackage (lock "nix-straight") { @@ -126,7 +146,7 @@ let phases = [ "installPhase" ]; nativeBuildInputs = [ git ]; preInstall = '' - export DOOMDIR=${doomPrivateDir} + export DOOMDIR=${doomPackageInstallDir} export DOOMLOCALDIR=$(mktemp -d)/local/ ''; }); @@ -144,7 +164,7 @@ let phases = [ "installPhase" ]; nativeBuildInputs = [ git ]; preInstall = '' - export DOOMDIR=${doomPrivateDir} + export DOOMDIR=${doomPackageInstallDir} export DOOMLOCALDIR=$out/ # Create a bogus $HOME directory because gccEmacs is known to require diff --git a/modules/home-manager.nix b/modules/home-manager.nix index 63ab768..9ec425c 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -22,6 +22,27 @@ in ''; apply = path: if lib.isStorePath path then path else builtins.path { inherit path; }; }; + doomPackageDir = mkOption { + description = '' + A Doom configuration directory from which to build the Emacs package environment. + + Can be used, for instance, to prevent rebuilding the Emacs environment + each time the `config.el` changes. + + Can be provided as a directory or derivation. If not given, package + environment is built against `doomPrivateDir`. + ''; + apply = path: if lib.isStorePath path then path else builtins.path { inherit path; }; + example = literalExample '' + doomPackageDir = pkgs.linkFarm "my-doom-packages" [ + # straight needs a (possibly empty) `config.el` file to build + { name = "config.el"; path = pkgs.emptyFile; } + { name = "init.el"; path = ./doom.d/init.el; } + { name = "packages.el"; path = pkgs.writeText "(package! inheritenv)"; } + { name = "modules"; path = ./my-doom-module; } + ]; + ''; + }; extraConfig = mkOption { description = '' Extra configuration options to pass to doom-emacs. From d4c681483e9d6048573948336341607ff44fe3ef Mon Sep 17 00:00:00 2001 From: Zachary Newman Date: Thu, 20 Oct 2022 18:42:57 -0400 Subject: [PATCH 2/3] Fix args and README; add check for doomPackageDir change --- .github/workflows/check-build.yml | 35 +++++++++++++++++++++++++++++++ checks.nix | 22 +++++++++++++++++++ default.nix | 13 ++++++------ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-build.yml b/.github/workflows/check-build.yml index 9bb32f6..698f148 100644 --- a/.github/workflows/check-build.yml +++ b/.github/workflows/check-build.yml @@ -108,3 +108,38 @@ jobs: if: ${{ !steps.cache-nix-store-emacsGit.outputs.cache-hit }} run: | nix-store --export $(nix-store -qR /nix/store/*-doom-emacs) > nix-store.dump + check-splitdir: + name: Flake Check splitdir (x86_64 only) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # Nix Flakes doesn't work on shallow clones + fetch-depth: 0 + - uses: cachix/install-nix-action@v17 + with: + extra_nix_config: | + extra-substituters = https://nix-community.cachix.org + extra-trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= + - name: Retrieve /nix/store archive + uses: actions/cache@v3 + id: cache-nix-store + with: + path: nix-store.dump + key: nix-store-${{ hashFiles('flake.lock') }} + restore-keys: | + nix-store- + - name: Import /nix/store contents + if: ${{ steps.cache-nix-store.outputs.cache-hit }} + run: | + if [[ -f nix-store.dump ]]; then + nix-store --import < nix-store.dump || true + rm nix-store.dump + fi + - name: Run checks in emacs + run: | + nix build .#checks.x86_64-linux.init-example-el-splitdir + - name: Export /nix/store contents + if: ${{ !steps.cache-nix-store.outputs.cache-hit }} + run: | + nix-store --export $(nix-store -qR /nix/store/*-doom-emacs) > nix-store.dump diff --git a/checks.nix b/checks.nix index d12a28d..e48599f 100644 --- a/checks.nix +++ b/checks.nix @@ -41,4 +41,26 @@ in dependencyOverrides = inputs; emacsPackages = with pkgs; emacsPackagesFor emacsGit; }; + init-example-el-splitdir = self.outputs.package.${system} { + dependencyOverrides = inputs; + doomPrivateDir = pkgs.linkFarm "my-doom-packages" [ + { name = "config.el"; path = ./test/doom.d/config.el; } + { name = "init.el"; path = ./test/doom.d/init.el; } + # Should *not* fail because we're building our straight environment + # using the doomPackageDir, not the doomPrivateDir. + { + name = "packages.el"; + path = pkgs.writeText "packages.el" "(package! not-a-valid-package)"; + } + ]; + doomPackageDir = pkgs.linkFarm "my-doom-packages" [ + # straight needs a (possibly empty) `config.el` file to build + { name = "config.el"; path = pkgs.emptyFile; } + { name = "init.el"; path = ./test/doom.d/init.el; } + { + name = "packages.el"; + path = pkgs.writeText "packages.el" "(package! inheritenv)"; + } + ]; + }; } diff --git a/default.nix b/default.nix index 0b712bf..68aa633 100644 --- a/default.nix +++ b/default.nix @@ -13,11 +13,14 @@ # straight needs a (possibly empty) `config.el` file to build { name = "config.el"; path = pkgs.emptyFile; } { name = "init.el"; path = ./doom.d/init.el; } - { name = "packages.el"; path = pkgs.writeText "(package! inheritenv)"; } + { + name = "packages.el"; + path = pkgs.writeText "packages.el" "(package! inheritenv)"; + } { name = "modules"; path = ./my-doom-module; } ]; */ -, doomPackageDir ? null +, doomPackageDir ? doomPrivateDir /* Extra packages to install Useful for non-emacs packages containing emacs bindings (e.g. @@ -123,8 +126,6 @@ let # Bundled version of `emacs-overlay` emacs-overlay = import (lock "emacs-overlay") pkgs pkgs; - doomPackageInstallDir = if doomPackageDir == null then doomPrivateDir else doomPackageDir; - # Stage 2: install dependencies and byte-compile prepared source doomLocal = let straight-env = pkgs.callPackage (lock "nix-straight") { @@ -146,7 +147,7 @@ let phases = [ "installPhase" ]; nativeBuildInputs = [ git ]; preInstall = '' - export DOOMDIR=${doomPackageInstallDir} + export DOOMDIR=${doomPackageDir} export DOOMLOCALDIR=$(mktemp -d)/local/ ''; }); @@ -164,7 +165,7 @@ let phases = [ "installPhase" ]; nativeBuildInputs = [ git ]; preInstall = '' - export DOOMDIR=${doomPackageInstallDir} + export DOOMDIR=${doomPackageDir} export DOOMLOCALDIR=$out/ # Create a bogus $HOME directory because gccEmacs is known to require From 29dff05b5b8b276a2ee24f47827f17b3573729f3 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sat, 22 Oct 2022 08:43:34 +0100 Subject: [PATCH 3/3] Fix indentation in example --- modules/home-manager.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/home-manager.nix b/modules/home-manager.nix index 9ec425c..6c9af54 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -34,7 +34,7 @@ in ''; apply = path: if lib.isStorePath path then path else builtins.path { inherit path; }; example = literalExample '' - doomPackageDir = pkgs.linkFarm "my-doom-packages" [ + doomPackageDir = pkgs.linkFarm "my-doom-packages" [ # straight needs a (possibly empty) `config.el` file to build { name = "config.el"; path = pkgs.emptyFile; } { name = "init.el"; path = ./doom.d/init.el; }