NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.65k stars 13.8k forks source link

Support for ZFS Systemd Mount generator #62644

Open Echaleon opened 5 years ago

Echaleon commented 5 years ago

Recently, support for a systemd mount generator landed in ZFS stable, and support for it is present in both 0.7.13 and 0.8.0. It's fairly simple to use, and works successfully on Arch, though it doesn't (yet) support encrypted datasets, though it's fairly easy to write your own unit file.

The benefit of this is that it allows the use of native ZFS mountpoints, streamlining administration. Using it is fairly simple, with just a few lines of code: https://zfsonlinux.org/manpages/0.7.13/man8/zfs-mount-generator.8.html

Relevant issues and merge requests: https://github.com/zfsonlinux/zfs/pull/7329 https://github.com/zfsonlinux/zfs/issues/8750 https://github.com/zfsonlinux/zfs/pull/8848

I've used this on Arch and it works wonderfully. I would try and do the integration myself, but my nix skills are not up to par yet.

ElvishJerricco commented 5 years ago

We would need to make sure file systems mounted this way aren't present in /etc/fstab. Not sure what the right way to do that would be, considering the file systems will be in hardware-configuration.nix.

stale[bot] commented 4 years ago

Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on irc.freenode.net.
emilazy commented 3 years ago

not stale

ghost commented 1 year ago

I'm maintaining the Alpine, Fedora, RHEL (Alma), Arch Linux and NixOS Root on ZFS guides. The systemd mount point generator causes a lot of headaches. Use legacy mount point with fileSystems if possible.

ElvishJerricco commented 1 year ago

The systemd mount point generator causes a lot of headaches.

I've been using the mount generator for like a year and a half on one of my systems and have had no troubles.

Especially with NixOS, we want the system root to be empty and stateless

Ideally, all system configuration should be only managed by NixOS

I think this is not exactly accurate. For a stateless system, sure, I guess. But for many use cases, file systems are a part of the inherently stateful problems that they're trying to solve. And to that end, I think it's reasonable in many cases to want to keep stateful things out of the Nix config, particularly so that the system can be rolled back or rebuilt with minimal concern for the state of the disks. So wanting file systems to be defined with non-legacy mountpoints, and/or with gpt-auto-generator, or whatever else, outside of the Nix config, seems like a valid use case that it would be nice to support.

TL;DR: I really don't think it's ok for us to just blanket tell people they should only use legacy mountpoints. There's plenty of reasons you might not want to.

gkleen commented 1 year ago

@ElvishJerricco

I've been using the mount generator for like a year and a half on one of my systems and have had no troubles.

Are you using it on a NixOS system?
I'd be interested in taking a look at the configuration if you'd be willing to share it.

ElvishJerricco commented 1 year ago

@gkleen This is what I have.

  systemd.generators."zfs-mount-generator" = "${config.boot.zfs.package}/lib/systemd/system-generator/zfs-mount-generator";
  environment.etc."zfs/zed.d/history_event-zfs-list-cacher.sh".source = "${config.boot.zfs.package}/etc/zfs/zed.d/history_event-zfs-list-cacher.sh";
  systemd.services.zfs-mount.enable = false;

  services.zfs.zed.settings.PATH = lib.mkForce (lib.makeBinPath [
    pkgs.diffutils
    config.boot.zfs.package
    pkgs.coreutils
    pkgs.curl
    pkgs.gawk
    pkgs.gnugrep
    pkgs.gnused
    pkgs.nettools
    pkgs.util-linux
  ]);

It basically just enables the generator and disables zfs-mount.service. Then it needs diffutils added to the zed.settings.PATH, but that option doesn't properly append different definitions so I had to mkForce it and copy the nixpkgs default for it.

I copied it from someone else, but unfortunately I can't remember who :P

ConnorBaker commented 1 year ago

@ElvishJerricco thank you for sharing that; I was running into similar problems discussed in this thread but using that snippet fixed things for me. I no longer need to specify boot.zfs.forceImportAll!