I’m still trying to grok flakes (and to an extent Nix/OS as a whole). I’ve been looking at other people’s configs to try and see what’s what, but it’s still very difficult for me to decipher exactly just what is what.
Could someone provide a minimal example of using a flake to declaratively install a program in home.nix? For example, the Neovim flake at github:neovim/neovim?dir=contrib?
Ideally in the form of
# In ~/.config/nixpkgs/home.nix
{ config, pkgs, ... }:
{
programs.home-manager.enable = true;
home.username = "myUsername";
home.homeDirectory = "/home/myUsername";
home.stateVersion = "21.03";
#
#
# Code that installs Neovim here using its flake at
# github:neovim/neovim?dir=contrib
#
#
}
where I could then run home-manager switch and be able to access Neovim via running nvim.
Problem is: They do not provide a flake.lock this might break the flake-compat function, as well as it will create warnings when used within a regular flake.
They should provide a lock file to make the flake complete and usable.
I’m not a flake user so take what I say with a grain of salt, but the flake in the neovim repo seems to be meant for developing neovim, not installing the package. I imagine that with nix installed and flakes enabled, a developer would make changes to the neovim source code in a local checkout of the repo, then cd into contrib and test the changes out by running a command like nix build . to build neovim or nix run .#nvim-debug to build and run neovim with debug settings.
If you’re new to Nix/NixOS I wouldn’t necessarily recommend learning flakes yet. They’re still experimental and as a user of NixOS and home-manager for about two years now, they haven’t felt well documented or easy enough to switch my configurations over to using them, though nix-flk has been very tempting. I would recommend doing a pretty vanilla home-manager installation in whatever linux distro you already have if you’re just looking for a declarative user environment, installing NixOS if you want more declarative system services, and using flakes if you need the reproducibility it provides.
I typed this directly into discourse from mobile so I may have mistakes. Hopefully someone with experience using flakes could give you a more satisfying answer.