Is NixBSD a possibility?

Hello, I would like to ask if it’s possible to bring NixOS’s configuration system to FreeBSD? I know the Nix packages work on FreeBSD but I’d like to know not only if we can install packages from the config file but do all of our configurations from there just like NixOS? I’m assuming I’d have to compile FreeBSD from scratch but to be honest that sounds like a cool project to do if I could find some help for it.

9 Likes

I believe right now NetBSD packages are in a better shape than FreeBSD.

I think BSDs structure their builds reasonably, so yeah, building stuff inside Nix derivations and doing your own installation scripts in activation should probably work. It’s another story that without packaging their libc their system utilities etc. you might end up with more of a GNU/kBSD, but with enough effort Nix-managed BSD should hopefully work.

Making this all reasonably customisable is, of course, a separate ton of effort.

3 Likes

At this point FreeBSD has come along way. They’re probably much the same, and once mesa: fix cross compilation to x86_64 by alyssais · Pull Request #233628 · NixOS/nixpkgs · GitHub is merged, FreeBSD will pull ahead because a bunch of graphical stuff will start working.

6 Likes

You might find this semi-related thread interesting: Support non-Linux kernels in NixOS · Issue #26850 · NixOS/nixpkgs · GitHub

5 Likes

Wait… Graphical stuff not working yet? I could have sworn I tried it in the past. That aside I guess no one would be interested in such an idea other than myself. And well… I don’t know the ins and outs of Nix yet. I could probably make a custom FreeBSD but with the knowledge I have of NixOS it looks rather hard to do. Although if you guys can point me to somewhere that I can get help from, maybe I can work something out.

1 Like

Do you want a thing like the defunct Debian GNU/kFreeBSD?
Or just a thing like Nixpkgs in Apple Darwin?

What I’m trying to achieve is to make FreeBSD with NixOS philosophy. Everything is in one config file and the setting file is portable so it can work on other machines as well. In fact if possible 1to1 with NixOS. So that you can jump from a NixOS configuration to a NixBSD configuration within seconds. So neither one of those options you gave really.

(Also preferably no GNU in it…)

1 Like

I expect that will be tough, given that the services more-or-less assume systemd…

1 Like

Just nixpkgs e.g. with a home manager or something similar – that might be a much more realistic goal.

1 Like

That’s a great idea! It’s true systemd calls were going to make a huge problem but making something like a home manager sounds doable.

1 Like

Basically, most of the things are on a single trajectory here!

  1. Check what clearly still needs fixing about packages and fix it.
  2. Home-Manager or just buildEnv, but try using a user env constructed via Nix (and see what packages still need fixing)
  3. Build bits of system side within Nix. Maybe try using the stuff from there in the user environment.
  4. Hacky build of a whole system with bootloader update.
  5. Customisable-ish build of a whole system.
  6. Use module system in a way where service configuration can be reused between Nix-managed-BSD and NixOS. Maybe these are technically separate modules who just reimport the config generation logic. But whatever, you can now easily port services between your configs.

I recall seeing @Ericson2314 working on nixpkgs *BSD support

Also using not-os as a base for this is probably the only way to go. There is also an issue on this: Support NetBSD in addition to Linux · Issue #16 · cleverca22/not-os · GitHub

2 Likes

As a basis for configuring the whole system with nix, GitHub - numtide/system-manager: Manage system config using nix on any distro might be a good starting point. You could probably use the same basic interfaces, but services and many modules of course would have to be changed to fit BSD.

@qyliss has done the vast majority of the Nixpkgs work.

My next BSD task will be, once Nix is CI’d against Nixpkgs 23.05, to utilize her work to cross-compile Nix to both BSDs.

4 Likes

I don’t come with much of a skillset however if you tell me what this work involves I could try my best to help.

1 Like

https://github.com/NixOS/nixpkgs/issues/26067

1 Like

The first thing that needs to happen is flake: update nixpkgs: 22.11 -> 23.05 by vcunat · Pull Request #8569 · NixOS/nix · GitHub getting finished.

2 Likes

It looks like a NixOS/kFreeBSD to me.
It has at least two serious hurdles:

  1. NixOS is too tied to Linux
  2. NixOS is too tied to systemd

My idea for now is a bit more modest:

  1. BSD as tier 1, or at least tier 2, on Nixpkgs.
    It makes few to no sense to try it before that “turning point”.
  2. NixBSD from scratch.

NixOS has a lot of cool stuff that’s actually portable and could be shared between NixOS/Linux and NixOS/*BSD

  • Core NixOS concepts such as
    • toplevel
    • the activation script
    • switch-to-configuration minus the systemd part
    • environment.*
  • The NixOS VM test framework. This is barely coupled with NixOS proper.

BSD support could initially be implemented as an alternate module list.

Some interesting first milestones would be

  • A cross compiled Nix that runs on *BSD

  • A package like darwin.builder that produces a VM launcher (ie produce a *BSD image containing an SSH server and a Nix that can serve a “remote” build; can be super hacky as long as it works). This will enable anyone to test with *BSD.

  • Make *BSD builds completely transparent (behind a single option on NixOS and/or nix-darwin) Transparent VM builds - a hook to start and stop a builder VM · Issue #8604 · NixOS/nix · GitHub

  • Linux / *BSD multi-boot with bootspec

And to work towards BSD support in NixOS:

  • BSD image support in the NixOS test framework.

  • Refactor modules such as users-groups.nix to work in a BSD context. Perhaps by splitting into interface vs implementation modules. Load only the modules that you need (and work) with nixpkgsFlake.lib.nixos.evalModules aka (import <nixpkgs/nixos/lib> {}).evalModules.

  • Establish a pattern for supporting services on both operating systems without duplicating everything. RFC 78 System-agnostic configuration file generators has some ideas for such a pattern.

Disclaimer: I don’t know a lot about the BSDs, but I do know where it should be integrated.

10 Likes

Porting NixOS could look a lot like Split nixos/nix-daemon.nix by roberth · Pull Request #241690 · NixOS/nixpkgs · GitHub
Portability wasn’t even my original goal, but rather it was just a consequence of the cleanup. You’d now only have to port a smaller module that’s exclusively about the daemon service.

5 Likes