This repository has no description
0

Configure Feed

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

superconfig / 3modules / folderPerms.nix
2.2 kB 107 lines
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8#TODO: implement recursive mode maybe? 9# enable different mods for files and folders 10 11let 12 inherit (pkgs) 13 writeScript 14 ; 15 16 inherit (lib) 17 concatMapStringsSep 18 concatStringsSep 19 mkEnableOption 20 mkIf 21 mkOption 22 types 23 ; 24 25 cfg = config.lass.folderPerms; 26 27 out = { 28 options.lass.folderPerms = api; 29 config = mkIf cfg.enable imp; 30 }; 31 32 api = { 33 enable = mkEnableOption "folder permissions"; 34 permissions = mkOption { 35 type = 36 with types; 37 listOf (submodule ({ 38 options = { 39 path = mkOption { 40 type = str; 41 }; 42 permission = mkOption { 43 type = nullOr str; 44 example = "755"; 45 description = '' 46 basically anything that chmod takes as permission 47 ''; 48 default = null; 49 }; 50 owner = mkOption { 51 type = nullOr str; 52 example = "root:root"; 53 description = '' 54 basically anything that chown takes as owner 55 ''; 56 default = null; 57 }; 58 }; 59 })); 60 }; 61 }; 62 63 imp = { 64 systemd.services.lass-folderPerms = { 65 description = "lass-folderPerms"; 66 wantedBy = [ "multi-user.target" ]; 67 68 path = with pkgs; [ 69 coreutils 70 ]; 71 72 restartIfChanged = true; 73 74 serviceConfig = { 75 type = "simple"; 76 RemainAfterExit = true; 77 Restart = "always"; 78 ExecStart = "@${startScript}"; 79 }; 80 }; 81 }; 82 83 startScript = writeScript "lass-folderPerms" '' 84 ${concatMapStringsSep "\n" writeCommand cfg.permissions} 85 ''; 86 87 writeCommand = 88 fperm: 89 concatStringsSep "\n" [ 90 (buildPermission fperm) 91 (buildOwner fperm) 92 ]; 93 94 buildPermission = 95 perm: 96 #TODO: create folder maybe 97 #TODO: check if permission is valid 98 if (perm.permission == null) then "" else "chmod ${perm.permission} ${perm.path}"; 99 100 buildOwner = 101 perm: 102 #TODO: create folder maybe 103 #TODO: check if owner/group valid 104 if (perm.owner == null) then "" else "chown ${perm.owner} ${perm.path}"; 105 106in 107out