Personal-use NixOS configuration
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Create NFS share generator function

encode42 f844f056 cbe3e5bf

+141 -62
+16 -11
hosts/index/config/media/emby.nix
··· 1 - { flakeRoot, ... }: 1 + { flakeRoot, config, ... }: 2 2 3 3 let 4 4 embyModule = import (flakeRoot + /packages/server/media/emby.nix) { 5 5 hosts = [ 6 - { 7 - name = "emby.lan"; 8 - ssl = "internal"; 9 - } 10 - { 11 - name = "watch.encrypted.group"; 12 - ssl = "cloudflare"; 6 + { 7 + name = "emby.lan"; 8 + ssl = "internal"; 9 + } 10 + { 11 + name = "watch.encrypted.group"; 12 + ssl = "cloudflare"; 13 13 14 - useLocal = true; 15 - } 16 - ]; 14 + useLocal = true; 15 + } 16 + ]; 17 17 }; 18 + 19 + service = config.services.emby; 18 20 in 19 21 { 20 22 imports = [ ··· 24 26 services.emby = { 25 27 dataDir = "/mnt/apps/emby"; 26 28 }; 29 + 30 + users.users.${service.user}.uid = 968; 31 + users.groups.${service.group}.gid = 965; 27 32 }
+6 -1
hosts/index/config/media/navidrome.nix
··· 1 - { flakeRoot, ... }: 1 + { flakeRoot, config, ... }: 2 2 3 3 let 4 4 navidromeModule = import (flakeRoot + /packages/server/media/navidrome.nix) { ··· 15 15 } 16 16 ]; 17 17 }; 18 + 19 + service = config.services.navidrome; 18 20 in 19 21 { 20 22 imports = [ ··· 29 31 30 32 environmentFile = "/mnt/apps/navidrome/navidrome.env"; 31 33 }; 34 + 35 + users.users.${service.user}.uid = 991; 36 + users.groups.${service.user}.gid = 974; 32 37 }
+48 -49
hosts/index/config/nfs.nix
··· 1 - { flakeRoot, ... }: 1 + { 2 + flakeRoot, 3 + flakeLib, 4 + config, 5 + ... 6 + }: 7 + 8 + let 9 + mediaGroupName = config.users.groups.media.name; 2 10 3 - { 4 - imports = [ 5 - (flakeRoot + /modules/server/filesystem/nfs.nix) 11 + embySharePaths = [ 12 + "Documentaries" 13 + "Live Performances" 14 + "Movies" 15 + "Music Videos" 16 + "Shows" 6 17 ]; 7 18 8 - services.nfs.server = { 9 - nproc = 16; 10 - }; 19 + embyShares = map (path: { 20 + path = "/mnt/data/media/${path}"; 11 21 12 - # TODO: Write a function that can improve this 22 + userName = config.services.emby.user; 23 + groupName = mediaGroupName; 24 + }) embySharePaths; 13 25 14 - fileSystems."/export/media" = { 15 - depends = [ 16 - "/mnt/data" 17 - ]; 26 + shares = [ 27 + { 28 + name = "torrents"; 18 29 19 - device = "/mnt/data/media"; 20 - fsType = "none"; 30 + path = "/mnt/data/rtorrent/downloads"; 21 31 22 - options = [ 23 - "bind" 24 - "x-systemd.requires=zfs-mount.service" 25 - ]; 26 - }; 32 + userName = config.services.rtorrent.user; 33 + groupName = mediaGroupName; 34 + } 35 + { 36 + name = "soulseek"; 27 37 28 - fileSystems."/export/torrents" = { 29 - depends = [ 30 - "/mnt/data" 31 - ]; 38 + path = "/mnt/data/soulseek/downloads"; 32 39 33 - device = "/mnt/data/rtorrent/downloads"; 34 - fsType = "none"; 35 - 36 - options = [ 37 - "bind" 38 - "x-systemd.requires=zfs-mount.service" 39 - ]; 40 - }; 40 + userName = config.services.slskd.user; 41 + groupName = mediaGroupName; 42 + } 43 + { 44 + path = "/mnt/data/media/Music"; 41 45 42 - fileSystems."/export/soulseek" = { 43 - depends = [ 44 - "/mnt/data" 45 - ]; 46 + userName = config.services.navidrome.user; 47 + groupName = mediaGroupName; 48 + } 49 + ] 50 + ++ embyShares; 51 + in 52 + { 53 + imports = [ 54 + (flakeRoot + /modules/server/filesystem/nfs.nix) 46 55 47 - device = "/mnt/data/soulseek/downloads"; 48 - fsType = "none"; 56 + (flakeLib.mkShares shares) 57 + ]; 49 58 50 - options = [ 51 - "bind" 52 - "x-systemd.requires=zfs-mount.service" 53 - ]; 59 + services.nfs.server = { 60 + nproc = 16; 54 61 }; 55 - 56 - # TODO: Automatically grab user and group IDs? 57 - services.nfs.server.exports = '' 58 - /export *(fsid=0,ro,insecure) 59 - /export/media *(rw,insecure,async,no_subtree_check,nohide,all_squash,anonuid=991,anongid=442) 60 - /export/torrents *(rw,insecure,async,no_subtree_check,nohide,all_squash,anonuid=987,anongid=972) 61 - /export/soulseek *(rw,insecure,async,no_subtree_check,nohide,all_squash,anonuid=985,anongid=973) 62 - ''; 63 62 }
+6
hosts/index/config/sharing/rtorrent.nix
··· 1 1 { 2 2 flakeRoot, 3 3 lib, 4 + config, 4 5 ... 5 6 }: 6 7 ··· 34 35 } 35 36 ]; 36 37 }; 38 + 39 + service = config.services.rtorrent; 37 40 in 38 41 { 39 42 imports = [ ··· 69 72 70 73 vpnNamespace = interface; 71 74 }; 75 + 76 + users.users.${service.user}.uid = 987; 77 + users.groups.${service.group}.gid = 972; 72 78 }
+9 -1
hosts/index/config/sharing/soulseek.nix
··· 13 13 } 14 14 ]; 15 15 }; 16 + 17 + service = config.services.slskd; 16 18 in 17 19 { 18 20 imports = [ ··· 64 66 vpnNamespace = interface; 65 67 }; 66 68 67 - users.users.${config.services.slskd.user}.extraGroups = [ "media" ]; 69 + users.users.${service.user} = { 70 + uid = 985; 71 + 72 + extraGroups = [ "media" ]; 73 + }; 74 + 75 + users.groups.${service.group}.gid = 973; 68 76 }
+1
lib/default.nix
··· 10 10 }; 11 11 12 12 mkProxies = import ./mkProxies.nix { inherit lib; }; 13 + mkShares = import ./mkShares.nix { inherit lib; }; 13 14 mkUserIcon = import ./mkUserIcon.nix; 14 15 }
+55
lib/mkShares.nix
··· 1 + { lib }: 2 + 3 + # targets: 4 + # [ { name = str?; path = str; userName = str; groupName = str?; } ]; 5 + targets: 6 + 7 + { config, ... }: 8 + 9 + let 10 + extraNfsExports = '' 11 + /export *(fsid=0,ro,insecure) 12 + ''; 13 + 14 + mkShare = 15 + target: 16 + let 17 + directories = lib.filter (x: x != "") (lib.splitString "/" target.path); 18 + 19 + exportPath = "/exports/${target.name or (lib.last directories)}"; 20 + 21 + mountName = builtins.elemAt directories 1; 22 + isZfsPool = lib.elem mountName config.boot.zfs.extraPools; 23 + 24 + user = config.users.users.${target.userName}; 25 + group = config.users.groups.${target.groupName or user.group}; 26 + in 27 + { 28 + inherit exportPath; 29 + 30 + fileSystemMount = { 31 + device = target.path; 32 + fsType = "none"; 33 + 34 + depends = lib.optionals isZfsPool [ "/mnt/${mountName}" ]; 35 + options = [ "bind" ] ++ lib.optionals isZfsPool [ "x-systemd.requires=zfs-mount.service" ]; 36 + }; 37 + 38 + nfsExport = '' 39 + "${exportPath}\" *(rw,insecure,async,no_subtree_check,nohide,all_squash,anonuid=${toString user.uid},anongid=${toString group.gid}) 40 + ''; 41 + }; 42 + 43 + shares = map mkShare targets; 44 + in 45 + { 46 + fileSystems = builtins.listToAttrs ( 47 + map (share: { 48 + name = share.exportPath; 49 + value = share.fileSystemMount; 50 + }) shares 51 + ); 52 + 53 + services.nfs.server.exports = 54 + extraNfsExports + lib.concatStringsSep "\n" (map (share: share.nfsExport) shares); 55 + }