Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 89 lines 3.2 kB view raw
1{ 2 lib, 3 symlinkJoin, 4 runCommand, 5 unwrapped, 6 python3, 7 formats, 8}: 9 10let 11 wrapper = 12 { 13 pythonPackages ? (_: [ ]), 14 plugins ? (_: [ ]), 15 baseConfig ? null, 16 }: 17 let 18 plugins' = plugins unwrapped.plugins; 19 extraPythonPackages = builtins.concatLists (map (p: p.propagatedBuildInputs or [ ]) plugins'); 20 in 21 symlinkJoin { 22 name = "${unwrapped.pname}-with-plugins-${unwrapped.version}"; 23 24 inherit unwrapped; 25 paths = lib.optional (baseConfig != null) unwrapped ++ plugins'; 26 pythonPath = 27 lib.optional (baseConfig == null) unwrapped ++ pythonPackages python3.pkgs ++ extraPythonPackages; 28 29 nativeBuildInputs = [ python3.pkgs.wrapPython ]; 30 31 postBuild = '' 32 rm -f $out/nix-support/propagated-build-inputs 33 rmdir $out/nix-support || true 34 ${lib.optionalString (baseConfig != null) '' 35 rm $out/${python3.sitePackages}/maubot/example-config.yaml 36 substituteAll ${ 37 (formats.yaml { }).generate "example-config.yaml" ( 38 lib.recursiveUpdate baseConfig { 39 plugin_directories = lib.optionalAttrs (plugins' != [ ]) { 40 load = [ "@out@/lib/maubot-plugins" ] ++ (baseConfig.plugin_directories.load or [ ]); 41 }; 42 # Normally it should be set to false by default to take it from package 43 # root, but aiohttp doesn't follow symlinks when serving static files 44 # unless follow_symlinks=True is passed. Instead of patching maubot, use 45 # this non-invasive approach 46 # XXX: would patching maubot be better? See: 47 # https://github.com/maubot/maubot/blob/75879cfb9370aade6fa0e84e1dde47222625139a/maubot/server.py#L106 48 server.override_resource_path = 49 if builtins.isNull (baseConfig.server.override_resource_path or null) then 50 "${unwrapped}/${python3.sitePackages}/maubot/management/frontend/build" 51 else 52 baseConfig.server.override_resource_path; 53 } 54 ) 55 } $out/${python3.sitePackages}/maubot/example-config.yaml 56 rm -rf $out/bin 57 ''} 58 mkdir -p $out/bin 59 cp $unwrapped/bin/.mbc-wrapped $out/bin/mbc 60 cp $unwrapped/bin/.maubot-wrapped $out/bin/maubot 61 wrapPythonProgramsIn "$out/bin" "${lib.optionalString (baseConfig != null) "$out "}$pythonPath" 62 ''; 63 64 passthru = { 65 inherit unwrapped; 66 python = python3; 67 withPythonPackages = 68 filter: 69 wrapper { 70 pythonPackages = pkgs: pythonPackages pkgs ++ filter pkgs; 71 inherit plugins baseConfig; 72 }; 73 withPlugins = 74 filter: 75 wrapper { 76 plugins = pkgs: plugins pkgs ++ filter pkgs; 77 inherit pythonPackages baseConfig; 78 }; 79 withBaseConfig = 80 baseConfig: 81 wrapper { 82 inherit baseConfig pythonPackages plugins; 83 }; 84 }; 85 86 meta.priority = (unwrapped.meta.priority or lib.meta.defaultPriority) - 1; 87 }; 88in 89wrapper