New users are using NixOS wrong (and it's our fault)

I installed NixOS in a VM to give it a shot, installed all packages and when trying to build a project called CMaNGOS which requires cmake, openssl, boost, bz2, mysql++ (and i wanted to build with clang) i completely lost it.

I did everything with configuration.nix up until that point where i wanted to do just build something in my homedir and NixOS blew up on me. And how would i go about debugging with with vs-code if i first need to make a nix package out of it?

So yeah, i agree too.

@Salsa9 Do you know how to build this project now?

No, I put it off for now as it was so arcane to me what i had to write to accomplish what i wanted. Coming from using Debian derivates and Manjaro where everything lives in a global “packagespace” is really quite the mindbender.

My long term goal is:
Replace Manjaro with NixOS on desktop (Everything up until building my own packages was no problem, the VM runs KDE with X, OpenSSH etc…)
Throw out my Macbook, find a good replacement to run NixOS on.
Find a cheapo host somewhere to run NixOS with containers for persistent services such as WeeChat, Syncthing, TypeScript labs (Since NixOS is heavier than others It’ll be some dedi)
Promote NixOS for the few Linux servers we have at work (We’re big into Microsoft and VMware at work)

Idk why i wrote my ambitions with Nix here, but it might be insightful for someone to know what people want to do and what’s blocking them from getting started.

Languages i have experience with already is only C# and C++ (Python, PowerShell, JS, PHP, bash scripts in small amounts too) as I’ve been involved in projects using these languages. I should probably start by reading the Nixlang manual before asking for help, so far i must say the documentation is quite good (except for building your own packages in my exp).

1 Like

No, I put it off for now as it was so arcane to me what i had to write to accomplish what i wanted. Coming from using Debian derivates and Manjaro where everything lives in a global “packagespace” is really quite the mindbender.

@Salsa9 he global namespace for packages is exactly what Nix tries to avoid, but I agree, once you’ve learned a “design pattern” wrt. package management, switching mental models can be initially costly.

It is quite simple to package things in Nix and specify dependencies, once you’ve seen an example (PM me if you want help with packaging your application). This is a good anecdote to the thread, since I myself felt the same.

Cheatsheet - NixOS Wiki is quite nice for beginners coming classical distros, but is lacking in even a basic “from scratch” example of how to package things.

I installed NixOS a year ago on my one server. I have to deal with 82 linux x86 servers and 112 ARM servers. Sometimes, when I have time, I install a new distribution on one server. Nix OS is simple. But in my opinion it is too simple because it is not intuitive at all. I don’t have time to read the entire documentation. There is a lack of simple “how to” guides on the Internet. If I don’t know something in Ubuntu or Debian, I write a phrase in google and pop up thousands of links on how to do it. Nix is so unpopular that the user relies on Documentation that they don’t have time to read.

I’m not aware of any good documentation for this, but you would want to do:

# shell.nix
with import '<nixpkgs>' { };

clangStdenv.mkDerivation {
  name = "CManGOS-git";
  
  src = null;

  nativeBuildInputs = [ cmake pkg-config ];
  buildInputs = [ openssl boost bz2 mysql ];
}

and to build it locally, you would just do:

nix-shell
# follow normal build instructions

there might be some “additional pain” if they have fixed paths in their code. e.g. /usr/bin/...

We have vscode with cpp extensions in the repo. Visual Studio Code - NixOS Wiki , I’m also working on creating a fhs-wrapped variation which will allow for extensions to “just work” vscode.fhs: add buildFHSUserEnv wrapped version by jonringer · Pull Request #99968 · NixOS/nixpkgs · GitHub

Purity does have a cost. The real pain is that it’s not apparent what you should do. And the learning curve is steeper than it needs to be.

7 Likes

We have searches for packages and options.

the nixpkgs framework (it’s libraries and conventions don’t have a reference guides with any examples).

It seems that it was written in adhoc manner, although it’s devilishly brilliant, I know for a fact it’s devilishly brilliant, because devilishly brilliant programmers don’t write devilishly brilliant documentation.

Many things have a level of API documentation… nix has none, and grepping the source right into the weeds, is probably going to put people off on first use.

is a brave attempt , nix/OS doesn’t have shortage of documentation, it has a shortage of Library functions->real world example . I guess that’s somewhere between API documentation and a Cookbook.

take this an example.

let
  sshkeys = pkgs.fetchFromGitHub {
    owner = "abc";
    repo = "def";
    rev = "123";
    sha512 = "456";
  };
  getpubkeys = user: builtins.readFile "${sshkeys}/${user}.pub";
  mkuser = user: { name = user; isNormalUser = true; extraGroups = [ "wheel" ]; initialPassword = "hdsklf"; openssh.authorizedKeys.keys = [ (getpubkeys user) ]; };
in
{
  users.users = (lib.genAttrs [ "alice" "bob" "charlie" ] mkuser) // {
    dana = { name = "dana"; isNormalUser = true; extraGroups = [ "wheel" ]; openssh.authorizedKeys.keys = [
      "ssh-rsa AAAA..."
    ]; };
  };
}

that’s pretty amazing as it goes… but uses lib.genAttrs

which is completely undocumented. (or is it).

apart from…

it’s here… with examples…

so i think all this stuff is actually documented, it’s just tucked away in .nix files… it needs to be extracted and placed in a searchable system like nix options (which is brilliant).

It’s a massive task. By the time i first this post , another 10 functions will be added to nixpkgs standard library…

Most projects ‘win’ not because they are technologically superior, they just have superior documentation over other pieces of technology.

2 Likes

The documentation for the nixpkgs library functions is extracted from the comments and is printed right in the document you linked: Nixpkgs 23.11 manual | Nix & NixOS

These examples are generated and beatified , that’s pretty ‘clever’… but i guess there’s only so many comments you can fit into a .nix until they become quite horrific to look at… You couldn’t for example give a use case for something like that within .nix comments. It actually makes sense why the examples are so short in the manual.

Inline comments are not documention, and shouldn’t live directly in the code… but the fact that it does this is testament to the whole automation in nix. :slight_smile: .

Maybe i can automate myself out of job one day…

Thanks to the llamma… for documentation… or attempting to give examples for functions.

https://github.com/NixOS/nixpkgs/commit/523e3283189710a9a58bd2828f45a7413f3ede3e#diff-4f436977e5d35e5466f04052c4b2d22e73ef0c98e1dd7888256fd7a8506a5678

so is it documented , or as i said… or is it?

Hi Jon!

Thanks for your effort, I was actually closer than I thought from reading docs.

Though one thing here that is unclear is where clangStdenv is declared and defined and how it relates to the normal stdenv. How nix-shell knows to “use” the clang stdenv just because we called a function on this.

There were some syntax errors in the example you sent me but i got that resolved. I’ll be posting a new thread about cmake and boost.

Thank you so far! :slight_smile:

1 Like

I typed it free hand into a textbox :slight_smile:

2 Likes

Is Nix even designed for the average user ?
I don’t see why a distro hopper should care to use Nix.
Let’s know our customer / preferable user.

Nix does best when it’s:
SRE/devops at companies or hobbyists who have a purist view on running their home server / laptop.

Let’s be frank, for many users Ubuntu or Fedora is just better suited.
We should lean into the users that excel the best and provide them even more reason and tools to do so.

2 Likes

Yes, I think as well that nixOS is not for the average user. Though distro hoppers and other kind of videos that “test” nixOS and make it appear to be harder to grasp than Gentoo do us no favor.

We as a community have to point out, that it was using nixOS wrong and that you have to think differently or we will somewhen have an image of the system that makes everything more complex than necessary, rather than the system that has puppet/chef/ansible as well as terraform built in… Even for the DevOps…

1 Like

Even if we just target power users, we should try to minimize onboarding pain as much as possible. If people like the declarative nature of Nix, then they’ll stay, if they prefer other distros, then they’ll switch anyway.

9 Likes

SRE/devops at companies or hobbyists who have a purist view on running their home server / laptop.

It is not so much a purist view, wanting some niche tools to be installable without breaking the main system, or maybe being able to benefit from mixing fresher and more stable versions of various stuff despite conflicting requirements w.r.t. basic libraries.

But in any case being qualified to know what exactly you want, and also wanting some minority thing (which often but not always comes with the previous part), is probably necessary to benefit from Nix, and also highly correlated with being able to learn Nix with reasonable time investment.

2 Likes

While reading this thread two ideas popped into my mind:

  1. Add a nasty red warning when users are abusing nix-env
  2. Having NixOS “flavors” much like other distros do. In the context of NixOS, I’d imagine that as some sort of easy to understand NixOS “rice” bundled as part of the installer where you can select some preconfigured DE/WM and start from there.

I was thinking of just making this possible through a calamares installer. NixOS is already very much a “choose-your-own-adventure” like Distro.

2 Likes

How do you want to identify “abuse”?

home-manager uses nix-env to “install” the created environment into the users env.

Do you want to show that warning now to all home-manager users that indeed do everything “right”?

1 Like

Yeah, calamares installer sounds great.
And what I pretty much meant is to just give users an example on which they could build upon. (Learn by example kind of thing) NixOS is very unique and I feel like that would be helpful. Might be just me

Yeah, you are right. I have not thought about that. Unless you’d add an additional argument to disable the warning? but yeah… at that point it’s just weird