Skip to content

Commit a04a8e3

Browse files
committed
build: extract pythonSet to default.nix
1 parent dba08c7 commit a04a8e3

File tree

2 files changed

+124
-105
lines changed

2 files changed

+124
-105
lines changed

default.nix

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
lib,
3+
stdenv,
4+
callPackage,
5+
python3,
6+
jetbrains-mono,
7+
asciinema-scenario,
8+
asciinema-agg,
9+
uv2nix,
10+
pyproject-nix,
11+
}:
12+
let
13+
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
14+
pyprojectOverlay = workspace.mkPyprojectOverlay {
15+
sourcePreference = "wheel";
16+
};
17+
pyprojectOverrides = final: prev: {
18+
makejinja = prev.makejinja.overrideAttrs (old: {
19+
passthru = lib.recursiveUpdate (old.passthru or { }) {
20+
tests.pytest = stdenv.mkDerivation {
21+
name = "${final.makejinja.name}-pytest";
22+
inherit (final.makejinja) src;
23+
nativeBuildInputs = [
24+
(final.mkVirtualEnv "makejinja-test-env" {
25+
makejinja = [ "test" ];
26+
})
27+
];
28+
dontConfigure = true;
29+
buildPhase = ''
30+
runHook preBuild
31+
pytest --cov-report=html
32+
runHook postBuild
33+
'';
34+
installPhase = ''
35+
runHook preInstall
36+
mv htmlcov $out
37+
runHook postInstall
38+
'';
39+
};
40+
docs = stdenv.mkDerivation {
41+
name = "${final.makejinja.name}-docs";
42+
inherit (final.makejinja) src;
43+
nativeBuildInputs = [
44+
(final.mkVirtualEnv "makejinja-docs-env" {
45+
makejinja = [ "docs" ];
46+
})
47+
asciinema-scenario
48+
asciinema-agg
49+
];
50+
dontConfigure = true;
51+
buildPhase = ''
52+
runHook preBuild
53+
54+
{
55+
echo '```txt'
56+
COLUMNS=120 makejinja --help
57+
echo '```'
58+
} > ./manpage.md
59+
60+
asciinema-scenario ./assets/demo.scenario > ./assets/demo.cast
61+
agg \
62+
--font-dir "${jetbrains-mono}/share/fonts/truetype" \
63+
--font-family "JetBrains Mono" \
64+
--theme monokai \
65+
./assets/demo.cast ./assets/demo.gif
66+
67+
pdoc \
68+
-d google \
69+
-t pdoc-template \
70+
--math \
71+
--logo https://raw.githubusercontent.com/mirkolenz/makejinja/main/assets/logo.png \
72+
-o "$out" \
73+
./src/makejinja
74+
75+
runHook postBuild
76+
'';
77+
installPhase = ''
78+
runHook preInstall
79+
80+
mkdir -p "$out/assets"
81+
cp -rf ./assets/{*.png,*.gif} "$out/assets/"
82+
83+
runHook postInstall
84+
'';
85+
};
86+
};
87+
});
88+
};
89+
baseSet = callPackage pyproject-nix.build.packages {
90+
python = python3;
91+
};
92+
pythonSet = baseSet.overrideScope (
93+
lib.composeManyExtensions [
94+
pyprojectOverlay
95+
pyprojectOverrides
96+
]
97+
);
98+
addMeta =
99+
drv:
100+
drv.overrideAttrs (old: {
101+
passthru = lib.recursiveUpdate (old.passthru or { }) {
102+
inherit (pythonSet.makejinja.passthru) tests;
103+
};
104+
meta = (old.meta or { }) // {
105+
mainProgram = "makejinja";
106+
maintainers = with lib.maintainers; [ mirkolenz ];
107+
license = lib.licenses.mit;
108+
homepage = "https://github.com/mirkolenz/makejinja";
109+
description = "Generate entire directory structures using Jinja templates with support for external data and custom plugins.";
110+
platforms = with lib.platforms; darwin ++ linux;
111+
};
112+
});
113+
in
114+
pythonSet
115+
// {
116+
mkApp = depsName: addMeta (pythonSet.mkVirtualEnv "makejinja-env" workspace.deps.${depsName});
117+
}

flake.nix

+7-105
Original file line numberDiff line numberDiff line change
@@ -47,108 +47,7 @@
4747
...
4848
}:
4949
let
50-
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
51-
pyprojectOverlay = workspace.mkPyprojectOverlay {
52-
sourcePreference = "wheel";
53-
};
54-
pyprojectOverrides = final: prev: {
55-
makejinja = prev.makejinja.overrideAttrs (old: {
56-
passthru = (old.passthru or { }) // {
57-
tests = (old.tests or { }) // {
58-
pytest = pkgs.stdenv.mkDerivation {
59-
name = "${final.makejinja.name}-pytest";
60-
inherit (final.makejinja) src;
61-
nativeBuildInputs = [
62-
(final.mkVirtualEnv "makejinja-test-env" {
63-
makejinja = [ "test" ];
64-
})
65-
];
66-
dontConfigure = true;
67-
buildPhase = ''
68-
runHook preBuild
69-
pytest --cov-report=html
70-
runHook postBuild
71-
'';
72-
installPhase = ''
73-
runHook preInstall
74-
mv htmlcov $out
75-
runHook postInstall
76-
'';
77-
};
78-
};
79-
docs = pkgs.stdenv.mkDerivation {
80-
name = "${final.makejinja.name}-docs";
81-
inherit (final.makejinja) src;
82-
nativeBuildInputs = with pkgs; [
83-
(final.mkVirtualEnv "makejinja-docs-env" {
84-
makejinja = [ "docs" ];
85-
})
86-
asciinema-scenario
87-
asciinema-agg
88-
];
89-
dontConfigure = true;
90-
buildPhase = ''
91-
runHook preBuild
92-
93-
{
94-
echo '```txt'
95-
COLUMNS=120 makejinja --help
96-
echo '```'
97-
} > ./manpage.md
98-
99-
asciinema-scenario ./assets/demo.scenario > ./assets/demo.cast
100-
agg \
101-
--font-dir "${pkgs.jetbrains-mono}/share/fonts/truetype" \
102-
--font-family "JetBrains Mono" \
103-
--theme monokai \
104-
./assets/demo.cast ./assets/demo.gif
105-
106-
pdoc \
107-
-d google \
108-
-t pdoc-template \
109-
--math \
110-
--logo https://raw.githubusercontent.com/mirkolenz/makejinja/main/assets/logo.png \
111-
-o "$out" \
112-
./src/makejinja
113-
114-
runHook postBuild
115-
'';
116-
installPhase = ''
117-
runHook preInstall
118-
119-
mkdir -p "$out/assets"
120-
cp -rf ./assets/{*.png,*.gif} "$out/assets/"
121-
122-
runHook postInstall
123-
'';
124-
};
125-
};
126-
});
127-
};
128-
baseSet = pkgs.callPackage pyproject-nix.build.packages {
129-
python = pkgs.python3;
130-
};
131-
pythonSet = baseSet.overrideScope (
132-
lib.composeManyExtensions [
133-
pyprojectOverlay
134-
pyprojectOverrides
135-
]
136-
);
137-
addMeta =
138-
drv:
139-
drv.overrideAttrs (old: {
140-
passthru = lib.recursiveUpdate (old.passthru or { }) {
141-
inherit (pythonSet.makejinja.passthru) tests;
142-
};
143-
meta = (old.meta or { }) // {
144-
mainProgram = "makejinja";
145-
maintainers = with lib.maintainers; [ mirkolenz ];
146-
license = lib.licenses.mit;
147-
homepage = "https://github.com/mirkolenz/makejinja";
148-
description = "Generate entire directory structures using Jinja templates with support for external data and custom plugins.";
149-
platforms = with lib.platforms; darwin ++ linux;
150-
};
151-
});
50+
inherit (config.legacyPackages) pythonSet;
15251
in
15352
{
15453
_module.args.pkgs = import nixpkgs {
@@ -174,11 +73,14 @@
17473
nixfmt.enable = true;
17574
};
17675
};
76+
legacyPackages.pythonSet = pkgs.callPackage ./default.nix {
77+
inherit (inputs) uv2nix pyproject-nix;
78+
};
17779
packages = {
17880
inherit (pythonSet.makejinja.passthru) docs;
17981
default = config.packages.makejinja;
180-
makejinja = addMeta (pythonSet.mkVirtualEnv "makejinja-env" workspace.deps.optionals);
181-
docker = pkgs.dockerTools.buildLayeredImage {
82+
makejinja = pythonSet.mkApp "optionals";
83+
docker = pkgs.dockerTools.streamLayeredImage {
18284
name = "makejinja";
18385
tag = "latest";
18486
created = "now";
@@ -198,7 +100,7 @@
198100
token = "$GH_TOKEN";
199101
};
200102
version = builtins.getEnv "VERSION";
201-
images = with self.packages; [
103+
imageStreams = with self.packages; [
202104
x86_64-linux.docker
203105
aarch64-linux.docker
204106
];

0 commit comments

Comments
 (0)