Skip to content

Commit 2b143c6

Browse files
committed
dev: implement nix flakes for developers
- Implement flakes with development dependencies - Add a `shell.nix` that leverages edolstra/flake-compat
1 parent ce88c6d commit 2b143c6

File tree

6 files changed

+388
-1
lines changed

6 files changed

+388
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.DS_Store
2-
*.nix
32
*.backup
43
__pycache__

flake.lock

+209
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
description = "A Nix flake for OSRD dev shell";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
8+
rust-overlay = {
9+
url = "github:oxalica/rust-overlay";
10+
inputs.nixpkgs.follows = "nixpkgs";
11+
};
12+
alejandra = {
13+
url = "github:kamadorueda/alejandra/3.0.0";
14+
inputs.nixpkgs.follows = "nixpkgs";
15+
};
16+
};
17+
18+
outputs = {
19+
self,
20+
nixpkgs,
21+
rust-overlay,
22+
flake-utils,
23+
alejandra,
24+
...
25+
}:
26+
flake-utils.lib.eachDefaultSystem (
27+
system: let
28+
pkgs = import nixpkgs {
29+
inherit system;
30+
overlays = [rust-overlay.overlays.default];
31+
};
32+
pythonPackages = ps: [
33+
ps.black
34+
ps.isort
35+
ps.flake8
36+
ps.intervaltree
37+
ps.numpy
38+
ps.mock
39+
ps.pillow
40+
ps.psycopg
41+
ps.psycopg2
42+
ps.pyyaml
43+
ps.requests
44+
ps.websockets
45+
(ps.callPackage (import ./nix/kdtree.nix) {})
46+
(ps.callPackage (import ./nix/geojson-pydantic.nix) {inherit (ps) pydantic;})
47+
48+
# DATA SCIENCE
49+
ps.ipykernel
50+
ps.jupyterlab
51+
ps.shapely
52+
ps.pyproj
53+
ps.ipympl
54+
ps.matplotlib
55+
ps.networkx
56+
ps.pyosmium
57+
58+
ps.progress
59+
ps.tqdm
60+
ps.ipywidgets
61+
];
62+
63+
fixedNode = pkgs.nodejs-18_x;
64+
fixedNodePackages = pkgs.nodePackages.override {
65+
nodejs = fixedNode;
66+
};
67+
68+
scriptFiles = builtins.attrNames (builtins.readDir ./scripts);
69+
scriptBins =
70+
map (
71+
scriptFile:
72+
pkgs.writeShellScriptBin
73+
(pkgs.lib.strings.removeSuffix ".sh" scriptFile)
74+
(pkgs.lib.strings.replaceStrings
75+
["#!/bin/sh"] [""]
76+
(builtins.readFile ./scripts/${scriptFile}))
77+
)
78+
scriptFiles;
79+
in
80+
with pkgs; {
81+
devShells.default = mkShell {
82+
buildInputs =
83+
[
84+
# API
85+
(python310.withPackages pythonPackages)
86+
poetry
87+
88+
# EDITOAST
89+
osmium-tool
90+
geos
91+
postgresql
92+
openssl
93+
pkg-config
94+
rustPackages.clippy
95+
cargo-watch
96+
cargo-tarpaulin
97+
rust-analyzer
98+
rust-bin.stable.latest.default
99+
100+
# CORE
101+
jdk17
102+
103+
# FRONT
104+
fixedNodePackages.create-react-app
105+
fixedNodePackages.eslint
106+
fixedNodePackages.yarn
107+
fixedNode
108+
109+
# Nix formatter
110+
alejandra.defaultPackage.${system}
111+
]
112+
++ scriptBins;
113+
114+
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
115+
OSRD_DEV = "True";
116+
OSRD_BACKEND_URL = "http://localhost:8080";
117+
};
118+
}
119+
);
120+
}

nix/geojson-pydantic.nix

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
lib,
3+
buildPythonPackage,
4+
fetchPypi,
5+
pydantic,
6+
}:
7+
buildPythonPackage rec {
8+
pname = "geojson-pydantic";
9+
version = "0.3.1";
10+
11+
src = fetchPypi {
12+
inherit pname version;
13+
sha256 = "1clj89s39qyc510sylyx5fcfx9lpk7g8mi64rbzw067hcd5n2hk5";
14+
};
15+
16+
doCheck = false;
17+
18+
propagatedBuildInputs = [pydantic];
19+
20+
meta = with lib; {
21+
maintainers = with maintainers; [flomonster];
22+
description = "GeoJson support for pydantic";
23+
};
24+
}

nix/kdtree.nix

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
lib,
3+
buildPythonPackage,
4+
fetchPypi,
5+
}:
6+
buildPythonPackage rec {
7+
pname = "kdtree";
8+
version = "0.16";
9+
10+
src = fetchPypi {
11+
inherit pname version;
12+
sha256 = "0d3m7pir24vp2sjg85anigv9xya4z5fh7qvlp7xf01bah73zcv9q";
13+
};
14+
15+
doCheck = false;
16+
17+
meta = with lib; {
18+
maintainers = with maintainers; [flomonster];
19+
description = "Kdtree";
20+
};
21+
}

shell.nix

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(
2+
import
3+
(
4+
let
5+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
6+
in
7+
fetchTarball {
8+
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
9+
sha256 = lock.nodes.flake-compat.locked.narHash;
10+
}
11+
)
12+
{src = ./.;}
13+
)
14+
.shellNix

0 commit comments

Comments
 (0)