forked from jan-leila/nix-config
		
	added syncthing
This commit is contained in:
		
							parent
							
								
									21eea779db
								
							
						
					
					
						commit
						905c4e73b2
					
				
					 5 changed files with 119 additions and 2 deletions
				
			
		|  | @ -8,6 +8,7 @@ | |||
|     ./desktop.nix | ||||
|     ./ssh.nix | ||||
|     ./i18n.nix | ||||
|     ./sync.nix | ||||
|     ./impermanence.nix | ||||
|     ./disko.nix | ||||
|     ./server | ||||
|  |  | |||
							
								
								
									
										87
									
								
								modules/nixos-modules/sync.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								modules/nixos-modules/sync.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,87 @@ | |||
| { | ||||
|   config, | ||||
|   lib, | ||||
|   ... | ||||
| }: let | ||||
|   mountDir = "/mnt/sync"; | ||||
| in { | ||||
|   options.host.sync = { | ||||
|     enable = lib.mkEnableOption "should sync thing be enabled on this device"; | ||||
|     folders = { | ||||
|       leyla = { | ||||
|         documents = { | ||||
|           enable = lib.mkEnableOption "should the documents folder be synced"; | ||||
|         }; | ||||
|         calendar = { | ||||
|           enable = lib.mkEnableOption "should the calendar folder be synced"; | ||||
|         }; | ||||
|         notes = { | ||||
|           enable = lib.mkEnableOption "should the notes folder by synced"; | ||||
|         }; | ||||
|       }; | ||||
|       extraFolders = lib.mkOption { | ||||
|         type = lib.types.attrsOf (lib.types.submodule ({...}: { | ||||
|           options = { | ||||
|             path = lib.mkOption { | ||||
|               type = lib.types.str; | ||||
|             }; | ||||
|             devices = lib.mkOption { | ||||
|               type = lib.types.listof lib.types.str; | ||||
|             }; | ||||
|           }; | ||||
|         })); | ||||
|         default = {}; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
| 
 | ||||
|   config = { | ||||
|     systemd = lib.mkIf config.services.syncthing.enable { | ||||
|       tmpfiles.rules = [ | ||||
|         "d ${mountDir} 755 syncthing syncthing -" | ||||
|         "d ${config.services.syncthing.dataDir} 755 syncthing syncthing -" | ||||
|         "d ${config.services.syncthing.configDir} 755 syncthing syncthing -" | ||||
|       ]; | ||||
|     }; | ||||
|     services.syncthing = { | ||||
|       enable = config.host.sync.enable; | ||||
|       user = "syncthing"; | ||||
|       group = "syncthing"; | ||||
|       dataDir = "${mountDir}/default"; | ||||
|       configDir = "/etc/syncthing"; | ||||
|       overrideDevices = true; | ||||
|       overrideFolders = true; | ||||
|       settings = { | ||||
|         devices = { | ||||
|           ceder = { | ||||
|             id = "MGXUJBS-7AENXHB-7YQRNWG-QILKEJD-5462U2E-WAQW4R4-I2TVK5H-SMK6LAA"; | ||||
|           }; | ||||
|         }; | ||||
|         folders = lib.mkMerge [ | ||||
|           config.host.sync.folders.extraFolders | ||||
|           (lib.mkIf config.host.sync.folders.leyla.documents.enable { | ||||
|             "documents" = { | ||||
|               id = "hvrj0-9bm1p"; | ||||
|               path = "/mnt/sync/leyla/documents"; | ||||
|               devices = ["ceder"]; | ||||
|             }; | ||||
|           }) | ||||
|           (lib.mkIf config.host.sync.folders.leyla.calendar.enable { | ||||
|             "calendar" = { | ||||
|               id = "8oatl-1rv6w"; | ||||
|               path = "/mnt/sync/leyla/calendar"; | ||||
|               devices = ["ceder"]; | ||||
|             }; | ||||
|           }) | ||||
|           (lib.mkIf config.host.sync.folders.leyla.notes.enable { | ||||
|             "notes" = { | ||||
|               id = "dwbuv-zffnf"; | ||||
|               path = "/mnt/sync/leyla/notes"; | ||||
|               devices = ["ceder"]; | ||||
|             }; | ||||
|           }) | ||||
|         ]; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
| } | ||||
|  | @ -22,6 +22,7 @@ | |||
|     hass = 2004; | ||||
|     headscale = 2005; | ||||
|     nextcloud = 2006; | ||||
|     syncthing = 2007; | ||||
|   }; | ||||
| 
 | ||||
|   gids = { | ||||
|  | @ -36,6 +37,7 @@ | |||
|     hass = 2004; | ||||
|     headscale = 2005; | ||||
|     nextcloud = 2006; | ||||
|     syncthing = 2007; | ||||
|   }; | ||||
| 
 | ||||
|   users = config.users.users; | ||||
|  | @ -160,6 +162,12 @@ in { | |||
|             isSystemUser = true; | ||||
|             group = config.users.users.nextcloud.name; | ||||
|           }; | ||||
| 
 | ||||
|           syncthing = { | ||||
|             uid = lib.mkForce uids.syncthing; | ||||
|             isSystemUser = true; | ||||
|             group = config.users.users.syncthing.name; | ||||
|           }; | ||||
|         }; | ||||
| 
 | ||||
|         groups = { | ||||
|  | @ -250,6 +258,16 @@ in { | |||
|               # leyla | ||||
|             ]; | ||||
|           }; | ||||
| 
 | ||||
|           syncthing = { | ||||
|             gid = lib.mkForce gids.syncthing; | ||||
|             members = [ | ||||
|               users.syncthing.name | ||||
|               leyla | ||||
|               ester | ||||
|               eve | ||||
|             ]; | ||||
|           }; | ||||
|         }; | ||||
|       }; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue