News for hackers. Stuff that matters.
Re:NixOS on Framework Laptop by jph on Sunday October 17, 2021 @05:14PM (#28899860)
Framework + NixOS is the most exciting hardware + OS going IMHO. If someone wants to do a crowdfunding or devpay or similar to make them work out of the box together, I will gladly donate or pay.
Re:NixOS on Framework Laptop by jeppesen-io on Sunday October 17, 2021 @05:52PM (#28900123)
It's not what you're asking but I wonder if NixOS's hardware repo could expand to support Framework with some good defaults

That being said, I think there could be a good use case for "meta" NixOS distributions. I'm working on such a thing for a NixOS based RetroArch type thing. But could see a PopOS like configuration, focused on on an “out the box experience”

https://github.com/NixOS/nixos-hardware

Re:NixOS on Framework Laptop by samueldr on Sunday October 17, 2021 @07:27PM (#28900664)
Yes.

Anyone with the hardware is welcome to contribute to nixos-hardware!

Even "no-op empty configs" are good imo as they show "there's no magic sauce needed".

Re:NixOS on Framework Laptop by jeppesen-io on Sunday October 17, 2021 @08:03PM (#28900848)
good to know; didn't think about "empty" configs
Re:NixOS on Framework Laptop by emiller88 on Monday October 18, 2021 @10:24PM (#28914210)
https://github.com/NixOS/nixos-hardware/issues/323

Created an issue for this for anyone interested!

Re:NixOS on Framework Laptop by georgewsinger on Sunday October 17, 2021 @07:58PM (#28900826)
Possibly of interest: SimulaVR (www.simulavr.com) is about to release a crowdfunding campaign for a portable Linux VR headset which will run NixOS stock under the hood (basically NixOS + Simula's window manager).
Re:NixOS on Framework Laptop by tomjen3 on Monday October 18, 2021 @01:41AM (#28902576)
I don't really see them as exciting when they are still Intel only. As far as I am aware you can't upgrade the CPU, much less upgrade it to AMD.

I plan on keeping my M1 for a 2-3 more years, then we will have to see what Framework has come up with then.

I like them a lot in principle (peripherals that can be switched to what I need? Yes please. Upgradable RAM? thanks), but I also won't compromise on battery time, performance or "linux works outside the box". Battery time could have been an easy fix if they had made it so I could switch the battery without taking the laptop apart.

Re:NixOS on Framework Laptop by globular-toast on Monday October 18, 2021 @06:06AM (#28903866)
Replace NixOS with Guix and I agree!
Re:NixOS on Framework Laptop by phaer on Monday October 18, 2021 @07:24AM (#28904303)
I'd love to see Guix with SystemD, but there's no work going in that direction that I am aware of. While I appreciate the work on [GNU Shepherd](https://www.gnu.org/software/shepherd/manual/shepherd.html), especially their documentation quality and the use of scheme instead of the rather obscure nix language, learning yet another init system on top of a new distro while systemd seemingly has won most of the market makes NixOS more attractive. At least to me
Re:NixOS on Framework Laptop by mbakke on Monday October 18, 2021 @01:32PM (#28908130)
Even if Guix were to switch to systemd (it won't), end users would primarily be interacting with services through the same high-level APIs as now.

https://guix.gnu.org/manual/devel/en/guix.html#Services

That is, the only difference in practice would be replacing 'herd' with 'systemctl' when stopping and starting services manually. Anything else, such as modifying a service, has to go through the configuration system.

Similarly, for service authors, whether the API you design ends up creating a systemd unit file or shepherd service object is an implementation detail and would be mostly transparent.

Re:NixOS on Framework Laptop by whateveracct on Sunday October 17, 2021 @05:36PM (#28900008)

    import framework.nix {}
Re:NixOS on Framework Laptop by joppy on Sunday October 17, 2021 @06:22PM (#28900343)
The post itself shows that it is non-trivial to even boot this hardware with Nix.
Re:NixOS on Framework Laptop by whateveracct on Sunday October 17, 2021 @07:07PM (#28900577)
yes I know - I am implying a future where they Just Work and we do the hard work of building needed abstractions

my code is possible if people want it :) the real value of NixOS is hardware and OS config can be turned into libraries!

Re:NixOS on Framework Laptop by prophesi on Monday October 18, 2021 @01:08AM (#28902400)
The only issues were needing to disable secure boot (which is usually a required step on laptops preinstalled with Windows anyways), and using a recent Linux kernel that has the required WiFi driver. Which the tutorial linked in the post mentions.

And then Linux in general is notorious for having issues with USB WiFi adapters. More info on that can be found here https://github.com/morrownr/USB-WiFi

Re:NixOS on Framework Laptop by fungiblecog on Sunday October 17, 2021 @05:16PM (#28899871)
+1
Re:NixOS on Framework Laptop by b9be520d93286 on Sunday October 17, 2021 @05:39PM (#28900029)
Can you do NixOS without systemd? If not, I'd look elsewhere for the distro. Maybe Guix?
Re:NixOS on Framework Laptop by jeppesen-io on Sunday October 17, 2021 @05:42PM (#28900064)
Just take the time to learn systemd. Once you do, like nix, it saves so much time
Re:NixOS on Framework Laptop by rollcat on Sunday October 17, 2021 @06:21PM (#28900338)
systemd is so complex, I've come to a conclusion, that it no longer fits my definition of free software.

We allow runaway complexity to obscure the inner workings of an important software package, to the point, where having source access no longer makes a practical difference to a "casual" power-user or even a software engineer. I can source-dive runit, s6, OpenBSD's rc, or OpenRC and within a weekend, have a pretty OK understanding, fix a bug, or add a feature. Having software as complex as systemd taking so many roles, and making itself so ubiquitous and irreplaceable, makes me feel that I no longer have any control or understanding of my system, bugs or misfeatures just become things you live with, or you riddle yourself with arcane workarounds. Portability suffers, monoculture takes root.

I've lost faith in "mainstream" Linux distros. I use macOS and OpenBSD for workstations, and Alpine where I need e.g. Docker. It must either be simple enough to understand, or provide enough utility/convenience that the lack of (practical) source access is compensated. systemd fits neither category.

Re:NixOS on Framework Laptop by viraptor on Sunday October 17, 2021 @07:09PM (#28900588)
Have you actually tried to dive into the part you're interested in? Where did you find the complexity? I've done it a few times for different components and found them pretty well separated and the source pretty straightforward. I have other issues with them, but complexity/obscurity of the is was not one of them.
Re:NixOS on Framework Laptop by Aeolun on Sunday October 17, 2021 @08:37PM (#28901049)
Looking at using systemd to just run a binary automatically on boot (which some smart person on HN told me was the easiest way). Just looking at the systemd landing page overwhelms me.

Boot Loader Interface, Discoverable Partitions Specification, etc.

I’m sure the implementation details are very interesting.

But where is the “Configure and Start a Service” option? Which is arguably the most important.

Re:NixOS on Framework Laptop by md8z on Sunday October 17, 2021 @09:47PM (#28901461)
The man pages are the reference manual. You might want to search for "systemd service tutorial" or something like that, there's a lot of blogs that explain how to make a simple service.
Re:NixOS on Framework Laptop by viraptor on Monday October 18, 2021 @12:37AM (#28902271)
Their frontpage sucks, but that's not related to the code really :)

For a quick intro to new services, see the examples here: https://www.freedesktop.org/software/systemd/man/systemd.ser... (they should cover most basic needs) then read above for the details on the parameters. You stick the file in /etc/systemd/system/your_thing.service and enable/start it.

Re:NixOS on Framework Laptop by markstos on Monday October 18, 2021 @09:35AM (#28905295)
I'm not sure why this comment was downvoted. I've read all the systemd documentation and this comment is spot on. System is lacking good documentation along the lines of "the least you need to know to setup and manage a service".

No, it's not as easy as "man systemd.service".

What's probably most useful in that documentation is the "hello world" example, which is buried at the bottom of the documentation. Also, key details are elsewhere, in "man systemd.exec" and "man systemd.unit".

The systemd docs a great comprehensive reference, but the man pages are poor introductory documentation.

Some useful tips that are hard to find:

  * man systemd.directives documents every directory and will tell you which man page as the full documentation for it.
  * man systemd.index lists every man page related to systemd.
Re:NixOS on Framework Laptop by candiddevmike on Sunday October 17, 2021 @06:45PM (#28900453)
Yes, systemd has a ton of surface area and options. Yes, the man pages are long. No, you don't need to read them--the beauty of systemd is you control how much of the complexity you use. Unit files can be 10 lines or 30. Most of the extra options are for security and hardening, when you need them you'll be glad they're easy to turn on. For the other components, I think have a stable, familiar, and consistent set of core services (boot, ntp, logging, networking) is glorious
Re:NixOS on Framework Laptop by ben0x539 on Sunday October 17, 2021 @08:25PM (#28900965)
That's an interesting line to draw! Do you think this also extends to stuff like firefox or java vm, or are you only focusing on "system" software with that analysis?
Re:NixOS on Framework Laptop by josephcsible on Monday October 18, 2021 @08:58AM (#28904944)
The key is how necessary the complexity is. The existence of simpler alternatives to systemd (that work just as well to run a system with) prove that its complexity is unnecessary. For things like Web browsers, the complexity is necessary, for better or worse.
Re:NixOS on Framework Laptop by rollcat on Monday October 18, 2021 @04:14AM (#28903266)
I'm trying to balance between idealism and pragmatism. Source access is pragmatic only in a situation where you feel confident to dive it. I admire projects like suckless, Alpine, or Netsurf, because they prove this kind of balance can be maintained. But I'm still posting this from Safari ;)
Re:NixOS on Framework Laptop by drran on Sunday October 17, 2021 @06:52PM (#28900486)
Good parts of SystemD are good, bad parts are bad. SystemD is easy to use when it fits your needs, but pain to use otherwise.

For example, `systemd-analyze` is a good tool for boot performance analysis, so + for systemd, but if I want/need to use perf for boot performance analysis, then systemd stands in my way, while for initd it's just yet another boot mode.

Re:NixOS on Framework Laptop by md8z on Sunday October 17, 2021 @08:17PM (#28900925)
What's the limitation stopping you from using perf in the same way as you would before? I've never had the need to try to do that.
Re:NixOS on Framework Laptop by josephcsible on Monday October 18, 2021 @08:56AM (#28904926)
Responding to "I don't like this" with "just learn it" is effectively saying "anyone who disagrees with me that this thing is awesome only does so because they know less than me." I'm very familiar with systemd, and I make use of its features on systems I can't avoid it on, but I still hate it.
Re:NixOS on Framework Laptop by daptaq on Monday October 18, 2021 @10:13AM (#28905611)
Can you recommend any links or literature to learn more about systemd, beyond the basics?
Re:NixOS on Framework Laptop by gigatexal on Sunday October 17, 2021 @05:49PM (#28900111)
Yeah no point in fighting it. It’s the standard. Learn to love SystemD.
Re:NixOS on Framework Laptop by mindslight on Sunday October 17, 2021 @06:46PM (#28900461)
NixOS is based on systemd. But it also seems like NixOS would be a great foundation to use something besides systemd. It would take some work of course, but it feels like you'd be mostly working with the OS rather than fighting it.

However having used it, NixOS seems like it mitigates the worst aspects of systemd. It gets rid of that that /etc/systemd /lib/systemd symlink "cleverness" for overriding/enabling units. Being functional makes it so that when systemd mysteriously breaks - for example if there is a loop in dependencies - it's easy to track down the change that caused it. And rather than splaying the config out in a bunch of random "unit" files, it's all contained in the nix config. About the worst thing I can say is that defining your own service is a bit more obtuse that it needs to be, with the arbitrary terms of the systemd unit format carrying over into the Nix config.

Re:NixOS on Framework Laptop by md8z on Sunday October 17, 2021 @08:40PM (#28901071)
The symlinking is one of the things systemd actually gets right on traditional distros. The files in /usr/lib are immutable data files shipped by the packages that you're not supposed to edit. The symlinks to them in /etc are configuration that you can change.
Re:NixOS on Framework Laptop by mindslight on Monday October 18, 2021 @01:35AM (#28902535)
I get the rationale. it just makes for one more layer of indirection that you have to overcome when trying to figure out what the configuration actually looks like.
Re:NixOS on Framework Laptop by md8z on Monday October 18, 2021 @02:51AM (#28902893)
Well I think you are supposed to just use systemctl to see what the configuration looks like.
Re:NixOS on Framework Laptop by 5e92cb50239222b on Monday October 18, 2021 @09:19AM (#28905142)
Why would you do this manually? You also have to remember to check multiple configuration paths (e.g. override units), all of which can have an additional `.d` include directory. This is the price you pay for the flexibility systemd provides (and I argue it's much better than random System V-style shell scripts that can include anything at all, maybe even some remote scripts piped from curl to sh if developers was mad enough).

Just use `systemctl cat`, it prints the whole effective configuration.

Re:NixOS on Framework Laptop by mindslight on Monday October 18, 2021 @10:38AM (#28905870)
Does `systemctl cat` also work for creating/editing units? If I've got to navigate files and directories configure the thing, then I am going to default to reading the configuration the same way. Having to find out these random commands to view simple things about its own internal model is one of the the worst parts of systemd.

I'm no fan of SysV init either, and I appreciate the advancements that systemd does bring to the table. But it is hard to shake the feeling of it having done the system software equivalent of sucking in a bunch of bloated javascript frameworks. Sure they made life easier for the developer, but everyone else has to live with the mess.

For enabling/sequencing, I'd say the preferable way would be to have a top level config file that pulls in the specified units explicitly rather than stitching together units based on their internal contents (akin to persistent structure rather than mutable cells). Juxtaposition is the most syntactically powerful operator and prevents loops intrinsically. Whereas by splaying dependencies in unit files, if you make one errant backreference the system is likely to not boot at all. I'm sure there's another clever command to check for that, but shrug.

Re:NixOS on Framework Laptop by nybble41 on Monday October 18, 2021 @02:37PM (#28909518)
> Does `systemctl cat` also work for creating/editing units?

No, for that you would use `systemctl edit UNIT...` to create or edit a drop-in file, e.g. to add local overrides for an existing service, or `systemctl edit --full UNIT...` to open a copy of the existing unit file for editing which will replace the packaged version. Add `--force` to create a new unit file for a service which doesn't already exist.

Re:NixOS on Framework Laptop by mindslight on Monday October 18, 2021 @03:09PM (#28910090)
I'm not surprised there is functionality like this, but I do question the value in learning it. After you've given up on the filesystem, you've got to figure out how to eg automate it. Some things you're forced to (virsh, crontab, etc), but that's not a selling point.

I've been doing fine on Debian dropping files in /etc/systemd, with a possible hook to `systemctl enable`. A rudimentary ad-hoc object system with overrides etc for every program is like the exact opposite of what I want when doing sysadmin. I think NixOS's approach does a good job of coping with systemd, in that it bundles all that complexity up in a way so it doesn't propagate, despite still having to look up what the Wants/Needs/Likes/Prayers/Requires/Binds designations mean every time I touch the config.

Re:NixOS on Framework Laptop by nybble41 on Monday October 18, 2021 @05:45PM (#28912202)
> I've been doing fine on Debian dropping files in /etc/systemd, with a possible hook to `systemctl enable`.

Don't forget `systemctl daemon-reload` to update the in-memory state when the unit files change. The `edit` command takes care of that for you. It also provides a template for the override files (when not using `--full`) which shows the current settings.

You are free to just drop files in /etc/systemd, of course. This is a fully-supported workflow. The `edit` command is only there for the convenience of the system administrator.

> A rudimentary ad-hoc object system with overrides etc for every program is like the exact opposite of what I want when doing sysadmin.

Are we talking about systemd, or NixOS? Their approaches to configuration really aren't all that different in this regard but you still seem to prefer one over the other. Or is the problem perhaps that you have two different programs trying to manage the configuration?

Personally, from the POV of distributions other than NixOS, I think the systemd approach is far superior to alternatives without overrides, where the only choice is to clone & modify the vendor-provided scripts. With overrides you can fine-tune the parts that matter for your environment without taking over the maintenance of the entire script (or unit file). For example, it's more likely to keep working after an upgrade.

Re:NixOS on Framework Laptop by mindslight on Monday October 18, 2021 @06:12PM (#28912485)
I was talking about systemd. It's each program having its own bespoke template/include/.d/override system that is the problem. Whereas NixOS is intended to be used for every program.

Personally I'd rather clone and modify a full config file rather than only overriding portions. Once I own it, I want to keep owning it - it's more straightforward to track down a problem due to my own assumptions being invalidated, than due to a distribution's assumptions being invalidated. And it's much nicer to read one file for the settings, than having to jump between a few different ones and know the overriding rules (referring to configuration in general here, not just systemd which provides the tools to work with them).

Good point about the daemon-reload. I actually don't have many custom systemd unit files, and they generally don't change. But to be fully correct and not require manual intervention or a full reboot I do need to include that step (although I'm moving away from Debian towards NixOS so shrug).

Re:NixOS on Framework Laptop by rnhmjoj on Monday October 18, 2021 @06:08AM (#28903872)
It is indeed possible, in fact a Nix-based project to generate and manage init/OS-agnostic services was shown last year at NixCon: https://github.com/svanderburg/nix-processmgmt
Re:NixOS on Framework Laptop by steve-chavez on Sunday October 17, 2021 @09:55PM (#28901503)
Not yet AFAICT. I've been following the nix-processmgmt[1] project, which looks it could make NixOS independent of the init system.

[1]: https://github.com/svanderburg/nix-processmgmt

Re:NixOS on Framework Laptop by mrobot on Sunday October 17, 2021 @10:25PM (#28901658)
This is great, thank you. I was gonna start on something like this myself, glad i did not duplicate effort with it yet.
Re:NixOS on Framework Laptop by Ericson2314 on Monday October 18, 2021 @12:24AM (#28902216)
I haven't bothered to have a beef with systemd, but some of us have discussed https://github.com/InitWare/InitWare to support non-Linux kernels. That would be really fun.
Re:NixOS on Framework Laptop by ayushnix on Monday October 18, 2021 @02:51AM (#28902890)
I doubt GuixSD would work on most modern hardware considering it uses the Linux-libre kernel. Using the Guix package manager itself sounds useful though.
Re:NixOS on Framework Laptop by rekado on Monday October 18, 2021 @07:23AM (#28904297)
Guix System works fine on modern hardware. I've been using it on new servers for the build farm at ci.guix.gnu.org and on laptops. Linux-libre has not been a problem.

The biggest recurring issue is with graphic cards that have poor support in Linux and require firmware blobs and with WiFi cards that have no free drivers / firmware.

It is trivial to use vanilla Linux with these machines as Guix System lets you use any other package for the `kernel` field in the configuration. The "nonguix" channel (hosted on Github) provides packages for vanilla Linux ("linux") in various versions, and also includes firmware packages that you can use in your config file.

If that's the only thing keeping you from using Guix System then I'm happy to say that it's a hurdle that is very easy to overcome.

Re:NixOS on Framework Laptop by ayushnix on Tuesday October 19, 2021 @06:48AM (#28916734)
> The biggest recurring issue is with graphic cards that have poor support in Linux and require firmware blobs and with WiFi cards that have no free drivers / firmware.

Intel, AMD, and Nvidia GPUS - all of them need firmware blobs to work as expected. Intel and AMD offer free drivers but not free firmware.

And if you want to WiFi 5 (ac) or WiFi 6 (ax), chances are that you'll need non-free drivers/firmware as well.

> The "nonguix" channel (hosted on Github) provides packages for vanilla Linux ("linux") in various versions, and also includes firmware packages that you can use in your config file.

Ah, that's good to know.

I'll probably give the Guix package manager a shot some day.

Re:NixOS on Framework Laptop by xyzzyz on Sunday October 17, 2021 @06:00PM (#28900190)
What would you prefer to have in Nix instead of systemd?
Re:NixOS on Framework Laptop by CameronNemo on Sunday October 17, 2021 @07:28PM (#28900668)
I've been running Upstart (well, a fork I maintain) for over 2 years on my laptops and SBC. I'd like to use that. TBH I think NixOS might make it easier than other distros to run a custom init. I just haven't gotten around to importing my configs into a nix derivation.
Re:NixOS on Framework Laptop by md8z on Sunday October 17, 2021 @08:29PM (#28900987)
If you have a parser for systemd unit files then you might have a chance to get that to work.

If the whole reason you're doing it is to migrate back to upstart's syntax then it seems that would be not so useful, you might as well go in the other direction: write an upstart generator for systemd, and then you can just plug that into ordinary NixOS.

Edit: Actually I think at some point NixOS did support upstart? Not sure whatever happened to that.

Re:NixOS on Framework Laptop by CameronNemo on Monday October 18, 2021 @01:29AM (#28902500)
I'm not planning on working on anything related to systemd in the near future. If anything, I will write a config generator/type spec for startup/Upstart in Nix.
Re:NixOS on Framework Laptop by md8z on Monday October 18, 2021 @01:57AM (#28902663)
Unfortunately I think you probably will have to work on it if you want to not break existing configurations, so maybe NixOS is not for you. You could try alpine possibly? But with that you will have to do the same with init.d, so it's going to be somewhat of an uphill battle either way I guess. This is generally why I would discourage maintaining a service manager outside of an established distro, I tried to do it for about the same amount of time as you and it became not worth it. Upstart in particular has been basically entirely replaced by systemd.
Re:NixOS on Framework Laptop by CameronNemo on Monday October 18, 2021 @02:15AM (#28902737)
I already use upstart on void no problem. Alpine would be a similar deal with me just managing the configs as raw text files via rsync. In fact my fork is already packaged in Alpine. A few people use it as a session manager for sway.

There is no chance that my Nix changes would affect existing configurations. They would be completely self contained.

Re:NixOS on Framework Laptop by md8z on Monday October 18, 2021 @02:43AM (#28902854)
I mean if you want to run existing configurations on your setup. Those aren't going to work. You can just install Nix on void though.

I had some users too but it still wasn't really worth it. I can't suggest it as a business model or a hobby project, you are basically going to be highly constrained by everything else on the system and your setup will just start looking like everything else eventually. Systemd also works fine as a session manager for whatever.

Re:NixOS on Framework Laptop by josephcsible on Monday October 18, 2021 @09:01AM (#28904973)
Literally any other init system. Maybe OpenRC, runit, or upstart? I'd even prefer to be stuck with sysvinit forever instead.
Re:NixOS on Framework Laptop by b9be520d93286 on Sunday October 17, 2021 @06:30PM (#28900375)
I would prefer OpenRC, runit or something similar.
Re:NixOS on Framework Laptop by md8z on Sunday October 17, 2021 @08:27PM (#28900979)
Those would probably be not so great matches for NixOS because they don't support the container stuff that systemd does, you would be throwing all that out.
Re:NixOS on Framework Laptop by CameronNemo on Sunday October 17, 2021 @10:45PM (#28901785)
Some people don't care. Some people want their boot ordering software and container runtime software to live in different code bases.
Re:NixOS on Framework Laptop by md8z on Sunday October 17, 2021 @10:55PM (#28901822)
With cgroupsv2 there seems to be very little benefit to doing that since the container runtime needs to sit at the top of the process tree anyway, so I'm not sure I understand what the purpose of that would be or why you would want that. If you were using containers to run services then I can't really think of a situation where you wouldn't also want it as part of the boot ordering process, so your services will just have it working immediately upon boot.
Re:NixOS on Framework Laptop by CameronNemo on Sunday October 17, 2021 @11:36PM (#28902006)
That is not true at all about cgroup2. Also think outside the box. Not everyone is using cgroups and namespaces. Some people are out there using gvisor, or KVM, or FreeBSD jails.
Re:NixOS on Framework Laptop by md8z on Sunday October 17, 2021 @11:56PM (#28902090)
I'm not sure what you mean it's not true, AFAIK that constraint was the main issue with getting Docker moved over to cgroupsv2. (Edit: some background here https://github.com/opencontainers/runc/pull/2113) It's fixed now though so everything should work fine with systemd. If you aren't using cgroups and namespaces then you probably don't get much benefit from running a system like NixOS on bare metal either, so I'm having trouble figuring out what your use case would be. Any other immutable Linux setup will do, it might even be less hassle.

Those other things you mention are confusing to me, gvisor and KVM are mostly orthogonal to container management. And FreeBSD jails don't work on Linux.

Re:NixOS on Framework Laptop by CameronNemo on Monday October 18, 2021 @01:15AM (#28902432)
Nix works on more than just linux.

Google Cloud uses gvisor for their K8s offering; AWS and Fly.io use firecracker for their container offerings.

Cgroups in v2 can be delegated easily and cleanly. As well as namespaced. Systemd or no systemd. Systemd just makes your life harder if you want to do rootless containers without integrating with them.

Re:NixOS on Framework Laptop by md8z on Monday October 18, 2021 @01:36AM (#28902543)
"Nix works on more than just linux."

IIRC the GP comment was asking about NixOS, not Nix. If you have everything already going through managed K8s or firecracker then I don't understand what you are using NixOS for. You could just install Nix on some other distribution that uses whatever init/container setup you want.

"Cgroups in v2 can be delegated easily and cleanly. As well as namespaced."

Right but none of those other things that were mentioned support cgroups delegation at an OS service level, only systemd does. Unless they have added this recently and I missed it. And if you're just using this to run a hypervisor then you're bypassing all that completely.

I don't see what you mean systemd makes it harder, you have to do basically the same process in any container manager if you want delegation. This is part of the design of cgroupsv2, it's not something systemd came up with. I'm sorry if I'm asking stupid questions but I honestly am really confused what your use case is, and your explanations are just making me more confused, so maybe something got lost here.

Re:NixOS on Framework Laptop by CameronNemo on Monday October 18, 2021 @02:12AM (#28902728)
I don't have a specific use case in mind. The possibilities are endless.

Delegating a cgroups doesn't take systemd, by the way. You can do it with mkdir().

Systemd puts user processes in a part of the cgroups tree where they can't work freely, by default. You have to use a systemd unit or the dbus api to break out of that box. That is a design decision on system's part. If I was putting user processes in cgroups, I would give them space to work amongst themselves.

Re:NixOS on Framework Laptop by md8z on Monday October 18, 2021 @02:25AM (#28902777)
Well you have to understand that my mental picture from your past description is FreeBSD running in KVM on NixOS running on managed GCP/AWS, which is a somewhat confusing and convoluted architecture to me and I'm not sure what it's for or what the possibilities are that can't be done with some other setup. You could probably simplify and cut out some of those pieces. But if you meant something else, then let me know.

AFAIK you actually should not be using mkdir, because it is racy to have more than one process writing to the toplevel hierarchy. It's only safe to do that from the cgroup manager. That's what I've seen with all the existing implementations anyway.

"Systemd puts user processes in a part of the cgroups tree where they can't work freely, by default. You have to use a systemd unit or the dbus api to break out of that box. That is a design decision on system's part."

It's a design decision that was made because of cgroupsv2. You should really read systemd's documentation on this if you haven't, it describes in detail why this is. https://systemd.io/CGROUP_DELEGATION/

Edit: and also the kernel documentation on delegation. https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2...

In particular, any other container manager that wants delegation needs to do this same thing using a similar mechanism that you initiate by configuring it somehow. (It doesn't have to be a unit file or dbus call obviously.) Processes cannot just freely break out of their cgroup, that wouldn't be secure. Sorry if you know all this already, maybe a reader doesn't. Or maybe this is helpful to you if you want to add this to startup, I don't know.

"If I was putting user processes in cgroups, I would give them space to work amongst themselves. "

Ok now you lost me again... is this not exactly the purpose of cgroup delegation?

Re:NixOS on Framework Laptop by CameronNemo on Monday October 18, 2021 @05:26AM (#28903648)
>it is racy to have more than one process writing to the toplevel hierarchy

Source? And define top level hierarchy? The top level isn't really special.

This is why locks exist btw.

I'm not convinced you have to manage cgroups from one process. That is not how most implementations do it.

>Processes cannot just freely break out of their cgroup, that wouldn't be secure.

Processes can freely migrate ("break out" if you insist on that terminology) if they have write access to one level above them in the tree. Systemd does not put you in that situation, but it could.

E.g. if you are in /user/<uid> you have nowhere to go, but if your are in /user/<uid>/default you can go to /user/<uid>/<container_runtime>/<unique_container_id>/default.

Re:NixOS on Framework Laptop by md8z on Monday October 18, 2021 @10:51AM (#28906007)
I'm sorry I don't understand what you're asking for specifically, the source is the cgroups API. Check the documentation I posted earlier, particularly this line:

"Because the resource control interface files in a given directory control the distribution of the parent’s resources, the delegatee shouldn’t be allowed to write to them."

You could add locking but that would be basically doing what systemd/docker/runc does and adding a new API on top of it which is then available through D-Bus or whatever. The top-level hierarchy is the top of any cgroup tree, if you have two processes writing to that without synchronization then they will potentially stomp over each other's values. You technically can go and run "sudo mkdir" inside your docker's toplevel cgroup but that would probably break things.

"if they have write access to one level above them in the tree. Systemd does not put you in that situation, but it could."

Well it does do that if you turn on delegation by giving you your own sub-tree, it doesn't do it by default because most services are not container managers and don't need an additional sub-tree. If you don't do that then write access is not allowed by the cgroups API, see above. It would not really make sense to allow a child process to say "I am going to take 100% of the cpu controller now and you get none sorry", that would defeat the purpose of cgroups.

Re:NixOS on Framework Laptop by CameronNemo on Monday October 18, 2021 @01:28PM (#28908081)
What have you worked on in this space?
Re:NixOS on Framework Laptop by md8z on Monday October 18, 2021 @04:48PM (#28911515)
I used to consult for this kind of thing several years ago, I don't any more. The field has really just coalesced around K8s. I don't think there is much space for innovation anymore.