From fd7f6e02dbe5b45b5039803c8ff27a02ac25dd03 Mon Sep 17 00:00:00 2001 From: Philippe Loctaux
Date: Sun, 24 Nov 2024 16:38:54 +0100
Subject: [PATCH] nix: do not build docker image, moved plcom and assets in
their own nix modules
---
crates/plcom/assets.nix | 26 +++++
crates/plcom/default.nix | 59 +++++++++++
flake.nix | 205 +++------------------------------------
readme.md | 2 +-
4 files changed, 102 insertions(+), 190 deletions(-)
create mode 100644 crates/plcom/assets.nix
create mode 100644 crates/plcom/default.nix
diff --git a/crates/plcom/assets.nix b/crates/plcom/assets.nix
new file mode 100644
index 0000000..452762a
--- /dev/null
+++ b/crates/plcom/assets.nix
@@ -0,0 +1,26 @@
+{
+ stdenvNoCC,
+ tailwindcss,
+ tailwindProjectRoot,
+ src,
+}:
+
+let
+ tailwindStylesheet = import ./tailwind.nix {
+ stdenvNoCC = stdenvNoCC;
+ tailwindcss = tailwindcss;
+ src = tailwindProjectRoot;
+ inputFile = "css/main.css";
+ };
+
+in
+stdenvNoCC.mkDerivation {
+ name = "plcom-assets";
+ src = src;
+ buildInputs = [ tailwindStylesheet ];
+ installPhase = ''
+ mkdir -p $out
+ cp -r $src/* $out/
+ cp ${tailwindStylesheet}/output.css $out/style.css
+ '';
+}
diff --git a/crates/plcom/default.nix b/crates/plcom/default.nix
new file mode 100644
index 0000000..1b53954
--- /dev/null
+++ b/crates/plcom/default.nix
@@ -0,0 +1,59 @@
+{
+ libiconv,
+ lib,
+ pkg-config,
+ stdenv,
+ craneLib,
+}:
+
+let
+ commonArgs = {
+ src = lib.cleanSourceWith {
+ src = craneLib.path ./.; # The original, unfiltered source
+ filter =
+ path: type:
+ # Assets for codegen
+ (lib.hasSuffix ".json" path)
+ ||
+ # Default filter from crane (allow .rs files)
+ (craneLib.filterCargoSources path type);
+ };
+
+ strictDeps = true;
+
+ buildInputs =
+ [
+ # Add additional build inputs here
+ ]
+ ++ lib.optionals stdenv.isDarwin [
+ libiconv
+ ];
+
+ nativeBuildInputs = [
+ # Add extra native build inputs here, etc.
+ pkg-config
+ ];
+ };
+
+ # Build *just* the cargo dependencies
+ cargoArtifacts = craneLib.buildDepsOnly commonArgs;
+
+ # Clippy
+ clippyArtifacts = craneLib.cargoClippy (
+ commonArgs
+ // {
+ inherit cargoArtifacts;
+ # Again we apply some extra arguments only to this derivation
+ # and not every where else. In this case we add some clippy flags
+ # cargoClippyExtraArgs = "--all-targets -- --deny warnings";
+ }
+ );
+
+in
+craneLib.buildPackage (
+ commonArgs
+ // {
+ cargoExtraArgs = "-p plcom";
+ cargoArtifacts = clippyArtifacts;
+ }
+)
diff --git a/flake.nix b/flake.nix
index c6edf60..db769f9 100644
--- a/flake.nix
+++ b/flake.nix
@@ -13,7 +13,6 @@
outputs =
{
- self,
nixpkgs,
crane,
flake-utils,
@@ -21,209 +20,38 @@
...
}:
flake-utils.lib.eachDefaultSystem (
- localSystem:
+ system:
let
- crossSystem = "aarch64-linux";
pkgs = import nixpkgs {
- inherit crossSystem localSystem;
+ inherit system;
overlays = [ (import rust-overlay) ];
};
- inherit (pkgs) lib;
-
- tailwindStylesheet = import ./crates/plcom/tailwind.nix {
+ # Gather assets
+ plcomAssets = import ./crates/plcom/assets.nix {
stdenvNoCC = pkgs.stdenvNoCC;
tailwindcss = pkgs.tailwindcss;
- src = ./crates/plcom;
- inputFile = "css/main.css";
- };
-
- plcomAssets = pkgs.stdenvNoCC.mkDerivation {
- name = "plcom-assets";
-
- # Local folder as a source
+ tailwindProjectRoot = ./crates/plcom;
src = ./public;
-
- # Build inputs (external derivation dependencies)
- buildInputs = [ tailwindStylesheet ];
-
- installPhase = ''
- mkdir -p $out
- cp -r $src/* $out/
- cp ${tailwindStylesheet}/output.css $out/style.css
- '';
};
+ # Which rust toolchain to use
craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.stable.latest.default);
- # Get metadata from Cargo.toml
- metadata = craneLib.crateNameFromCargoToml { cargoToml = ./crates/plcom/Cargo.toml; };
-
- # TODO: move to its own module
- crateExpression =
- {
- openssl,
- libiconv,
- lib,
- pkg-config,
- qemu,
- stdenv,
- }:
- craneLib.buildPackage (
- metadata
- // {
- src = lib.cleanSourceWith {
- src = craneLib.path ./.; # The original, unfiltered source
- filter =
- path: type:
- # Assets for codegen
- (lib.hasSuffix ".json" path)
- ||
- # Default filter from crane (allow .rs files)
- (craneLib.filterCargoSources path type);
- };
- cargoExtraArgs = "-p plcom";
- strictDeps = true;
-
- # Build-time tools which are target agnostic. build = host = target = your-machine.
- # Emulators should essentially also go `nativeBuildInputs`. But with some packaging issue,
- # currently it would cause some rebuild.
- # We put them here just for a workaround.
- # See: https://github.com/NixOS/nixpkgs/pull/146583
- depsBuildBuild = [
- qemu
- ];
-
- # Dependencies which need to be build for the current platform
- # on which we are doing the cross compilation. In this case,
- # pkg-config needs to run on the build platform so that the build
- # script can find the location of openssl. Note that we don't
- # need to specify the rustToolchain here since it was already
- # overridden above.
- nativeBuildInputs =
- [
- pkg-config
- stdenv.cc
- ]
- ++ lib.optionals stdenv.buildPlatform.isDarwin [
- libiconv
- ];
-
- # Dependencies which need to be built for the platform on which
- # the binary will run. In this case, we need to compile openssl
- # so that it can be linked with our executable.
- buildInputs = [
- # Add additional build inputs here
- openssl
- ];
-
- # Tell cargo about the linker and an optional emulater. So they can be used in `cargo build`
- # and `cargo run`.
- # Environment variables are in format `CARGO_TARGET_