-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
97 lines (84 loc) · 2.33 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
description = "Parametric surface renderer";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let pkgs = import nixpkgs {
system = "x86_64-linux";
};
in {
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = with pkgs; [
clang
clang-tools
cmake
gnumake
python311
python311Packages.sympy
python311Packages.matplotlib
ffmpeg_6-full
];
};
packages.x86_64-linux.default = pkgs.stdenv.mkDerivation rec {
name = "renderer";
src = ./.;
buildInputs = with pkgs; [
clang
cmake
gnumake
];
buildPhase = ''
cmake .. -DCMAKE_BUILD_TYPE=Release
make
'';
installPhase = ''
mkdir -p $out/bin
cp renderer $out/bin
'';
};
packages.x86_64-linux.video = pkgs.writeScriptBin "video" ''
#!${pkgs.python311}/bin/python
import argparse
import subprocess
parser = argparse.ArgumentParser(description='Render a parametric surface to a video file.')
parser.add_argument('output_file', type=str, help='output video file')
parser.add_argument('--fps', type=int, default=60, help='frames per second of output video')
parser.add_argument('args', nargs=argparse.REMAINDER, help='arguments to pass to renderer')
args = parser.parse_args()
renderer = subprocess.Popen(
[
"${self.packages.x86_64-linux.default}/bin/renderer",
"--fps", str(args.fps),
*args.args
],
stdout=subprocess.PIPE
)
ffmpeg = subprocess.Popen(
[
"${pkgs.ffmpeg_6-headless}/bin/ffmpeg",
"-y",
"-f", "image2pipe",
"-framerate", str(args.fps),
"-i", "-",
"-c:v", "libx264",
"-preset", "veryslow",
"-crf", "18",
"-pix_fmt", "yuv420p",
"-f", "mp4",
args.output_file
],
stdin=renderer.stdout
)
ffmpeg.communicate()
'';
apps.x86_64-linux.renderer = {
type = "app";
program = "${self.packages.x86_64-linux.default}/bin/renderer";
};
apps.x86_64-linux.video = {
type = "app";
program = "${self.packages.x86_64-linux.video}/bin/video";
};
};
}