From 86438632ace9d7483da0b4002276314f4d4891b4 Mon Sep 17 00:00:00 2001 From: Jeppe Fihl-Pearson <jeppe@tenzer.dk> Date: Mon, 23 Dec 2024 21:55:52 +0000 Subject: [PATCH] Use poetry2nix to configure Nix Flake It means no special configuration is needed for dependencies that are not packaged in nixpkgs, and installation becomes faster because wheels are used which require less dependencies to be installed. --- flake.lock | 90 +++++++++++++++++++++++++++++++++++++++++++-------- flake.nix | 94 +++++++++++++----------------------------------------- 2 files changed, 100 insertions(+), 84 deletions(-) diff --git a/flake.lock b/flake.lock index 406c56b..d9d6ad3 100644 --- a/flake.lock +++ b/flake.lock @@ -18,37 +18,66 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1729742964, + "narHash": "sha256-B4mzTcQ0FZHdpeWcpDYPERtyjJd/NIuaQ9+BV1h+MpA=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "e04df33f62cdcf93d73e9a04142464753a16db67", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1734856068, - "narHash": "sha256-Q+CB1ajsJg4Z9HGHTBAGY1q18KpnnkmF/eCTLUY6FQ0=", + "lastModified": 1734649271, + "narHash": "sha256-4EVBRhOjMDuGtMaofAIqzJbg4Ql7Ai0PSeuVZTHjyKQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "93ff48c9be84a76319dac293733df09bbbe3f25c", + "rev": "d70bd19e0a38ad4790d3913bf08fcbfc9eeca507", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" } }, - "pyproject-nix": { + "poetry2nix": { "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nix-github-actions": "nix-github-actions", "nixpkgs": [ "nixpkgs" - ] + ], + "systems": "systems_2", + "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1734658408, - "narHash": "sha256-HdHkeJ506zKDOrCvsMoZllrOs1sol6bYbv1DifDtas0=", + "lastModified": 1731205797, + "narHash": "sha256-F7N1mxH1VrkVNHR3JGNMRvp9+98KYO4b832KS8Gl2xI=", "owner": "nix-community", - "repo": "pyproject.nix", - "rev": "139a84af40ed51c87f27708fcbe196bd6f189efd", + "repo": "poetry2nix", + "rev": "f554d27c1544d9c56e5f1f8e2b8aff399803674e", "type": "github" }, "original": { "owner": "nix-community", - "repo": "pyproject.nix", + "repo": "poetry2nix", "type": "github" } }, @@ -56,7 +85,7 @@ "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "pyproject-nix": "pyproject-nix" + "poetry2nix": "poetry2nix" } }, "systems": { @@ -73,6 +102,41 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "id": "systems", + "type": "indirect" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1730120726, + "narHash": "sha256-LqHYIxMrl/1p3/kvm2ir925tZ8DkI0KA10djk8wecSk=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "9ef337e492a5555d8e17a51c911ff1f02635be15", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index e0f1507..fd23448 100644 --- a/flake.nix +++ b/flake.nix @@ -1,93 +1,45 @@ { - inputs = { - pyproject-nix.url = "github:nix-community/pyproject.nix"; - pyproject-nix.inputs.nixpkgs.follows = "nixpkgs"; + description = "CLI for remote controlling LG webOS TVs"; + inputs = { flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + poetry2nix = { + url = "github:nix-community/poetry2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; }; outputs = { + self, nixpkgs, - pyproject-nix, flake-utils, - ... + poetry2nix, }: flake-utils.lib.eachDefaultSystem ( system: let - inherit (nixpkgs) lib; - project = pyproject-nix.lib.project.loadPoetryPyproject { projectRoot = ./.; }; - - overlay = _: prev: { - python3 = prev.python3.override { - packageOverrides = _: p: { - cfgs = p.buildPythonPackage rec { - version = "0.13.0"; - pname = "cfgs"; - format = "pyproject"; - nativeBuildInputs = with p.pythonPackages; [ poetry-core ]; - src = p.fetchPypi { - inherit version pname; - hash = "sha256-zvR+Z/BRJ4Pug+JMwvOeWyO11MoMMrvXIb1k9IY2Zn4="; - }; - }; - pzp = p.buildPythonPackage rec { - version = "0.0.25"; - pname = "pzp"; - format = "pyproject"; - nativeBuildInputs = with p.pythonPackages; [ - poetry-core - setuptools - ]; - src = p.fetchPypi { - inherit version pname; - hash = "sha256-29OhVEM9By+SQ6Cb+SF/f3157FBDttCxDHHV8kpcx2Y="; - }; - }; - typer = p.buildPythonPackage rec { - version = "0.15.1"; - pname = "typer"; - format = "pyproject"; - nativeBuildInputs = with p.pythonPackages; [ - poetry-core - pdm-backend - ]; - propagatedBuildInputs = with p.pythonPackages; [ - click - shellingham - rich - typing-extensions - ]; - src = p.fetchPypi { - inherit version pname; - hash = "sha256-oFiMCn+mihl4oGmBhld3j4ar5v9epqv0cvlAoIv+Two="; - }; - }; - - }; + alga = + { poetry2nix, lib }: + poetry2nix.mkPoetryApplication { + projectDir = self; + preferWheels = true; }; - }; - pkgs = import nixpkgs { inherit system; - overlays = [ overlay ]; + overlays = [ + poetry2nix.overlays.default + (final: _: { + alga = final.callPackage alga { }; + }) + ]; }; - python = pkgs.python3; in { - devShells.default = - let - arg = project.renderers.withPackages { inherit python; }; - pythonEnv = python.withPackages arg; - in - pkgs.mkShell { packages = [ pythonEnv ]; }; - - packages.default = - let - attrs = project.renderers.buildPythonPackage { inherit python; }; - in - python.pkgs.buildPythonPackage attrs; + packages.default = pkgs.alga; + legacyPackages = pkgs; } ); }