瀏覽代碼

feat(odin): storage mount permissions

Zander Hawke 9 月之前
父節點
當前提交
3f9a03499e
共有 1 個文件被更改,包括 26 次插入4 次删除
  1. 26 4
      hosts/odin/mergerfs.nix

+ 26 - 4
hosts/odin/mergerfs.nix

@@ -1,10 +1,15 @@
-{ pkgs, ... }:
+{ config
+, pkgs
+, ...
+}:
 {
   environment.systemPackages = with pkgs; [
     mergerfs
     mergerfs-tools
   ];
 
+  users.groups.storage.gid = 992;
+
   fileSystems."/mnt/storage" = {
     device = "/mnt/data*";
     options = [
@@ -16,10 +21,27 @@
       "minfreespace=25G"
       "func.getattr=newest"
       "fsname=storage"
-      "uid=1000"
-      "gid=1000"
-      "umask=002"
+      "gid=${toString config.users.groups.storage.gid}"
     ];
     fsType = "fuse.mergerfs";
   };
+
+  systemd.services."chown-storage" = {
+    description = "Ensure correct group ownership on the storage pool";
+
+    wantedBy = [ "local-fs.target" ];
+    after = [ "local-fs.target" ];
+
+    script = ''
+      ${pkgs.coreutils}/bin/chown -R :storage /mnt/data*
+      ${pkgs.coreutils}/bin/chmod -R 0775 /mnt/data*
+      ${pkgs.coreutils}/bin/chown -R :storage /mnt/parity*
+      ${pkgs.coreutils}/bin/chmod -R 0775 /mnt/parity*
+    '';
+
+    serviceConfig = {
+      Type = "oneshot";
+      RemainAfterExit = "yes";
+    };
+  };
 }