From 26c0cc49901ce6a814b64b44ec2a2d1cf34e4e50 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 19 Nov 2022 19:17:13 +0100 Subject: [PATCH] Use poetry2nix as a flake --- flake.lock | 39 +++++++++++++++++- flake.nix | 115 +++++++++++++++++++++++++++++------------------------ 2 files changed, 102 insertions(+), 52 deletions(-) diff --git a/flake.lock b/flake.lock index de8fe0a..f41c9e4 100644 --- a/flake.lock +++ b/flake.lock @@ -15,6 +15,21 @@ "type": "github" } }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1668765800, @@ -31,10 +46,32 @@ "type": "github" } }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1668738526, + "narHash": "sha256-OtyHtZalpeTjZ5B44C8wV3WqTUmeBBxoGc7KPIkwxAU=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "0c5bae34bee822876a2dbb1c62d89cd1b29b648d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix" } } }, diff --git a/flake.nix b/flake.nix index 6286bba..268d12b 100644 --- a/flake.nix +++ b/flake.nix @@ -3,71 +3,84 @@ inputs = { nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable; flake-utils.url = github:numtide/flake-utils; + poetry2nix = { + url = "github:nix-community/poetry2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: + outputs = { self, nixpkgs, flake-utils, poetry2nix }: + { + overlay = nixpkgs.lib.composeManyExtensions [ + poetry2nix.overlay + (final: prev: { + inventory = prev.poetry2nix.mkPoetryEnv { + projectDir = ./.; + overrides = prev.poetry2nix.defaultPoetryOverrides.extend + (self: super: { + findpython = super.findpython.overridePythonAttrs ( + old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.pdm ]; + } + ); + django-floppyforms = + super.django-floppyforms.overridePythonAttrs + ( + old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; + } + ); + django-crispy-forms = super.django-crispy-forms.overridePythonAttrs + ( + old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; + } + ); + django-nested-admin = super.django-crispy-forms.overridePythonAttrs + ( + old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; + } + ); + exceptiongroup = super.exceptiongroup.overridePythonAttrs + ( + old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.flit-scm ]; + } + ); + python-monkey-business = super.python-monkey-business.overridePythonAttrs + ( + old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.flit-scm ]; + } + ); + pytoolconfig = super.pytoolconfig.overridePythonAttrs + ( + old: { + buildInputs = (old.buildInputs or [ ]) ++ [ super.pdm ]; + } + ); + }); + }; + }) + ]; + } // (flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; + overlays = [ self.overlay ]; }; in { devShell = pkgs.mkShell { buildInputs = [ pkgs.gnumake - (pkgs.poetry2nix.mkPoetryEnv { - projectDir = ./.; - overrides = pkgs.poetry2nix.defaultPoetryOverrides.extend - (self: super: { - findpython = super.findpython.overridePythonAttrs ( - old: { - buildInputs = (old.buildInputs or [ ]) ++ [ super.pdm ]; - } - ); - django-floppyforms = - super.django-floppyforms.overridePythonAttrs - ( - old: { - buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; - } - ); - django-crispy-forms = super.django-crispy-forms.overridePythonAttrs - ( - old: { - buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; - } - ); - django-nested-admin = super.django-crispy-forms.overridePythonAttrs - ( - old: { - buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; - } - ); - exceptiongroup = super.exceptiongroup.overridePythonAttrs - ( - old: { - buildInputs = (old.buildInputs or [ ]) ++ [ super.flit-scm ]; - } - ); - python-monkey-business = super.python-monkey-business.overridePythonAttrs - ( - old: { - buildInputs = (old.buildInputs or [ ]) ++ [ super.flit-scm ]; - } - ); - pytoolconfig = super.pytoolconfig.overridePythonAttrs - ( - old: { - buildInputs = (old.buildInputs or [ ]) ++ [ super.pdm ]; - } - ); - }); - }) + pkgs.inventory pkgs.python310Packages.poetry ]; }; shellHook = '' export DJANGO_SETTINGS_MODULE=network_inventory.settings.local ''; - }); + })); }