this post was submitted on 21 Feb 2024
15 points (100.0% liked)

nixos

1233 readers
1 users here now

All about NixOS - https://nixos.org/

founded 4 years ago
 

Hi, sorry if that title isn't very clear. I just started learning about nix a couple days ago; I'll explain what I mean.

I'm trying to set up a web application that I'm currently hosting with Docker containers, but do it with nix instead, like what's shown in this blog post: https://carjorvaz.com/posts/the-holy-grail-nextcloud-setup-made-easy-by-nixos/

However, I don't have NixOS on my server. I'm using Debian, with the nix package manager installed.

Is it possible to use a nix config file, like the one below, when only using the nix package manager? Currently it errors when I try to call nix-build with it, giving an error about calling a lambda function that never called self. If I remove the self argument, it complains about config, and so on.

{ self, config, lib, pkgs, ... }:

{
  services = {
    nextcloud = {
      enable = true;
      hostName = "cloud.example.com";

      package = pkgs.nextcloud27;

      # Let NixOS install and configure the database automatically.
      database.createLocally = true;

      # Let NixOS install and configure Redis caching automatically.
      configureRedis = true;

      < other settings here... >
    };
  };
}

From what I've read, the services part of that creates systemd services, which makes me think that it only works if you're on a full NixOS system and not only using the nix package manager. But it's been difficult to find a clear answer on that, probably because I'm still learning what terms to search for.

top 11 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 6 months ago (1 children)

I am pretty certain you’ll need to be using NixOS, as the goal of the blogpost from my reading is about having an OS configured specifically for NextCloud hosting on Nix in a performant way

However, having a faster and more optimized setup can take some effort on these platforms. Thankfully, on NixOS it’s not hard at all, as I’ll show you.

[–] [email protected] 1 points 6 months ago

I see, thanks. I hadn't realized the difference between installing one package vs. configuring the system. (And in the case of creating a server setup, that would be configuring the system.) Well, that's good to know.

[–] [email protected] 2 points 6 months ago (2 children)

docker container with nixos inside??

[–] [email protected] 2 points 6 months ago (2 children)

Sounds like that's my best bet. My goal here was to stop using docker and use nix instead, but at least this would allow me to still use NixOS for the configuration and mostly ignore the fact that it's actually running in docker. I used the stones to destroy the stones kind of thing.

[–] [email protected] 3 points 6 months ago

It'll be easy to transition to a nixos machine or cloud instance later.

[–] [email protected] 1 points 6 months ago

You can also use nix to get docker so, its kinda meta.

There's a tool called devbox that uses nix under the hood and has services. Probably not what you're looking for, but its nice to know there are people working on a native solution.

[–] [email protected] 2 points 6 months ago

Idk who downvoted this, as its legitmately probably the most easy way for people who are familiar with docker.

[–] [email protected] 2 points 6 months ago* (last edited 6 months ago)

see Nix System Manager. Of course, you'll have to be really creative with selective module imports if you want to use something as complex as Nextcloud.

[–] [email protected] 2 points 6 months ago* (last edited 6 months ago) (1 children)

All of the configuration options you're specifying there are for the nextcloud NixOS module, it's not a magical part of Nix itself. Same with the self and other arguments at the top. Outside of NixOS (and home-manager, for user-level installations), all Nix is going to be able to do for you is build software, it cannot do runtime configuration or other alterations to your system like that.

[–] [email protected] 1 points 6 months ago

Thanks, that makes sense. When I saw the error about how self and config weren't being passed in, I assumed those must be values that NixOS gives you, not the plain package manager.

I saw a blog post a while ago that said you can basically get all the benefits of NixOS just by using the package manager. Sounds like that's not so true, although the package manager is definitely very cool by itself.

[–] [email protected] 1 points 6 months ago

https://github.com/erikarvstedt/extra-container

Let's you run nixos containers on non nixos distros. Requires a multi user install w/ a daemon.