systemd services for non-NixOS

245 views
Skip to first unread message

Spooky Hunter

unread,
Oct 2, 2017, 4:17:12 AM10/2/17
to nix-devel
Hello all,

I'm using Nix packages on various systemd based Linux distro (Arch, LFS, Debian, CentOS and NixOS of course).
Is there a technical reason why Nix doesn't provide ".service" file for non-NixOS?
It should be great to have fully Nix services on other distro.


Thanks,
SH

Rickard Nilsson

unread,
Oct 2, 2017, 4:27:17 AM10/2/17
to nix-...@googlegroups.com
The .service files for NixOS are generated from the NixOS configuration
(configuration.nix). That configuration is not available for other distros.

However, there is (technically) nothing that would prevent implementing
a stand-alone (non-NixOS) tool that could evaluate a NixOS configuration
(or a subset of it), build the .service files and then activate them for
a running systemd instance. However, many services use other parts
(uids, filesystem mounts etc) of the NixOS configuration. Such things
would be tricky to handle on non-NixOS distributions.


/ Rickard

>
>
> Thanks,
> SH

Eelco Dolstra

unread,
Oct 2, 2017, 7:57:24 AM10/2/17
to nix-...@googlegroups.com
Hi,

On 10/02/2017 10:17 AM, Spooky Hunter wrote:

> I'm using Nix packages on various systemd based Linux distro (Arch, LFS, Debian,
> CentOS and NixOS of course).
> Is there a technical reason why Nix doesn't provide ".service" file for non-NixOS?

Many packages do in fact provide systemd units, for example:

$ nix-build -A utillinux.bin

$ ls -l ./result-bin/lib/systemd/system/
total 16
-r--r--r-- 2 root root 155 Jan 1 1970 fstrim.service
-r--r--r-- 5 root root 170 Jan 1 1970 fstrim.timer
-r--r--r-- 2 root root 248 Jan 1 1970 uuidd.service
-r--r--r-- 2 root root 185 Jan 1 1970 uuidd.socket

--
Eelco Dolstra | LogicBlox, Inc. | http://nixos.org/~eelco/

czap...@gmail.com

unread,
Dec 4, 2017, 9:39:46 AM12/4/17
to nix-devel
On Monday, October 2, 2017 at 1:57:24 PM UTC+2, Eelco Dolstra wrote:
Many packages do in fact provide systemd units, for example:

  $ nix-build -A utillinux.bin
  $ ls -l ./result-bin/lib/systemd/system/

Does anyone know if such files could be then easily, possibly automatically, plugged into host OS's systemd infrastructure? A similar question was asked on unix.stackexchange.com (https://unix.stackexchange.com/q/349199/11352), and I tried to post an incomplete answer, based in part on above discussion (https://unix.stackexchange.com/a/408735/11352).

I'm potentially interested in such a solution, as a kind of "gateway drug" and "incremental step", which might let me (and other people in similar situation) gently evaluate NixOS-like infrastructure approach, making the transition less radical and drastic than an immediate jump to full NixOS (which we cannot afford at my workplace).

I imagine some kind of "activation script" would be needed in such case, possibly with some additional systemd tweaks in the host OS (adding the ~/.nix-profile/lib/systemd/system/ of some special user, e.g. "nixos-guest", to systemd; also maybe adding some special 'nixos-guest.target' file? I don't know systemd very well...) I outlined my current ideas in the stackexchange answer I linked above:


Some challenges I'm still not sure how to resolve:
 - how to rename/prefix Nix-generated .service files, to avoid conflicts with host OS's services?
 - not all .service files should be automatically activated, only the ones listed in some special list (e.g. "enabledServices = [...];") — how to take care of this?
 - how to disable old services in the "activation script" if they are removed from the list? (grep systemctl .service paths for '/home/nixos-guest/.nix-profile/'? or some smart setup with 'nixos-guest.target' and 'systemctl daemon-reload'?)
 - [nice-to-have] would it be possible to manage such a system remotely with NixOps?

I'd be grateful for any hints!
Thanks,
/Mateusz.
Reply all
Reply to author
Forward
0 new messages