···74747575#### `buildPythonPackage` function {#buildpythonpackage-function}
76767777-The `buildPythonPackage` function is implemented in
7878-`pkgs/development/interpreters/python/mk-python-derivation.nix`
7777+The `buildPythonPackage` function has its name binding in
7878+`pkgs/development/interpreters/python/python-packages-base.nix` and is
7979+implemented in `pkgs/development/interpreters/python/mk-python-derivation.nix`
7980using setup hooks.
80818182The following is an example:
···85858686- [ollama](https://ollama.ai), server for running large language models locally.
87878888+- [Mihomo](https://github.com/MetaCubeX/mihomo), a rule-based proxy in Go. Available as [services.mihomo.enable](#opt-services.mihomo.enable).
8989+8890- [hebbot](https://github.com/haecker-felix/hebbot), a Matrix bot to generate "This Week in X" like blog posts. Available as [services.hebbot](#opt-services.hebbot.enable).
89919092- [Python Matter Server](https://github.com/home-assistant-libs/python-matter-server), a
+59-26
nixos/modules/image/repart-image.nix
···22# NixOS module that can be imported.
3344{ lib
55+, stdenvNoCC
56, runCommand
66-, runCommandLocal
77, python3
88, black
99, ruff
···2626, xz
27272828 # arguments
2929+, name
3030+, version
2931, imageFileBasename
3032, compression
3133, fileSystems
3232-, partitions
3434+, partitionsJSON
3335, split
3436, seed
3537, definitionsDirectory
3638, sectorSize
3739, mkfsEnv ? {}
4040+, createEmpty ? true
3841}:
39424043let
···5255 mypy --strict $out
5356 '';
54575555- amendedRepartDefinitions = runCommandLocal "amended-repart.d" {} ''
5656- definitions=$(${amendRepartDefinitions} ${partitions} ${definitionsDirectory})
5757- cp -r $definitions $out
5858- '';
5959-6058 fileSystemToolMapping = {
6159 "vfat" = [ dosfstools mtools ];
6260 "ext4" = [ e2fsprogs.bin ];
···7876 "xz" = "xz --keep --verbose --threads=0 -${toString compression.level}";
7977 }."${compression.algorithm}";
8078in
8181-8282-runCommand imageFileBasename
8383-{
7979+ stdenvNoCC.mkDerivation (finalAttrs:
8080+ (if (version != null)
8181+ then { pname = name; inherit version; }
8282+ else { inherit name; }
8383+ ) // {
8484 __structuredAttrs = true;
85858686 nativeBuildInputs = [
8787 systemd
8888 fakeroot
8989 util-linux
9090+ ] ++ lib.optionals (compression.enable) [
9091 compressionPkg
9192 ] ++ fileSystemTools;
92939394 env = mkfsEnv;
94959696+ inherit partitionsJSON definitionsDirectory;
9797+9898+ # relative path to the repart definitions that are read by systemd-repart
9999+ finalRepartDefinitions = "repart.d";
100100+95101 systemdRepartFlags = [
96102 "--dry-run=no"
9797- "--empty=create"
98103 "--size=auto"
99104 "--seed=${seed}"
100100- "--definitions=${amendedRepartDefinitions}"
105105+ "--definitions=${finalAttrs.finalRepartDefinitions}"
101106 "--split=${lib.boolToString split}"
102107 "--json=pretty"
108108+ ] ++ lib.optionals createEmpty [
109109+ "--empty=create"
103110 ] ++ lib.optionals (sectorSize != null) [
104111 "--sector-size=${toString sectorSize}"
105112 ];
106113107107- passthru = {
108108- inherit amendRepartDefinitions amendedRepartDefinitions;
109109- };
110110-} ''
111111- mkdir -p $out
112112- cd $out
114114+ dontUnpack = true;
115115+ dontConfigure = true;
116116+ doCheck = false;
117117+118118+ patchPhase = ''
119119+ runHook prePatch
120120+121121+ amendedRepartDefinitionsDir=$(${amendRepartDefinitions} $partitionsJSON $definitionsDirectory)
122122+ ln -vs $amendedRepartDefinitionsDir $finalRepartDefinitions
123123+124124+ runHook postPatch
125125+ '';
126126+127127+ buildPhase = ''
128128+ runHook preBuild
113129114114- echo "Building image with systemd-repart..."
115115- unshare --map-root-user fakeroot systemd-repart \
116116- ''${systemdRepartFlags[@]} \
117117- ${imageFileBasename}.raw \
118118- | tee repart-output.json
130130+ echo "Building image with systemd-repart..."
131131+ unshare --map-root-user fakeroot systemd-repart \
132132+ ''${systemdRepartFlags[@]} \
133133+ ${imageFileBasename}.raw \
134134+ | tee repart-output.json
119135136136+ runHook postBuild
137137+ '';
138138+139139+ installPhase = ''
140140+ runHook preInstall
141141+142142+ mkdir -p $out
143143+ ''
120144 # Compression is implemented in the same derivation as opposed to in a
121145 # separate derivation to allow users to save disk space. Disk images are
122146 # already very space intensive so we want to allow users to mitigate this.
123123- if ${lib.boolToString compression.enable}; then
147147+ + lib.optionalString compression.enable
148148+ ''
124149 for f in ${imageFileBasename}*; do
125150 echo "Compressing $f with ${compression.algorithm}..."
126151 # Keep the original file when compressing and only delete it afterwards
127152 ${compressionCommand} $f && rm $f
128153 done
129129- fi
130130-''
154154+ '' + ''
155155+ mv -v repart-output.json ${imageFileBasename}* $out
156156+157157+ runHook postInstall
158158+ '';
159159+160160+ passthru = {
161161+ inherit amendRepartDefinitions;
162162+ };
163163+})
+26-16
nixos/modules/image/repart.nix
···211211 '';
212212 };
213213214214+ finalPartitions = lib.mkOption {
215215+ type = lib.types.attrs;
216216+ internal = true;
217217+ readOnly = true;
218218+ description = lib.mdDoc ''
219219+ Convenience option to access partitions with added closures.
220220+ '';
221221+ };
222222+214223 };
215224216225 config = {
···224233 "zstd" = ".zst";
225234 "xz" = ".xz";
226235 }."${cfg.compression.algorithm}";
236236+237237+ makeClosure = paths: pkgs.closureInfo { rootPaths = paths; };
238238+239239+ # Add the closure of the provided Nix store paths to cfg.partitions so
240240+ # that amend-repart-definitions.py can read it.
241241+ addClosure = _name: partitionConfig: partitionConfig // (
242242+ lib.optionalAttrs
243243+ (partitionConfig.storePaths or [ ] != [ ])
244244+ { closure = "${makeClosure partitionConfig.storePaths}/store-paths"; }
245245+ );
227246 in
228247 {
229248 name = lib.mkIf (config.system.image.id != null) (lib.mkOptionDefault config.system.image.id);
···239258 "xz" = 3;
240259 }."${cfg.compression.algorithm}";
241260 };
261261+262262+ finalPartitions = lib.mapAttrs addClosure cfg.partitions;
242263 };
243264244265 system.build.image =
···247268 (f: f != null)
248269 (lib.mapAttrsToList (_n: v: v.repartConfig.Format or null) cfg.partitions);
249270250250- makeClosure = paths: pkgs.closureInfo { rootPaths = paths; };
251251-252252- # Add the closure of the provided Nix store paths to cfg.partitions so
253253- # that amend-repart-definitions.py can read it.
254254- addClosure = _name: partitionConfig: partitionConfig // (
255255- lib.optionalAttrs
256256- (partitionConfig.storePaths or [ ] != [ ])
257257- { closure = "${makeClosure partitionConfig.storePaths}/store-paths"; }
258258- );
259259-260260- finalPartitions = lib.mapAttrs addClosure cfg.partitions;
261271262272 format = pkgs.formats.ini { };
263273264274 definitionsDirectory = utils.systemdUtils.lib.definitions
265275 "repart.d"
266276 format
267267- (lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) finalPartitions);
277277+ (lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) cfg.finalPartitions);
268278269269- partitions = pkgs.writeText "partitions.json" (builtins.toJSON finalPartitions);
279279+ partitionsJSON = pkgs.writeText "partitions.json" (builtins.toJSON cfg.finalPartitions);
270280271281 mkfsEnv = mkfsOptionsToEnv cfg.mkfsOptions;
272282 in
273283 pkgs.callPackage ./repart-image.nix {
274284 systemd = cfg.package;
275275- inherit (cfg) imageFileBasename compression split seed sectorSize;
276276- inherit fileSystems definitionsDirectory partitions mkfsEnv;
285285+ inherit (cfg) name version imageFileBasename compression split seed sectorSize;
286286+ inherit fileSystems definitionsDirectory partitionsJSON mkfsEnv;
277287 };
278288279279- meta.maintainers = with lib.maintainers; [ nikstur ];
289289+ meta.maintainers = with lib.maintainers; [ nikstur willibutz ];
280290281291 };
282292}
···22, lib
33, buildPythonPackage
44, fetchPypi
55+, fetchpatch
56, isPyPy
67, R
78, rWrapper
···3839 # R_LIBS_SITE is used by the nix r package to point to the installed R libraries.
3940 # This patch sets R_LIBS_SITE when rpy2 is imported.
4041 ./rpy2-3.x-r-libs-site.patch
4242+4343+ # https://github.com/rpy2/rpy2/pull/1094
4444+ (fetchpatch {
4545+ url = "https://github.com/rpy2/rpy2/commit/026d069a008163a62d12567bcb938410d0f9bf7a.diff";
4646+ hash = "sha256-x778upSY3zab5EiRyOcsbDpPj7vN/7XzefEs+wvkNg0=";
4747+ })
4148 ];
42494350 postPatch = ''
···8188 ];
82898390 doCheck = !stdenv.isDarwin;
8484-8585- # newlines in environment variables are a problem due to
8686- # https://github.com/rpy2/rpy2/issues/1066
8787- preCheck = "unset postPatch";
88918992 nativeCheckInputs = [
9093 pytestCheckHook