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.
- hallettj ( @hallettj@beehaw.org ) English5•9 months ago
I think there’s a way that might be easy-ish. In short what the
services
setting does is to get necessary packages, write configuration files, and install systemd unit files. You can build a NixOS configuration, and symlink or copy the necessary systemd units and configuration files. I think that would work, and would not interfere with other stuff on your system.NixOS configurations must be built with
nixos-rebuild
- you can’t usenix-build
by itself. You can put your configuration wherever, and run:$ nixos-rebuild build -I nixos-config=./configuration.nix
That will build everything in paths under
/nix/store/
without touching anything else on your system. It will create a symlink in your working directory calledresult/
with a fully-built, bot not installed, NixOS. If you were running NixOS you would runnixos-rebuild switch
to update symlinks to point to all of this stuff. But you’d skip that step.result/etc/systemd/system/
contains systemd units. There will be a lot of stuff there that you don’t want. You’d need to selectively symlink or copy units from this directory to your/etc/systemd/
tree.The units use full paths to binaries in
/nix/store/
so you don’t need to do anything extra to install software packages.You might need to symlink or copy configuration files for your services. Those should also be somewhere in
result/
.If NixOS and Debian use the same systemd target names your services should run automatically on boot. If not you might have to do some fix-up, or run
systemctl
commands manually. I think you’d need to run somesystemctl
commands to start and stop services if you want to update without rebooting.You can probably do all that symlinking just once if you symlink everything through that
result
symlink.Edit: Although, taking a closer look at what
services.nextcloud
does I see that it does a lot, like initializing databases and creating user accounts if you choose to use a local database. It might be a lot of work to chase down all of the configuration that you would have to copy over. Running NixOS is definitely going to be easier.- tuckerm ( @tuckerm@supermeter.social ) 2•9 months ago
Oh, that’s a really cool idea. I’ll check that out just for my own nix education, although I’m a little leery about doing something so custom for my first nix setup, especially if
services.nextcloud
has a lot in it. Thanks for the info, though! That’s really good to know about. I’ll probably end up running NixOS in a docker container. The server is an Orange Pi 5, which doesn’t have a stable NixOS image available for it, unfortunately. - hallettj ( @hallettj@beehaw.org ) English2•9 months ago
I realized I made an implicit assumption that I didn’t explain. You can use Nix without NixOS. But the configuration you’re looking at is specifically a NixOS configuration. The shortcuts for setting up nextcloud services are based on the NixOS module system. You could get the same setup with Nix without NixOS, but you’d have to reproduce some of the functionality that is provided out-of-the-box in NixOS. My answer is one way to use the functionality from NixOS without fully installing NixOS.
- pr06lefs ( @pr06lefs@lemmy.ml ) 3•9 months ago
docker container with nixos inside??
- tuckerm ( @tuckerm@supermeter.social ) 3•9 months ago
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.
- pr06lefs ( @pr06lefs@lemmy.ml ) 3•9 months ago
It’ll be easy to transition to a nixos machine or cloud instance later.
- jeffhykin ( @jeffhykin@lemm.ee ) 1•9 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.
- jeffhykin ( @jeffhykin@lemm.ee ) 2•9 months ago
Idk who downvoted this, as its legitmately probably the most easy way for people who are familiar with docker.
- chayleaf ( @chayleaf@lemmy.ml ) 2•9 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.
- moonpiedumplings ( @moonpiedumplings@programming.dev ) 1•9 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.