Can I use NixOS without being able to code?

I’ve been using several Linux distros over the years, but I have no programming background, zero, nothing.

I spent 2 months trying to configure NixOS, every time I try to rebuild it fails. In the terminal I get errors for lines copied and pasted from the NixOS wiki. I must admit I did not expect this distro to be so difficult to set up. I told myself that once passed the initial hurdle it would be downhill, but now I feel like I wasted 2 months on something I will never be able to use.

Did you guys had the same hardships in the beginning? Did you know how to write code prior to using NixOS? Should I move to something else? The closest thing I found would be Guix, but it seems as difficult and it has a smaller repo, the repo is a very big reason why I was interested in NixOS in the first place, other than the declarative approach which makes a lot of sense to me, but I completely failed in understanding the language, the syntax, everything. All the documentation I read has been useless because in the end all I can do is copy-paste stuff and try to intuitively edit it to my needs, but it’s like trying to communicate speaking a language I don’t know.

Is there some tools for noobs that guides the user like an interpreter would do for someone who doesn’t speak a language? Something I can input the state I want the system in and it outputs the lines I must enter in the various configuration files? Or should I just give up on NixOS?

NixOS is an OS that uses code written in the nix language to configure the system. You can always ask here for help if you’re stuck, but if you’re unwilling or unable to learn, NixOS is not the distro to use. You don’t necessarily need prerequisite knowledge, but you need some preseverance in that case, and it’s hard for strangers to tell you whether it’s worth it for you.

But step 1 is: forget the wiki, just ask here if you need help. That probably is the source of frustration.

And keep another system that’s not NixOS around, so that you don’t feel pressure to learn quickly. NixOS forces you to become a packager, sysadmin, and sometimes developer to get going - that’s a massive learning curve for sure.

7 Likes

I’ve been coding for nearly 40 years, and 18 months after starting with Nix I still don’t feel I know what I’m doing! Just about OK with very basic stuff, but the moment I try to do anything more sophisticated it all goes horribly wrong. My lack of functional programming experience really worked against me, I think.

If you’re struggling with NixOS itself, don’t forget you can use nix + nixpkgs on top of another distro as a way of either getting newer package versions, or creating declarative dev/shell environments. There are various different front-ends that can help with that (devenv being the first that leaps to mind), and I think some will generate nix expressions that you can inspect to see ‘under the hood’ how they did what you asked. That might be a gentler approach path than going full NixOS from the start?

3 Likes

There have also been various attempts to make GUI config editors for NixOS, but everything I turned up on a quick search looks to be in some state of abandonment, with the possible exception of Snowfall / SnowflakeOS’s stuff:

The actual ‘alpha’ SnowflakeOS isos don’t seem to have been updated for a year, but if you’ve already got a successful NixOS install, you might be able to add the above to it.

It feels like a command similar to sysctl(8) is needed to make nixos configuration easier, but I’ve not come across one …

Edit: https://mynixos.com/ might be worth a look - I’ve not tried it personally.

1 Like

I’ve been using several Linux distros over the years, but I have no programming background, zero, nothing.

You don’t really need to be a programmer to learn how to use or like NixOS. For a basic setup you can just treat the NixOS configuration as a that, a configuration file with an particular syntax.
Even if you had some programming knowledge, unless you used functional languages a bit, it wouldn’t help much in understanding the Nix language, but that’s fine.

I spent 2 months trying to configure NixOS, every time I try to rebuild it fails. […] now I feel like I wasted 2 months on something I will never be able to use.

Did you guys had the same hardships in the beginning? Did you know how to write code prior to using NixOS? Should I move to something else?

Not really, but I wasn’t trying to achieve anything grand. I just followed the manual to a basic graphical setup, imported some custom systemd services I had from my previous Arch installation, my WM configuration and scripts.
Maybe you’re trying to do too much all at once?

The repo is a very big reason why I was interested in NixOS in the first place, other than the declarative approach which makes a lot of sense to me, but I completely failed in understanding the language, the syntax, everything.

You don’t really need to learn the language, I’d recommend against trying to follow a guide or tutorial if you don’t have any specific goal in mind (creating a complex package, NixOS module, some abstraction, etc.).
And even if you did, there is a pratically infinite amount of examples you can read, copy and try to understand (everyting is in Nixpkgs).

Something I can input the state I want the system in and it outputs the lines I must enter in the various configuration files? Or should I just give up on NixOS?

Yes, they’re called NixOS users. You can find them here on the forum or in the Matrix chat rooms, ask nicely and they will help you.

What is it that you’re trying to do? I’m curious at this point.

2 Likes

step 1 is: forget the wiki, just ask here if you need help

Basically the complete opposite of Arch’s RTFM lol

My idea is that I only want to backup my home folder and all my config files should reside there. The configuration.nix file should always contain only one line that points to the config directory.

For example I will have the /home/user/NixOS/ folder containing

disk-mounts.nix
./networking
├── network-config.nix
├── ./ssh
    ├── ssh-server.nix
    ├── ssh-client.nix
./software
├── ./utilities
    ├── cli-utils.nix
    ├── ./gui
        ├── example1.nix
        ├── example2.nix
        ├── ./another-folder
            ├── another-file.nix
├── office.nix
├── browsers.nix

and the configuration.nix file will contain only this line (which is wrong apparently?)

{lib, ...}: { imports = lib.filter (n: lib.strings.hasSuffix ".nix" n) (lib.filesystem.listFilesRecursive /home/user/NixOS); }

or

{lib, ...}
{
  imports = [
    ./hardware-configuration.nix
    lib.filter (n: lib.strings.hasSuffix ".nix" n) (lib.filesystem.listFilesRecursive /home/user/NixOS);
  ]
}

if I don’t want to move the hardware-configuration.nix file to the home folder.

When I want to add a feature, for example I want to mount an NFS share, I will add a preconfigured nfs-client.nix file in ./networking and sudo nixos-rebuild switch.

If I want to replicate the system on another machine, or I want a different configuration, I will just remove/add the relative .nix files in the folder structure and just invoke the rebuild command.

If I want to switch DE I will delete gnome.nix and drop kde.nix in its place, so that just by replacing that file I will rebuild to a different DE, without always editing a giant config file.

But I don’t understand, should my .nix files always begin with a line such as { config, pkgs, ... }: or can I add that line in the main config file in /etc/nixos and ignore it in the folder structure?

The terminal would point me to the = being an error in lines such as

services.displayManager.sddm.wayland.enable = true;

which I literally copy-pasted like that. Or it would spit out something like the x.nix file doesn't look like a configuration file or something like that.

Can you show me what I’m doing wrong or point me to a better direction? If I must add information please tell me.

I’ve been coding for nearly 40 years, and 18 months after starting with Nix I still don’t feel I know what I’m doing!

My goodness! I had no idea what I was getting into.

Thanks for devenv, I will try and see if it’s more explicative than terminal output. I also looked for other tools, but I found what you said, every project was abandoned except SnowflakeOS, which just enters lines in the main configuration.nix file, which is not how I want the system to be structured, as I detailed in the previous post.

I just followed the manual to a basic graphical setup, imported some custom systemd services I had from my previous Arch installation, my WM configuration and scripts.
Maybe you’re trying to do too much all at once?

Perhaps so

What is it that you’re trying to do? I’m curious at this point.

I detailed what I want to accomplish in another reply. I also used the graphical installer, so the initial configuration was set up automatically, I only decided the partitions and their sizes and the username.

That’s because Arch’s wiki is well-maintained, relatively, compared to the NixOS one.

Okay, well, it’s not that hard, it just comes down to time investment and how often you ask questions. The less asked the longer it takes.

Those are called module arguments and you only need to list the args that you use in that given module. Usually you want to write one module per file, so if you don’t use it in the file, don’t list it out. Most often you’ll use pkgs, lib, config, and whatever custom args you provide, sometimes options and modulesPath, and if there’s other module args then they’re so niche I forgot about them.

1 Like

Yeah, well, I’m used to try with the docs first before asking because otherwise other users would tell me to go read the documentation first anyway, I didn’t know things worked like this around here.

if you don’t use it in the file, don’t list it

So I can’t spam all of them at the beginning of each file huh? That was my plan actually.

Those might be the reason why it keeps failing, I need to carefully select those that are needed and see if it makes it.

1 Like

configuration.nix doesn’t need to be kept in /etc/nixos, from what I can tell - nixos-rebuild should check the NIXOS_CONFIG env variable to find it for a non-flake configuration, and with a flake configuration you can pass the path of the flake with the --flake option I believe.

Alternatively you could use something like deploy-rs - normally used for deploying to remote machines, but I can see no reason why you couldn’t use it to deploy to localhost.

1 Like

I’m afraid flakes and deploy-rs a little too much over my head at the moment

Basically the complete opposite of Arch’s RTFM lol

I recommend looking at the manual, not the wiki. The documentation in the manual is typically written by the same people that wrote the
respective code in NixOS, while the wiki used to be completely unofficial and was only “adopted” officially a few months ago. If you find some info in the manual it’s highly likely to be up to date and correct, for the wiki, not so much.

Unfortunately for new users, the older experienced users find easier to just look at the code in Nixpkgs rather than reading the manual, so the documentation is famously lacking. People are working on improving this, but NixOS is still a lot behind projects like Arch or Debian.

My idea is that I only want to backup my home folder and all my config files should reside there. The configuration.nix file should always contain only one line that points to the config directory.

That is a good idea and I think it’s what most of us do as well. As as suggestion, don’t to put anything at all in /etc/nixos/configuration.nix: you can specify the entry point using the environment variable NIXOS_CONFIG or passing -I nixos-config=... to nixos-rebuild.
If you find this annoying you can set the variable in your shell (using environment.variables.NIXOS_CONFIG=...), or add this:

nix.nixPath = [
 "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
 "nixos-config=/home/ExtraJuicy/NixOS/configuration.nix"
 "/nix/var/nix/profiles/per-user/root/channels"
];

The latter is equivalent to passing -I nixos-config.

For example I will have the /home/user/NixOS/ folder containing

disk-mounts.nix
./networking
├── network-config.nix
├── ./ssh
    ├── ssh-server.nix
    ├── ssh-client.nix
./software
├── ./utilities
    ├── cli-utils.nix
    ├── ./gui

This is way too complicated, I think you’re definitely overdoing it. Split the configuration in some files, but don’t create subdirectories and manually specify which modules to load in the imports = [ ... ]. Trust me.

If I want to switch DE I will delete gnome.nix and drop kde.nix in its place, so that just by replacing that file I will rebuild to a different DE, without always editing a giant config file.

This seems like a bad idea, what if you want to go back or temporarily disable something? There is no way to “comment out” a file. I’ve seen some advanced users define their own options to toggle large portions of their configuration (shared between multiple machines and such), but to me it feels just too complicated. I just put separate stuff into separate files and imports them where I need them. For example, I have a neovim.nix file that configures my editor and I load it into the configuration of all my machines.

should my .nix files always begin with a line such as { config, pkgs, ... }:

The answer is “it depends”. If you’re importing these files using imports = [...] from your configuration.nix then yes, they must be “NixOS modules”. To put it simple, a NixOS module is a file with this structure:

{ ... }:
{
 some.option.name = "value";
 some.other.option = true;
}
2 Likes

Sounds like the same thing with extra steps to me. In my case I would have to put everything KDE-related into the kde.nix file, just like you are suggesting, but I would not need to edit the config file to import every single file I want to add or remove, it would be double the work.

There is no way to “comment out” a file

I wouldn’t need to, I would just delete it (I will have a backup folder where I keep all the files, those I use and those I don’t), or I can always edit the file should the need arise. So the difference being moving .nix files instead of manually entering them one by one in the main config file.
This one line should be everything I need in the main config file

{lib, ...}: { imports = lib.filter (n: lib.strings.hasSuffix ".nix" n) (lib.filesystem.listFilesRecursive /home/user/NixOS); }

all the folder structure would be picked up automatically, no matter how nested it is. I wouldn’t call it complicated, it’s just one more layer of abstraction, the complicated thing is the syntax, my hope is that once I master the basics of the syntax I can go on with just that.

@waffle8946 @srd424 @rnhmjoj
By the way thanks everyone for the support, now I don’t see everything dark anymore. I was so projected into this thing and spent so much time studying and crafting all the configs, that after the nth failure I was about to throw the towel and mourn all the hours spent reading stuff and writing down everything. You guys gave me the confidence that I can make it in the end, so thanks for your help, it is much appreciated.

3 Likes

You can if you really want to.

1 Like

Would this be a correct syntax for a .nix file to only install an application for example?

{ config, pkgs, options, ... }:

environment.systemPackages = with pkgs; [
  thunderbird
]

Ok, if you don’t care of have a backup it’s another matter.

But it doesn’t require any programming in Nix. Isn’t that the thing that got you stuck for weeks? Anyway, it seems to be working ok for me.

I tested it with nix repl inside my configuration directory:

nix-repl> lib.filter (n: lib.strings.hasSuffix ".nix" n) (lib.filesystem.listFilesRecursive ./.)  [
  /home/rnhmjoj/../backup.nix
  /home/rnhmjoj/../configuration.nix
  /home/rnhmjoj/../hardware.nix
]

So I’d say you’ve done great job for one with no programming background. I also tried building a system with it:

nix-repl> import <nixpkgs/nixos> { configuration = {lib, ...}: { imports = lib.filter (n: lib.strings.hasSuffix ".nix" n) (lib.filesystem.listFilesRecursive ./.); }; }
{ ... };
  options = { ... };
  pkgs = { ... };
}

and it didn’t complain, so this part is fine. Your problem may have only be the fact your “.nix files” weren’t NixOS modules.

2 Likes

Yes, but if no one mentioned it already, prefer searching for options (NixOS Search) first before you go to the last resort of putting stuff in a package list.

2 Likes

Yes, I spent weeks trying to dig stuff from the wiki and customize it without even knowing the syntax, I just edited the relevant parts to my own needs, so when something fails it could be anything tbh.

Thank you, but the job I’ve done is just copying from the docs and from other discussions if it was understandable enough, it seems like everyone around here has tons of knowledge, I can open any other thread and it will be some super-specific and technical question on how to achieve something super particular, and here I am needing help with attributes which, as you said,

are the first of my problems, a thing that should be one of the very first I should have learned.
I will try adding { config, pkgs, options, ... }: to the beginning of each file and see if it works.