To use your Helix configuration in NixOS and Home Manager with flakes, you'll need to:
- Place your Helix config in the correct location.
- Declare the Helix package in your configuration.
- Ensure Home Manager manages the config file.
Here's a step-by-step guide:
1. Directory Structure
First, ensure your Helix config is in the right place. A typical structure might look like:
~/.config/helix/
├── config.toml
└── languages.toml
2. NixOS Configuration (Flake)
In your NixOS flake (flake.nix), ensure Helix is installed and the config is managed.
Example flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, home-manager, ... }@inputs: {
nixosConfigurations.your-hostname = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
({ config, pkgs, ... }: {
# Install Helix
environment.systemPackages = with pkgs; [ helix ];
# Enable Home Manager
users.users.your-username = {
isNormalUser = true;
extraGroups = [ "wheel" "networkmanager" ];
};
# Import Home Manager
imports = [
inputs.home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.your-username = import ./home.nix;
}
];
})
];
};
};
}
3. Home Manager Configuration
In your Home Manager config (home.nix), manage the Helix config file.
Example home.nix
{ config, pkgs, ... }:
{
# Install Helix (optional, since it's already in systemPackages)
home.packages = with pkgs; [ helix ];
# Manage Helix config
home.file.".config/helix/config.toml".text = ''
theme = "onedark"
[editor]
line-number = "relative"
[keys.normal]
esc = ["collapse_selection", "keep_primary_selection"]
'';
# Alternatively, use an existing config file
home.file.".config/helix/config.toml".source = ./helix/config.toml;
}
Alternative: Using xdg.configFile
If you prefer xdg.configFile (recommended for XDG-compliant apps):
xdg.configFile."helix/config.toml".text = ''
theme = "onedark"
[editor]
line-number = "relative"
'';
4. Apply the Configuration
Run:
sudo nixos-rebuild switch --flake ~/.dotfiles#your-hostname
home-manager switch --flake ~/.dotfiles#your-username
5. Verify Helix Works
Check if Helix is installed and the config is applied:
hx --version
cat ~/.config/helix/config.toml
Summary
- Install Helix in
environment.systemPackages (NixOS) or home.packages (Home Manager).
- Manage the config using
home.file or xdg.configFile.
- Apply changes with
nixos-rebuild and home-manager switch.
This ensures Helix is properly configured in a declarative way with Nix flakes. 🚀