diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-12-27 22:52:12 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-12-27 23:14:08 +0900 |
| commit | e42ea32dbe9283d14a7c0e8746059bc5ef97f6cd (patch) | |
| tree | 9ddc8d4bb6438d00a8e04b1cdf07df5e3570f7eb /nixos.nix | |
| parent | e7982b4ee9cc935d6b89f291087524cdee229d09 (diff) | |
nix: configure sharefs via fileSystems
Turns out this did not work because in the vm test harness, virtualisation.fileSystems completely and silently overrides fileSystems, causing its contents to not even be evaluated anymore. This is not documented as far as I can tell, and is not obvious by any stretch of the imagination. The current hack is cargo culted from nix-community/impermanence and hopefully lasts until this project fully replaces nix.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'nixos.nix')
| -rw-r--r-- | nixos.nix | 62 |
1 files changed, 30 insertions, 32 deletions
@@ -24,11 +24,38 @@ let getsubuid = userid: appid: userid * 100000 + 10000 + appid; getsubname = userid: appid: "u${toString userid}_a${toString appid}"; getsubhome = userid: appid: "${cfg.stateDir}/u${toString userid}/a${toString appid}"; + + mountpoints = { + ${cfg.sharefs.name} = mkIf (cfg.sharefs.source != null) { + depends = [ cfg.sharefs.source ]; + device = "sharefs"; + fsType = "fuse.sharefs"; + noCheck = true; + options = [ + "rw" + "noexec" + "nosuid" + "nodev" + "noatime" + "allow_other" + "mkdir" + "source=${cfg.sharefs.source}" + "setuid=${toString config.users.users.${cfg.sharefs.user}.uid}" + "setgid=${toString config.users.groups.${cfg.sharefs.group}.gid}" + ]; + }; + }; in { imports = [ (import ./options.nix packages) ]; + options = { + # Forward declare a dummy option for VM filesystems since the real one won't exist + # unless the VM module is actually imported. + virtualisation.fileSystems = lib.mkOption { }; + }; + config = mkIf cfg.enable { assertions = [ ( @@ -66,38 +93,9 @@ in ) "" cfg.users; }; - systemd.services = { - sharefs = mkIf (cfg.sharefs.source != null) { - unitConfig.RequiresMountsFor = cfg.sharefs.source; - serviceConfig = { - NoNewPrivileges = true; - }; - script = '' - ${pkgs.coreutils}/bin/install -dm0 ${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}" - "mkdir" - ] - } ${cfg.sharefs.name} - ''; - - # do not unmount on configuration changes - restartIfChanged = false; - - wantedBy = [ "multi-user.target" ]; - }; - }; + environment.systemPackages = optional (cfg.sharefs.source != null) cfg.sharefs.package; + fileSystems = mountpoints; + virtualisation.fileSystems = mountpoints; home-manager = let |
