forked from papis/papis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
182 lines (166 loc) · 5.88 KB
/
flake.nix
File metadata and controls
182 lines (166 loc) · 5.88 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{
description = "Papis - Powerful command-line document and bibliography manager";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pyproject-nix.url = "github:nix-community/pyproject.nix";
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
flake-utils,
pyproject-nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python3.override {
packageOverrides = final: prev: {
types-pygments = final.buildPythonPackage rec {
pname = "types-Pygments";
version = "2.19.0.20250305";
src = final.fetchPypi {
inherit version;
pname = "types_pygments";
sha256 = "sha256-BExQ6A7NQSjACnJo8gNV4W9cVUZtPUnf2gm+kgr0C0s=";
};
doCheck = false;
checkInputs = [ ];
meta = with pkgs.lib; {
homepage = "https://github.com/python/typeshed";
description = "Typing stubs for Pygments";
license = licenses.asl20;
};
};
papis =
let
# Returns an attribute set that can be passed to `buildPythonPackage`.
attrs = project.renderers.buildPythonPackage {
inherit python;
extras = [ "optional" ];
};
in
assert
project.validators.validateVersionConstraints {
inherit python;
extras = [
"develop"
"docs"
"optional"
];
} == { };
# Pass attributes to buildPythonPackage.
# Here is a good spot to add on any missing or custom attributes.
final.buildPythonPackage (
attrs
// {
# Because we're following main, use the git rev as version
version = if (self ? rev) then self.shortRev else self.dirtyShortRev;
}
);
};
};
project = pyproject-nix.lib.project.loadPyproject {
projectRoot = ./.;
};
in
{
packages = {
default = self.packages.${system}.papis;
inherit (python.pkgs) papis;
};
devShells = {
default =
let
# Returns a function that can be passed to `python.withPackages`
arg = project.renderers.withPackages {
inherit python;
extras = [
"develop"
"docs"
"optional"
];
};
# Returns a wrapped environment (virtualenv like) with all our packages
pythonEnv = python.withPackages arg;
# Tools useful to have in the dev environment but not strictly
# necessary to our workflow
extra-dev-tools = python.withPackages (ps: [
ps.python-lsp-server
]);
# used in below scripts to check if docker or podman is available
check-container-cmd =
# bash
''
if command -v podman &> /dev/null
then
container_cmd="podman"
elif command -v docker &> /dev/null
then
container_cmd="docker"
else
echo "Neither Podman or Docker could be found. Aborting..."
exit 1
fi
'';
# convenience command to build a Papis container with docker/podman
papis-build-container = pkgs.writeShellApplication {
name = "papis-build-container";
text =
check-container-cmd
+
# bash
''
"$container_cmd" build -t papisdev .
'';
};
# convenience command to run containerised tests
papis-run-container-tests = pkgs.writeShellApplication {
name = "papis-run-container-tests";
text =
check-container-cmd
+
# bash
''
"$container_cmd" run -v "$(pwd)":/papis --rm -it papisdev
'';
};
# convenience command to enter a container with a populated test library
papis-run-container-interactive = pkgs.writeShellApplication {
name = "papis-run-container-interactive";
text =
check-container-cmd
+
# bash
''
populateLibPy=$(cat << END
import papis.testing
papis.testing.populate_library('/root/Documents/papers')
END
)
entryCmd="python -c \"$populateLibPy\"; bash"
"$container_cmd" run -v "$(pwd)":/papis --rm -it papisdev bash -c "$entryCmd"
'';
};
in
# Create a devShell like normal.
pkgs.mkShell {
packages = [
self.packages.${system}.papis
pythonEnv
extra-dev-tools
papis-build-container
papis-run-container-tests
papis-run-container-interactive
];
shellHook = ''
export PYTHONPATH="$(pwd):$PYTHONPATH"
'';
};
};
}
);
}