Skip to content

Commit

Permalink
dev: implement nix flakes for developers
Browse files Browse the repository at this point in the history
- Implement flakes with development dependencies
- Add a `shell.nix` that leverages edolstra/flake-compat
  • Loading branch information
ElysaSrc committed Oct 19, 2023
1 parent 7033056 commit 9aebedc
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.DS_Store
*.nix
*.backup
__pycache__
209 changes: 209 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 120 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
description = "A Nix flake for OSRD dev shell";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
alejandra = {
url = "github:kamadorueda/alejandra/3.0.0";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
rust-overlay,
flake-utils,
alejandra,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
pythonPackages = ps: [
ps.black
ps.isort
ps.flake8
ps.intervaltree
ps.numpy
ps.mock
ps.pillow
ps.psycopg
ps.psycopg2
ps.pyyaml
ps.requests
ps.websockets
(ps.callPackage (import ./nix/kdtree.nix) {})
(ps.callPackage (import ./nix/geojson-pydantic.nix) {inherit (ps) pydantic;})

# DATA SCIENCE
ps.ipykernel
ps.jupyterlab
ps.shapely
ps.pyproj
ps.ipympl
ps.matplotlib
ps.networkx
ps.pyosmium

ps.progress
ps.tqdm
ps.ipywidgets
];

fixedNode = pkgs.nodejs-18_x;
fixedNodePackages = pkgs.nodePackages.override {
nodejs = fixedNode;
};

scriptFiles = builtins.attrNames (builtins.readDir ./scripts);
scriptBins =
map (
scriptFile:
pkgs.writeShellScriptBin
(pkgs.lib.strings.removeSuffix ".sh" scriptFile)
(pkgs.lib.strings.replaceStrings
["#!/bin/sh"] [""]
(builtins.readFile ./scripts/${scriptFile}))
)
scriptFiles;
in
with pkgs; {
devShells.default = mkShell {
buildInputs =
[
# API
(python310.withPackages pythonPackages)
poetry

# EDITOAST
osmium-tool
geos
postgresql
openssl
pkg-config
rustPackages.clippy
cargo-watch
cargo-tarpaulin
rust-analyzer
rust-bin.stable.latest.default

# CORE
jdk17

# FRONT
fixedNodePackages.create-react-app
fixedNodePackages.eslint
fixedNodePackages.yarn
fixedNode

# Nix formatter
alejandra.defaultPackage.${system}
]
++ scriptBins;

RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
OSRD_DEV = "True";
OSRD_BACKEND_URL = "http://localhost:8080";
};
}
);
}
24 changes: 24 additions & 0 deletions nix/geojson-pydantic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
lib,
buildPythonPackage,
fetchPypi,
pydantic,
}:
buildPythonPackage rec {
pname = "geojson-pydantic";
version = "0.3.1";

src = fetchPypi {
inherit pname version;
sha256 = "1clj89s39qyc510sylyx5fcfx9lpk7g8mi64rbzw067hcd5n2hk5";
};

doCheck = false;

propagatedBuildInputs = [pydantic];

meta = with lib; {
maintainers = with maintainers; [flomonster];
description = "GeoJson support for pydantic";
};
}
21 changes: 21 additions & 0 deletions nix/kdtree.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
lib,
buildPythonPackage,
fetchPypi,
}:
buildPythonPackage rec {
pname = "kdtree";
version = "0.16";

src = fetchPypi {
inherit pname version;
sha256 = "0d3m7pir24vp2sjg85anigv9xya4z5fh7qvlp7xf01bah73zcv9q";
};

doCheck = false;

meta = with lib; {
maintainers = with maintainers; [flomonster];
description = "Kdtree";
};
}
14 changes: 14 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{src = ./.;}
)
.shellNix

0 comments on commit 9aebedc

Please sign in to comment.