This allows me to test the neovim configuration much easier and also adds neovim checks to the flake.
5.8 KiB
Nix Based Configuration
I use NixOS and home-manager to manage my system and user configuration respectively. You can see what options I have added to configure the system and user configuration in the next chapters.
The source repo is configuration.nix.
Table of Contents
How to Use
If you are not me, then you probably shouldn't use this, but feel free to draw inspiration from what I have done c:.
First you want to see what your environment is; if you are using NixOS then you want to look at the NixOS Module Setup, if you are just using home-manager, then you should look at the homa-manager Module Setup. Or if you just want to use my NeoVIM configuration then look at the NeoVIM standalone setup.
NixOS Module Setup
Although I am talking about the NixOS module setup, this uses both NixOS and home-manager, so you can (and should) use both modules.
Setup from LiveISO
Follow the NixOS Manual until before
you run nixos-generate-config
.
First you will want to create a directory for your NixOS configuration. I like
using ~/.config/nixos
. You then want to run nixos-generate-config --root /mnt --dir ~/.config/nixos
(assuming you mounted your filesystem to /mnt
). Now you
have configuration.nix
and hardware-configuration.nix
inside
~/.config/nixos
. I like renaming configuration.nix
to default.nix
and
putting it in a folder with the same hostname as the machine (See the source
repo).
Now you can add a flake.nix
file to your ~/.config/nixos
and make it a flake
based configuration. This is the general structure you'll want:
{
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
# My custom configuration module
inputs.config.url = "github:jalil-salame/configuration.nix";
inputs.config.inputs.follows.nixpkgs = "nixpkgs";
outputs = { self, nixpkgs, config }: let
pc = import (./. + hostname);
hostname = "nixos";
system = "x86_64-linux";
overlays = builtins.attrValues config.overlays;
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"steam-original"
];
pkgs = import nixpkgs { inherit system overlays config; };
in {
nixosConfigurations.${hostname} = nixpkgs.lib.nixosSystem {
inherit system pkgs;
modules = [
# My configuration module (includes home-manager)
config.nixosModules.nixosModule
# Results from `nixos-generate-config`
pc
# Custom options (see module configuration options)
{
# Enable my custom configuration
jconfig.enable = true;
jconfig.gui.enable = true; # Enable gui environment
# Add users to use with home-manager
users.users = {};
# You should probably also enable wifi if needed
# Add home-manager users configuration (here you can enable jhome options)
home-manager.users = {};
# home-manager globally set options
home-manager.sharedModules = [{ jhome.hostName = hostname; }];
}
];
};
};
}
Now you should be ready to do sudo nixos-rebuild switch --flake .#$hostname
and use the configuration c:.
home-manager Module Setup
If you are not using NixOS, then you probably want to only use the home-manager
configuration. In that case, you want to use the
nixosModules.homeManagerModuleSandalone
in your home-manager
configuration,
and probably disable GUI applications all together jhome.gui.enable = false
.
Your flake should then look like this (follow the home-manager Manual for more information):
{
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.home-manager.url = "github:nixos-community/home-manager";
inputs.home-manager.inputs.follows.nixpkgs = "nixpkgs";
# My custom configuration module
inputs.config.url = "github:jalil-salame/configuration.nix";
inputs.config.inputs.follows.nixpkgs = "nixpkgs";
inputs.config.inputs.follows.home-manager = "home-manager";
outputs = { self, nixpkgs, home-manager, config }: let
hostname = "nixos";
username = "jdoe";
system = "x86_64-linux";
overlays = builtins.attrValues config.overlays;
pkgs = import nixpkgs { inherit system overlays; };
in {
homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
# My configuration module (includes home-manager)
config.nixosModules.homeManagerModuleSandalone
# Custom options (see module configuration options and home-manager options)
{
# Enable my custom configuration
jhome.enable = true;
jhome.hostName = hostname;
jhome.gui.enable = false;
# Extra configuration options
}
];
};
};
}
NeoVIM Standalone setup
My NeoVIM configuration is managed by NixVIM, so check that project out if you want to understand how it works. You can use this tutorial to extend my configuration without forking this repo or copying its files.
If you want to test out my configuration then you can run this handy nix command:
$ nix run github:jalil-salame/configuration.nix#nvim
It will download and build my NeoVIM configuration and run NeoVIM. Alternatively
you can replace nix run
with nix shell
which will temporarily add my NeoVIM
configuration to your shell and when you run nvim
it will launch it.