diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..2cee1789 --- /dev/null +++ b/flake.lock @@ -0,0 +1,138 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688870561, + "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1694499547, + "narHash": "sha256-R7xMz1Iia6JthWRHDn36s/E248WB1/je62ovC/dUVKI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e5f018cf150e29aac26c61dac0790ea023c46b24", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils_2", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1694165861, + "narHash": "sha256-FMiPKVcNxb9QWATnQrC68nIL2t8Fm4zBH0XyLz9uqko=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "c3d3c4a0396b1bcccd72c82551a319229997f6e4", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..97a2dd53 --- /dev/null +++ b/flake.nix @@ -0,0 +1,79 @@ +# This flake reads the Poetry configuration and builds a development shell with +# all the dependencies (Python and not!) needed to run the site. + +# It's not required to run the site, mostly a convenience for those who use Nix. +# Most people can just use Poetry directly. + +# But Nix is cool! You should check it out :) :) +# Casually dropping a link: https://zero-to-nix.com/ + +{ + description = "Eta Kappa Nu, Mu Chapter website"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + flake-utils.url = "github:numtide/flake-utils"; + poetry2nix = { + url = "github:nix-community/poetry2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, poetry2nix }: flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ poetry2nix.overlay ]; + }; + + # Python version to use. Should match the version in pyproject.toml. + python = pkgs.python39; + + # Since some dependencies require additional build inputs, we need to + # specify them here. + extra-build-requirements = { + django-autocomplete-light = [ "setuptools" ]; + django-markdownx = [ "setuptools" ]; + mysqlclient = [ pkgs.pkg-config ]; + }; + + # This uses the above to build a poetry2nix overrides set that adds the + # build inputs to the Python packages. + overrides = pkgs.poetry2nix.defaultPoetryOverrides.extend (final: prev: + builtins.mapAttrs + (package: reqs: + let + reqs-pkgs = builtins.map (pkg: if builtins.isString pkg then prev.${pkg} else pkg) reqs; + in + prev.${package}.overridePythonAttrs (old: { + buildInputs = (old.buildInputs or [ ]) ++ reqs-pkgs; + nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ reqs-pkgs; + }) + ) + extra-build-requirements + ); + + # This is the actual package definition. It uses poetry2nix to build a + # Python package from the poetry.lock file in the current directory. + env = pkgs.poetry2nix.mkPoetryEnv { + inherit python overrides; + projectDir = self; + groups = [ "dev" ]; + preferWheels = true; + }; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.libmysqlclient + pkgs.pkg-config + pkgs.blackbox + pkgs.poetry + pkgs.pinentry + pkgs.gnupg + env + ]; + }; + } + ); +}