-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake.nix
108 lines (106 loc) · 3.46 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
98
99
100
101
102
103
104
105
106
107
108
{
description = "Nix flake for Volt";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
poetry2nix = {
url = "github:bow/poetry2nix/personal/overrides";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
poetry2nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ poetry2nix.overlays.default ];
};
overrides = pkgs.poetry2nix.overrides.withDefaults (
# Using wheel since mypy compilation is too long and it is only a dev/test dependency.
_final: prev: { mypy = prev.mypy.override { preferWheel = true; }; }
);
projectDir = self;
python = pkgs.python312; # NOTE: Keep in-sync with pyproject.toml.
app = pkgs.poetry2nix.mkPoetryApplication { inherit overrides projectDir python; };
in
{
apps = {
default = {
type = "app";
program = "${app}/bin/${app.pname}";
};
};
devShells =
let
devPackages = with pkgs; [
# python-only
(poetry.withPlugins (_ps: [ python.pkgs.poetry-dynamic-versioning ]))
# nix-only
deadnix
nixfmt-rfc-style
statix
# others
curl
entr
gnugrep
pre-commit
skopeo
];
devNativeBuildInputs = [
python
python.pkgs.venvShellHook
];
ciEnv = pkgs.poetry2nix.mkPoetryEnv { inherit overrides projectDir python; };
in
{
ci = pkgs.mkShellNoCC { packages = devPackages ++ [ ciEnv ]; };
default = pkgs.mkShellNoCC rec {
nativeBuildInputs = devNativeBuildInputs;
packages = devPackages;
venvDir = "./.venv";
postVenvCreation = ''
unset SOURCE_DATE_EPOCH
poetry env use ${venvDir}/bin/python
poetry install
'';
postShellHook = ''
unset SOURCE_DATE_EPOCH
'';
};
};
formatter = pkgs.nixfmt-rfc-style;
packages =
let
readFileOr = (path: default: with builtins; if pathExists path then (readFile path) else default);
imgTag = if app.version != "0.0.dev0" then app.version else "latest";
imgAttrs = rec {
name = "ghcr.io/bow/${app.pname}";
tag = imgTag;
contents = [ app ];
config = {
Entrypoint = [ "/bin/${app.pname}" ];
Labels = {
"org.opencontainers.image.revision" = readFileOr "${self}/.rev" "";
"org.opencontainers.image.source" = "https://github.com/bow/${app.pname}";
"org.opencontainers.image.title" = "${app.pname}";
"org.opencontainers.image.url" = "https://${name}";
};
};
};
in
{
dockerArchive = pkgs.dockerTools.buildLayeredImage imgAttrs;
dockerArchiveStreamer = pkgs.dockerTools.streamLayeredImage imgAttrs;
local = app;
};
}
);
}