nix: configure sharefs as a mount unit
Some checks failed
Test / Sandbox (push) Successful in 46s
Test / Create distribution (push) Successful in 43s
Test / Sandbox (race detector) (push) Successful in 46s
Test / Hpkg (push) Successful in 49s
Test / Hakurei (push) Successful in 54s
Test / Hakurei (race detector) (push) Successful in 54s
Test / ShareFS (push) Failing after 1m11s
Test / Flake checks (push) Has been skipped

This should have been configured via fileSystem instead, but that somehow has no effect, it is not even being evaluated, and I am not wasting any more time on nix. This change aims to keep everything working until all nix/systemd tooling is replaced.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-12-27 20:57:10 +09:00
parent ef1ebf12d9
commit 4862e8b74d
4 changed files with 50 additions and 25 deletions

View File

@@ -66,42 +66,56 @@ in
) "" cfg.users;
};
environment.systemPackages = optional (cfg.sharefs.source != null) cfg.sharefs.package;
systemd.services = {
sharefs = mkIf (cfg.sharefs.source != null) {
unitConfig.RequiresMountsFor = cfg.sharefs.source;
sharefs-setup = mkIf (cfg.sharefs.source != null) {
unitConfig.RequiresMountsFor = dirOf cfg.sharefs.source;
serviceConfig = {
NoNewPrivileges = true;
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
${pkgs.coreutils}/bin/install \
-dm0700 \
-o ${cfg.sharefs.user} \
-g ${cfg.sharefs.group} \
${cfg.sharefs.source} ${cfg.sharefs.name}
exec ${cfg.package}/libexec/sharefs -f \
-o ${
lib.join "," [
"noexec"
"nosuid"
"nodev"
"noatime"
"auto_unmount"
"allow_other"
"setuid=$(id -u ${cfg.sharefs.user})"
"setgid=$(id -g ${cfg.sharefs.group})"
"source=${cfg.sharefs.source}"
]
} ${cfg.sharefs.name}
${cfg.sharefs.source}
'';
# do not unmount on configuration changes
restartIfChanged = false;
wantedBy = [ "multi-user.target" ];
wantedBy = [ "local-fs.target" ];
};
};
systemd.mounts = optional (cfg.sharefs.source != null) {
unitConfig.RequiresMountsFor = cfg.sharefs.source;
where = cfg.sharefs.name;
what = "sharefs";
type = "fuse.sharefs";
options = lib.join "," [
"noexec"
"nosuid"
"nodev"
"noatime"
"auto_unmount"
"allow_other"
"setuid=${toString config.users.users.${cfg.sharefs.user}.uid}"
"setgid=${toString config.users.groups.${cfg.sharefs.group}.gid}"
"source=${cfg.sharefs.source}"
];
wants = [ "sharefs-setup.service" ];
after = [ "sharefs-setup.service" ];
before = [
"local-fs.target"
"multi-user.target"
"nix-daemon.socket"
];
wantedBy = [
"local-fs.target"
"multi-user.target"
"nix-daemon.socket"
];
};
home-manager =
let
privPackages = mapAttrs (_: userid: {