From 26ec66d03eea8fadad94386e93a2c2b2cd57be97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sat, 13 Aug 2022 21:44:31 +0100 Subject: [PATCH] Refactor and update flake --- flake.lock | 130 ++++++++++++++++++++++++++++++++++++++++++++++------- flake.nix | 116 +++++++++++++++++++++++++---------------------- 2 files changed, 176 insertions(+), 70 deletions(-) diff --git a/flake.lock b/flake.lock index af26285..ee0c0e3 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,26 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1653893745, - "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1631561581, + "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19", "type": "github" }, "original": { @@ -22,11 +37,32 @@ ] }, "locked": { - "lastModified": 1655042882, - "narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=", + "lastModified": 1659610603, + "narHash": "sha256-LYgASYSPYo7O71WfeUOaEUzYfzuXm8c8eavJcel+pfI=", "owner": "nmattia", "repo": "naersk", - "rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f", + "rev": "c6a45e4277fa58abd524681466d3450f896dc094", + "type": "github" + }, + "original": { + "owner": "nmattia", + "repo": "naersk", + "type": "github" + } + }, + "naersk_2": { + "inputs": { + "nixpkgs": [ + "tlaternet-templates", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1632266297, + "narHash": "sha256-J1yeJk6Gud9ef2pEf6aKQemrfg1pVngYDSh+SAY94xk=", + "owner": "nmattia", + "repo": "naersk", + "rev": "ee7edec50b49ab6d69b06d62f1de554efccb1ccd", "type": "github" }, "original": { @@ -37,11 +73,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1655200170, - "narHash": "sha256-/yzkX+10sJhYNIcTtZ5ObS+nh/HrJp01XLaubzbRDcU=", + "lastModified": 1660318005, + "narHash": "sha256-g9WCa9lVUmOV6dYRbEPjv/TLOR5hamjeCcKExVGS3OQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "9ff91ce2e4c5d70551d4c8fd8830931c6c6b26b8", + "rev": "5c211b47aeadcc178c5320afd4e74c7eed5c389f", "type": "github" }, "original": { @@ -51,29 +87,43 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1632408697, + "narHash": "sha256-JqTfu361AwFmV0WszXLAjfukqGxBbHRopRgdp9A2w8s=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a13824fe5e38187fbc75cd598b5c06bdcc13501f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-20.09", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { - "flake-utils": "flake-utils", "naersk": "naersk", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "tlaternet-templates": "tlaternet-templates" } }, "rust-overlay": { "inputs": { - "flake-utils": [ - "flake-utils" - ], + "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1655261370, - "narHash": "sha256-AxKkHEuOgV/PyK+T6NOE4QyDHmZO+/XVyp0AtmrIoV0=", + "lastModified": 1660358625, + "narHash": "sha256-uv+ZtOAEeM5tw78CLdRQmbZyDZYc0piSflthG2kNnrc=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "d62021584e798dd9e169f543dd3f1296f5216d0c", + "rev": "18354cce8137aaef0d505d6f677e9bbdd542020d", "type": "github" }, "original": { @@ -81,6 +131,52 @@ "repo": "rust-overlay", "type": "github" } + }, + "rust-overlay_2": { + "inputs": { + "flake-utils": [ + "tlaternet-templates", + "flake-utils" + ], + "nixpkgs": [ + "tlaternet-templates", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1633400100, + "narHash": "sha256-kHQV7jZ2vVHVI9sfda1mUROVBbQbdfKcbIpKG9WdqGo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "9c2fc6a62ccbc6f420d71ecac6bf0b84dbbee64f", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "tlaternet-templates": { + "inputs": { + "flake-utils": "flake-utils_2", + "naersk": "naersk_2", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay_2" + }, + "locked": { + "lastModified": 1633433130, + "narHash": "sha256-jkW+HV8cJvE86gppOEXQl2ke+bDHJ7SAp8eJp8pJ0N8=", + "ref": "master", + "rev": "1232950c06ae16bf17fb16ac1f5f2231e971936b", + "revCount": 16, + "type": "git", + "url": "https://gitea.tlater.net/tlaternet/tlaternet.git" + }, + "original": { + "type": "git", + "url": "https://gitea.tlater.net/tlaternet/tlaternet.git" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index b16ecf2..8e5c476 100644 --- a/flake.nix +++ b/flake.nix @@ -3,70 +3,80 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05"; - flake-utils.url = "github:numtide/flake-utils"; rust-overlay = { url = "github:oxalica/rust-overlay"; - inputs = { - flake-utils.follows = "flake-utils"; - nixpkgs.follows = "nixpkgs"; - }; + inputs.nixpkgs.follows = "nixpkgs"; }; naersk = { url = "github:nmattia/naersk"; inputs.nixpkgs.follows = "nixpkgs"; }; + + tlaternet-templates = { + url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git"; + # No need to override anything here; we can save some downloads + # if we rely on the webserver to do that. + }; }; - outputs = { self, nixpkgs, flake-utils, rust-overlay, naersk }@inputs: - flake-utils.lib.simpleFlake { - inherit self nixpkgs; - name = "tlaternet-webserver"; - preOverlays = [ rust-overlay.overlay ]; + outputs = { + self, + nixpkgs, + rust-overlay, + naersk, + tlaternet-templates, + }: let + # At the moment, we only deploy to x86_64-linux. Update when we + # care about another platform. + system = "x86_64-linux"; + overlays = [ + rust-overlay.overlays.default + ]; + pkgs = import nixpkgs {inherit system overlays;}; - overlay = final: prev: { - tlaternet-webserver = let - # The rust toolchain to use - toolchain = - prev.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + # Rust build config + rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + naersk-lib = naersk.lib.${system}.override { + cargo = rust-toolchain; + rustc = rust-toolchain; + }; + buildInputs = with pkgs; [ + pkg-config + openssl + ]; + in { + packages.${system} = rec { + tlaternet-webserver = naersk-lib.buildPackage { + inherit buildInputs; + pname = "tlaternet-webserver"; + root = pkgs.lib.cleanSource self; + }; + default = tlaternet-webserver; + }; - # The rust build lib, set to use the toolchain - naersk-lib = naersk.lib.${prev.system}.override { - cargo = toolchain; - rustc = toolchain; - }; - - # pkg-config, needed to include many native libs - nativeBuildInputs = [ prev.pkgconfig ]; - - # Native libs - buildInputs = [ prev.openssl ]; - - in rec { - # The packages provided by this flake - packages = { - webserver = prev.callPackage - ({ rustPlatform, openssl, pkgconfig, ... }: - naersk-lib.buildPackage { - inherit nativeBuildInputs buildInputs; - - pname = "tlaternet-webserver"; - root = ./.; - }) { }; - }; - defaultPackage = packages.webserver; - - # A dev shell to hack manually; note this includes - # additional toolchain components - devShell = prev.mkShell { - inherit buildInputs; - nativeBuildInputs = nativeBuildInputs ++ [ - (toolchain.override { - extensions = - [ "rust-src" "rust-analysis" "rust-analyzer-preview" ]; - }) - ]; - }; - }; + apps.${system} = { + run-with-templates = let + script = pkgs.writeShellScriptBin "run-with-templates" '' + export ROCKET_TEMPLATE_DIR=${tlaternet-templates.packages.${system}.tlaternet-templates} + ${self.packages.${system}.tlaternet-webserver}/bin/tlaternet-webserver + ''; + in { + type = "app"; + program = "${script}/bin/run-with-templates"; }; }; + + devShells.${system} = { + default = pkgs.mkShell { + packages = builtins.concatLists [ + buildInputs + [ + (rust-toolchain.override { + extensions = ["rust-src" "rust-analysis" "rust-analyzer-preview"]; + }) + ] + ]; + }; + }; + }; }