From 3c81dea1c9275480cbc7c3a303a8dc432af23359 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 7 Jul 2024 13:09:05 +0200 Subject: [PATCH] feat(nix): Update tooling --- .envrc | 1 + .gitignore | 1 + 01-authens.patch | 11 +++++++ default.nix | 64 +++++++++++++++++++++++++++++++++++++ npins/default.nix | 80 ++++++++++++++++++++++++++++++++++++++++++++++ npins/sources.json | 22 +++++++++++++ shell.nix | 23 +------------ 7 files changed, 180 insertions(+), 22 deletions(-) create mode 100644 .envrc create mode 100644 01-authens.patch create mode 100644 default.nix create mode 100644 npins/default.nix create mode 100644 npins/sources.json diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore index d433e86..98737dc 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ pyrightconfig.json *.sqlite3 .vscode +.direnv diff --git a/01-authens.patch b/01-authens.patch new file mode 100644 index 0000000..e161a1d --- /dev/null +++ b/01-authens.patch @@ -0,0 +1,11 @@ +diff --git a/authens/utils.py b/authens/utils.py +index 7306506..36063b6 100644 +--- a/authens/utils.py ++++ b/authens/utils.py +@@ -16,7 +16,7 @@ def get_cas_client(request): + service_url=urlunparse( + (request.scheme, request.get_host(), request.path, "", "", "") + ), +- server_url="https://cas.eleves.ens.fr/", ++ server_url="https://cas-eleves.dgnum.eu/", + ) diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..1a4b7fe --- /dev/null +++ b/default.nix @@ -0,0 +1,64 @@ +{ + sources ? import ./npins, + pkgs ? import sources.nixpkgs { }, +}: + +let + nix-pkgs = import sources.nix-pkgs { inherit pkgs; }; + + python3 = pkgs.python3.override { + packageOverrides = _: _: { + inherit (nix-pkgs) + django-background-tasks + django-browser-reload + django-bulma-forms + django-translated-fields + loadcredential + ; + + authens = nix-pkgs.authens.overridePythonAttrs (old: { + patches = [ ./01-authens.patch ]; + }); + }; + }; +in + +{ + devShell = pkgs.mkShell { + name = "cas-eleves.dev"; + + packages = [ + (python3.withPackages (ps: [ + ps.django + ps.ipython + + ps.markdown + ps.numpy + ps.networkx + + ps.authens + ps.django-background-tasks + ps.django-browser-reload + ps.django-bulma-forms + ps.django-debug-toolbar + ps.django-translated-fields + ps.loadcredential + ])) + + pkgs.gettext + pkgs.gtranslator + ]; + + env = { + CREDENTIALS_DIRECTORY = builtins.toString ./.credentials; + CE_DEBUG = true; + CE_STATIC_ROOT = builtins.toString ./.static; + }; + + shellHook = '' + if [ ! -d .static ]; then + mkdir .static + fi + ''; + }; +} diff --git a/npins/default.nix b/npins/default.nix new file mode 100644 index 0000000..fb04b70 --- /dev/null +++ b/npins/default.nix @@ -0,0 +1,80 @@ +# Generated by npins. Do not modify; will be overwritten regularly +let + data = builtins.fromJSON (builtins.readFile ./sources.json); + version = data.version; + + mkSource = + spec: + assert spec ? type; + let + path = + if spec.type == "Git" then + mkGitSource spec + else if spec.type == "GitRelease" then + mkGitSource spec + else if spec.type == "PyPi" then + mkPyPiSource spec + else if spec.type == "Channel" then + mkChannelSource spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = path; }; + + mkGitSource = + { + repository, + revision, + url ? null, + hash, + branch ? null, + ... + }: + assert repository ? type; + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository + # In the latter case, there we will always be an url to the tarball + if url != null then + (builtins.fetchTarball { + inherit url; + sha256 = hash; + }) + else + assert repository.type == "Git"; + let + urlToName = + url: rev: + let + matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; + in + "${if matched == null then "source" else builtins.head matched}${appendShort}"; + name = urlToName repository.url revision; + in + builtins.fetchGit { + url = repository.url; + rev = revision; + inherit name; + narHash = hash; + }; + + mkPyPiSource = + { url, hash, ... }: + builtins.fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { url, hash, ... }: + builtins.fetchTarball { + inherit url; + sha256 = hash; + }; +in +if version == 4 then + builtins.mapAttrs (_: mkSource) data.pins +else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" diff --git a/npins/sources.json b/npins/sources.json new file mode 100644 index 0000000..fdb8ee4 --- /dev/null +++ b/npins/sources.json @@ -0,0 +1,22 @@ +{ + "pins": { + "nix-pkgs": { + "type": "Git", + "repository": { + "type": "Git", + "url": "https://git.hubrecht.ovh/hubrecht/nix-pkgs.git" + }, + "branch": "main", + "revision": "46879d052e4a694ceb3027dbcff641c44e0ae1bd", + "url": null, + "hash": "sha256-/Yn3NDYA76bv8x06jahLAJ2z54L0vFeAtQKzyW3MfGA=" + }, + "nixpkgs": { + "type": "Channel", + "name": "nixpkgs-unstable", + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.11pre646460.0aeab749216e/nixexprs.tar.xz", + "hash": "0xa73bs0n28x731hf6ipqrlji0p3qf2a42vfm6g8snnhaab9mfwj" + } + }, + "version": 4 +} \ No newline at end of file diff --git a/shell.nix b/shell.nix index be49fa8..d6d21cf 100644 --- a/shell.nix +++ b/shell.nix @@ -1,22 +1 @@ -let - mach-nix = import - (builtins.fetchGit { - url = "https://github.com/DavHau/mach-nix"; - ref = "refs/tags/3.5.0"; - }) - { }; - - requirements = builtins.readFile ./requirements.txt; - - requirements-dev = '' - django-debug-toolbar - ipython - black - isort - flake8 - ''; -in - -mach-nix.mkPythonShell { - requirements = requirements + requirements-dev; -} +(import ./. { }).devShell