Help me get started - Best practice, nvim, learning the language

Hi,
I am all new to NixOS. Just installed it yesterday. And within an hour or so, I had it pretty much up and running how I like it, i.e. installed my must-have programs, changed WM to I3 etc. I really like TUI and textbased configuration. I obviously love VI and NixOS just seems to be a natural extension of this. So <3 <3 <3

  1. Actually I love it so much that I have planned to spend time learning the language at least somewhat. I have worked as a software developer, so learning a new computer language shouldnā€™t be TOO hard. But I have never done anything functional programming. So perhaps? Also I have been working with as a teacher for the last 13 years. So my CS might be slightly rusty.
    What are your recommendation to get too learn the language?

  2. As said I really like VI, or rather neovim. How do I set it up properly. I would like:

  • vimtex
  • ultisnips
  • A language server / IDE for the Nix-language
  • A language server / IDE for Bash and Python
  1. What is best-practice for making configuration?
  • Is it prefered, acceptable or not recommended to split up the configuration, so I have e.g. a special file for everything with my WM, a special file for everything with VI, a special file for everything with my hard drives, luks, etc. etc. etc.
  • Is it recommended to move as much as possible from the .config to the Nix-file? E.g. should I have all my I3 configuration which is currently in .config/i3/config in my Nix-file? Some of it? Or should I just leave it in my .config-folder?

Just to clarify. I am using the full OS on bare metal. So I am talking about the OS, nut ā€˜justā€™ the package-manager.

Thanks!
And thanks for NixOS. I really love it. Right now my favorite things about my computer-setup is: VI, I3, TUI-software and GNU tools like piping and grep etc., Git, BTRFS with snapshots and CoW (I love cp --reflink) and Nixos (not necessarily in that order though). I really do not understand how I could live with Windows, Notepad++ etc.

As one of the main authors and maintainers of the official Nix language tutorial, I obviously recommend https://nix.dev/tutorials/first-steps/nix-language. It is deliberately designed to be gentle with people not familiar with functional programming. Any feedback in the form of pull requests to further ease onboarding is highly appreciated.

3 Likes

Thereā€™s a basic tutorial here: https://nix.dev/tutorials/first-steps/nix-language

nix.dev generally has some good guides nowadays.

Beyond that, figure out how packaging packages work, how writing modules works, and make use of the nix repl to try things out

Functional languages definitely feel different, if youā€™ve used python before, think list comprehensions and generators in general.

Iā€™ve worked with engineers much more senior than me who hated them because they felt they were ā€œthinking backwardsā€. But if you come to them with an open mind I think you might find them fun. Nix is only rarely used for hardcore programming anyway, so you may never have to really learn programming in these languages.

I have to admit, Iā€™ve not used vim on NixOS. There is programs.neovim.enable and its sister options, which you can use to do most configuration.

Lot of language servers are also just packaged for nix, and you only need to install them.

Maybe home-managerā€™s options are better/more idiomatic though: https://nix-community.github.io/home-manager/options.html#opt-programs.neovim.enable

Depends. Generally, yes, splitting files into conceptual units is good software engineering practice, but you donā€™t want dozens of three-line files.

Vi/WM definitely sound complex enough to be nice ā€œunitsā€.

For hard drives/luks Iā€™d recommend disko by the way.

If you want the full reproducible OS experience, this is indeed necessary. If you use home-manager this can be done relatively transparently, often just need to set up a home.file.

Itā€™s not mandatory to use NixOS, however, and trying to do so can be time consuming. Itā€™s a good way to learn nix though!

2 Likes

@lytjedk Welcome to the dark side. :slight_smile:

You already got good advise in this thread, so Iā€™ll just add a few remarks:

Donā€™t try to cramp everything in your main config. It just bloats your system and increases rebuild times. If you launch Gimp only once in a few months, just run in on demand using nix-shell/nix run. Keep stuff like compiler-toolchains in project specific setups. These usually have a different cadence of updates and again, keeps your main system lean and clean.

Use Home-Manager for your system configuration. Home-Manager has very elaborate options for many programs (e.g. VIM) and is much better suited to manage/create your dotfiles.

Keep the search and manual pages at hand.

Split your config, but donā€™t overdo it. Having a separate config file e.g. for VIM or i3 can be quite useful when you want to share it with configurations for other machines later on, while keeping system-specific stuff (e.g. GPU settings, monitor layout,ā€¦) in one file avoids cluttering of your config folder.
Donā€™t worry too much about that in the beginning, you can always refactor as your config grows and you get more proficient with Nix. Nixpkgs brings also a good library of helper functions: Nixpkgs 23.11 manual | Nix & NixOS

3 Likes

Those things can grow out of hand though, especially with nvidia. You also already have a hardware-configuration.nix. Personally I recommend host-specific folders so the mess is contained, just donā€™t be too hesitant about splitting these configs either (and later you can also factor out e.g. nvidia config into a more general module if you have more nvidia machines).

1 Like