aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--README.md12
-rw-r--r--flake.lock42
-rw-r--r--flake.nix42
-rw-r--r--main.py3
-rw-r--r--requirements.txt1
6 files changed, 103 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e1bd8ab
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.venv
+.direnv
+.envrc
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e01dfe6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,12 @@
+# Python with Nix Flakes
+
+This repo is just to show how to use flakes with a simple python project. To try
+it out you can clone the repo and run:
+
+```
+nix develop
+python main.py
+```
+
+`nix develop` will drop you into a bash shell that will have everything you need
+to run `main.py`.
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..014a0c3
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,42 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "locked": {
+ "lastModified": 1620759905,
+ "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1621630984,
+ "narHash": "sha256-lCzF8vKaUGzlQFx0RARbO7tRPUx01Spr/1fCkzV/i5s=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "12a9bd6fb8a6883480d5fc7ea4518c621060875e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..3c153d3
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,42 @@
+{
+ description = "A very basic flake for developing in python";
+ # Provides abstraction to boiler-code when specifying multi-platform outputs.
+ inputs = {
+ flake-utils.url = "github:numtide/flake-utils";
+ nixpkgs.url = "github:nixos/nixpkgs";
+ };
+ outputs = { self, nixpkgs, flake-utils }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+ venvDir = "./.venv";
+ pythonPackages = pkgs.python38Packages;
+ in {
+ devShell = pkgs.mkShell {
+ nativeBuildInputs = with pkgs; [
+ hello
+ pythonPackages.python
+ ];
+ shellHook = ''
+ SOURCE_DATE_EPOCH=$(date +%s)
+
+ if [ -d "${venvDir}" ]; then
+ echo "Skipping venv creation, '${venvDir}' already exists"
+ else
+ echo "Creating new venv environment in path: '${venvDir}'"
+ # Note that the module venv was only introduced in python 3, so for 2.7
+ # this needs to be replaced with a call to virtualenv
+ ${pythonPackages.python.interpreter} -m venv "${venvDir}"
+ fi
+
+ # Under some circumstances it might be necessary to add your virtual
+ # environment to PYTHONPATH, which you can do here too;
+ # PYTHONPATH=$PWD/${venvDir}/${pythonPackages.python.sitePackages}/:$PYTHONPATH
+
+ source "${venvDir}/bin/activate"
+
+ # As in the previous example, this is optional.
+ pip install -r requirements.txt
+ '';
+ };
+ });
+}
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..97b869a
--- /dev/null
+++ b/main.py
@@ -0,0 +1,3 @@
+import requests
+
+print(requests.get("https://www.codyhiar.com").text)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..f229360
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+requests