nix-community / nix-doom-emacs

doom-emacs packaged for Nix [maintainers=@thiagokokada]
MIT License
213 stars 43 forks source link

How to use XDG paths for the package? #472

Open NovaViper opened 1 year ago

NovaViper commented 1 year ago

Hey I'm new to NixOS and I'm wondering how I can make the doom emacs package use the XDG path (so instead of placing the files in directly in my home folder, it goes into the ~/.config/emacs)? I have Home-manager setup as a standalone installation with flakes

flake.nix

{
  description = "Your new nix config";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
    home-manager = {
      url = "github:nix-community/home-manager/release-23.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-doom-emacs.url = "github:nix-community/nix-doom-emacs";
  };

  outputs = { nixpkgs, home-manager, nix-doom-emacs, ... }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      nixosConfigurations = {
        ryzennova = nixpkgs.lib.nixosSystem {
          modules = [
            ./nixos/ryzennova.nix
          ];
        };
        thinknova = nixpkgs.lib.nixosSystem {
          modules = [
            ./nixos/thinknova.nix
          ];
        };
      };
      homeConfigurations = {
        novaviper = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [
            ./home-manager/home.nix
            # Add custom programs
            {
              imports = [ nix-doom-emacs.hmModule ];
              programs.doom-emacs = {
                enable = true;
                doomPrivateDir = ./doom; # Directory containing your config.el, init.el and packages.el files
                emacsPackage = pkgs.emacsPackages;
              };
            }
          ];
        };
      };
    };
}

home.nix

{ config, pkgs, ... }:

{
  imports = [
    ./apps/zsh.nix
    ./apps/doom-emacs.nix
  #  ./apps/git.nix
  ];

  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = "novaviper";
  home.homeDirectory = "/home/novaviper";
  xdg.cacheHome = "/home/novaviper/.cache";
  xdg.configHome = "/home/novaviper/.config";
  xdg.dataHome = "/home/novaviper/.local/share";
  xdg.stateHome = "/home/novaviper/.local/state";

  # This value determines the Home Manager release that your configuration is
  # compatible with. This helps avoid breakage when a new Home Manager release
  # introduces backwards incompatible changes.
  #
  # You should not change this value, even if you update Home Manager. If you do
  # want to update the value, then make sure to first check the Home Manager
  # release notes.
  home.stateVersion = "23.05"; # Please read the comment before changing.

  # Allow unfree packages
  nixpkgs.config.allowUnfreePredicate = (pkg: true);

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages = with pkgs; [
    vivaldi
    firefox
    kate
    keepassxc
    discord
    btop

    # # Adds the 'hello' command to your environment. It prints a friendly
    # # "Hello, world!" when run.
    # pkgs.hello

    # # It is sometimes useful to fine-tune packages, for example, by applying
    # # overrides. You can do that directly here, just don't forget the
    # # parentheses. Maybe you want to install Nerd Fonts with a limited number of
    # # fonts?
    # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })

    # # You can also create simple shell scripts directly inside your
    # # configuration. For example, this adds a command 'my-hello' to your
    # # environment:
    # (pkgs.writeShellScriptBin "my-hello" ''
    #   echo "Hello, ${config.home.username}!"
    # '')
  ];

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
    # # Building this configuration will create a copy of 'dotfiles/screenrc' in
    # # the Nix store. Activating the configuration will then make '~/.screenrc' a
    # # symlink to the Nix store copy.
    # ".screenrc".source = dotfiles/screenrc;

    # # You can also set the file content immediately.
    # ".gradle/gradle.properties".text = ''
    #   org.gradle.console=verbose
    #   org.gradle.daemon.idletimeout=3600000
    # '';
  };

  xdg.configFile = {
    "git/config".source = apps/config/gitrc;
  };

  # You can also manage environment variables but you will have to manually
  # source
  #
  #  ~/.nix-profile/etc/profile.d/hm-session-vars.sh
  #
  # or
  #
  #  /etc/profiles/per-user/novaviper/etc/profile.d/hm-session-vars.sh
  #
  # if you don't want to manage your shell through Home Manager.
  home.sessionVariables = {
    # EDITOR = "emacs";
  };

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}
necrophcodr commented 1 year ago

This might make sense. It seems that emacs does indeed look for the init.el file in different places (see https://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html ), so perhaps being able to change this path isn't such a bad idea.