From c5192146afeec86545a9eeae3b22c0eaeb33e9e6 Mon Sep 17 00:00:00 2001 From: Matthew Croughan Date: Tue, 3 Oct 2023 09:50:35 +0100 Subject: [PATCH] nix: fix nixosModule and build (#1979) * lnbits/settings: get LNBITS_COMMIT from envvar if available There is no other way of setting the git commit at runtime, for build systems like Nix that allow you to hermetically define envvars derived from the source that will be available reproducibly at runtime * nix: update potree2nix and nixosModule This is a general refactor that gets everything building and passing the vmTest again * Update nix/modules/lnbits-service.nix --------- Co-authored-by: Pavol Rusnak --- flake.lock | 52 ++++++++++++++++++++++++++---- flake.nix | 18 ++++++++++- nix/modules/lnbits-service.nix | 2 ++ nix/tests/nixos-module/default.nix | 1 + 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 1aad47069..415efda47 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,15 @@ { "nodes": { "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", "type": "github" }, "original": { @@ -15,6 +18,27 @@ "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": 1678470307, @@ -34,16 +58,17 @@ "poetry2nix": { "inputs": { "flake-utils": "flake-utils", + "nix-github-actions": "nix-github-actions", "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1678513806, - "narHash": "sha256-bEto1lp9bIQ+DlJsXQyRxN5l6B/oy3Skb7DueYRJJBo=", + "lastModified": 1695386222, + "narHash": "sha256-5lgnhCCGW0NH5+m5iTED8u6NSSM/dbH9LBPvX0x0XXg=", "owner": "nix-community", "repo": "poetry2nix", - "rev": "bf239d53fafb53cf439a72b3a50e86dd6a3984a5", + "rev": "093383b3d7fdd36846a7d84e128ca11865800538", "type": "github" }, "original": { @@ -57,6 +82,21 @@ "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" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index a0f9dba42..6d5b9089a 100644 --- a/flake.nix +++ b/flake.nix @@ -28,13 +28,29 @@ }); overlays = { default = final: prev: { - ${projectName} = self.packages.${final.hostPlatform.system}.${projectName}; + ${projectName} = self.packages.${prev.stdenv.hostPlatform.system}.${projectName}; }; }; packages = forAllSystems (system: pkgs: { default = self.packages.${system}.${projectName}; ${projectName} = pkgs.poetry2nix.mkPoetryApplication { projectDir = ./.; + meta.rev = self.dirtyRev or self.rev; + overrides = pkgs.poetry2nix.overrides.withDefaults (final: prev: { + ruff = prev.ruff.override { preferWheel = true; }; + fastapi = prev.fastapi.overridePythonAttrs (old: { + postPatch = '' + substituteInPlace pyproject.toml \ + --replace '"Framework :: Pydantic",' "" \ + --replace '"Framework :: Pydantic :: 1",' "" + ''; + }); + bolt11 = prev.bolt11.overrideAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ + prev.poetry + ]; + }); + }); }; }); nixosModules = { diff --git a/nix/modules/lnbits-service.nix b/nix/modules/lnbits-service.nix index 8e6188e0e..dd9beca27 100644 --- a/nix/modules/lnbits-service.nix +++ b/nix/modules/lnbits-service.nix @@ -88,6 +88,8 @@ in after = [ "network-online.target" ]; environment = { LNBITS_DATA_FOLDER = "${cfg.stateDir}"; + LNBITS_EXTENSIONS_PATH = "${cfg.stateDir}/extensions"; + LNBITS_PATH = "${cfg.package.src}"; }; serviceConfig = { User = cfg.user; diff --git a/nix/tests/nixos-module/default.nix b/nix/tests/nixos-module/default.nix index 868579121..d40e35e7d 100644 --- a/nix/tests/nixos-module/default.nix +++ b/nix/tests/nixos-module/default.nix @@ -1,5 +1,6 @@ { pkgs, makeTest, inputs }: makeTest { + name = "lnbits-nixos-module"; nodes = { client = { config, pkgs, ... }: { environment.systemPackages = [ pkgs.curl ];