Skip to content

Commit

Permalink
Add optional nix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni committed Sep 16, 2023
1 parent a164a97 commit 0a4c8c2
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
138 changes: 138 additions & 0 deletions flake.lock

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

79 changes: 79 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
}
);
}

0 comments on commit 0a4c8c2

Please sign in to comment.