Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp nix flake #215

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7502029
Setup functional flake from crane - will fix later with original flake
nixith Apr 22, 2024
1d7c7e8
change back to original linux only
nixith Apr 22, 2024
79ddaa4
use fenix rust tool chain
nixith Apr 22, 2024
ae224bf
filter builds to allow resources and protobuffs
nixith Apr 22, 2024
26819f7
fix common configuration
nixith Apr 22, 2024
818a758
move to using the whole source - the tiny file size savings aren't wo…
nixith Apr 22, 2024
8ef577e
use inherited src instead of the filtered one
nixith Apr 22, 2024
02f07c3
add other cargo projects in the workspace
nixith Apr 22, 2024
8889d07
use the same formatter as before
nixith Apr 22, 2024
915ed1e
fixup check names
nixith Apr 22, 2024
5bf3abb
disable tests - see comment
nixith Apr 22, 2024
b21f39f
remove hakari
nixith Apr 22, 2024
20f8441
fixup devshell
nixith Apr 22, 2024
37394b8
formatting
nixith Apr 22, 2024
caf18fc
add lua api package
nixith Apr 25, 2024
052dd15
all of the lua config stuff
nixith Apr 25, 2024
12ab52a
pinnacle lua api
nixith Apr 27, 2024
a0cde88
initialize lua config
nixith Apr 27, 2024
6489ef4
drop api version for nixpkgs - need to discuss
nixith Apr 28, 2024
3155647
adapt lua default config for testing
nixith Apr 28, 2024
1a21071
move to correct testing config
nixith Apr 28, 2024
8177ace
move protocols to pinnacle-api-defs
nixith Apr 28, 2024
9d5e1c8
change protobuff location
nixith Apr 28, 2024
ecfa5f1
move functions to lib
nixith Apr 28, 2024
75c2290
change protobuff location
nixith Apr 28, 2024
02d75f9
fix path again
nixith Apr 28, 2024
de625e4
make rust config conform to the same style lua config does
nixith Apr 28, 2024
5a0f8a6
Merge branch 'pinnacle-comp:main' into main
nixith Apr 28, 2024
9ab2820
run formatter
nixith Apr 28, 2024
6ba90b6
Merge branch 'config'
nixith Apr 28, 2024
c25fec7
update flake
nixith Apr 28, 2024
a72ea51
fix lua example from testing value
nixith Apr 28, 2024
66b6854
update justfile to use new protocol location
nixith Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/lua/examples/default/default_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require("pinnacle").setup(function(Pinnacle)
---@type Modifier
local mod_key = "ctrl"

local terminal = "alacritty"
local terminal = "kitty"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna need a very good reason why this has been changed to kitty because I like alacritty better and I will die on that hill

Copy link
Author

@nixith nixith May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, see, the reason is because I'm a creature of habit who forgot to remove that change before commiting. V easy remove lol. It also looks like I forgot to remove some other changes I made in that file for testing purposes.


--------------------
-- Mousebinds --
Expand Down
4 changes: 2 additions & 2 deletions api/lua/pinnacle-api-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ description = {
dependencies = {
"lua >= 5.2",
"cqueues ~> 20200726",
"http ~> 0.4",
"http ~> 0.3",
"lua-protobuf ~> 0.5",
"compat53 ~> 0.13",
"compat53 ~> 0.12-1",
}
build = {
type = "builtin",
Expand Down
75 changes: 48 additions & 27 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

159 changes: 140 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
{
description =
"A WIP Smithay-based Wayland compositor, inspired by AwesomeWM and configured in Lua or Rust";
description = "Build a cargo workspace";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is a copy-paste error :)


inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};

fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? (I've never seen a follows set to "")

};

flake-utils.url = "github:numtide/flake-utils";

advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};

outputs = { nixpkgs, flake-utils, fenix, ... }:
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }:
flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
let
pkgs = nixpkgs.legacyPackages.${system};
fenixPkgs = fenix.packages.${system};
toolchain = fenixPkgs.stable;
combinedToolchain = toolchain.completeToolchain;
in {
formatter = pkgs.nixfmt;
inherit (pkgs) lib;

devShell = pkgs.mkShell {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = with pkgs; [
# rust devel tools
combinedToolchain
rust-analyzer
cargo-outdated
craneLib = (crane.mkLib pkgs).overrideToolchain combinedToolchain;

# wlcs
(writeScriptBin "wlcs" ''
#!/bin/sh
${wlcs}/libexec/wlcs/wlcs "$@"
'')
# Get the relevant files for the rust build
src = lib.cleanSourceWith {
src = ./.; # The original, unfiltered source
filter = path: type:
(lib.hasSuffix ".rockspec" path) || # keep lua in build
(lib.hasInfix "/protocol/" path) || # protobuf stuff
(lib.hasInfix "/resources/" path)
|| # some resources are needed at build time

# Default filter from crane (allow .rs files)
(craneLib.filterCargoSources path type);
};
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;

nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = with pkgs; [
wayland

# build time stuff
Expand All @@ -58,14 +74,119 @@
xorg.libX11
];

# Enironment Variables to set as necessary
PROTOC = "${pkgs.protobuf}/bin/protoc";
};

# Build *just* the cargo dependencies (of the entire workspace),
# so we can reuse all of that work (e.g. via cachix) when running in CI
# It is *highly* recommended to use something like cargo-hakari to avoid
# cache misses when building individual top-level-crates
cargoArtifacts = craneLib.buildDepsOnly commonArgs;

individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
# NB: we disable tests since we'll run them all via cargo-nextest
doCheck = false;
};

# Build the top-level crates of the workspace as individual derivations.
# This allows consumers to only depend on (and build) only what they need.
# Though it is possible to build the entire workspace as a single derivation,
# so this is left up to you on how to organize things
pinnacle = craneLib.buildPackage (individualCrateArgs // {
pname = "pinnacle";
cargoExtraArgs = "-p pinnacle";
inherit src;
});
pinnacle-api-defs = craneLib.buildPackage (individualCrateArgs // {
pname = "pinnacle-api-defs";
cargoExtraArgs = "-p pinnacle-api-defs";
inherit src;
});
pinnacle-api-macros = craneLib.buildPackage (individualCrateArgs // {
pname = "pinnacle-api-macros";
cargoExtraArgs = "-p pinnacle-api-macros";
inherit src;
});
pinnacle-api = craneLib.buildPackage (individualCrateArgs // {
pname = "pinnacle-api";
cargoExtraArgs = "-p pinnacle-api";
inherit src;
});

protobuffs = pkgs.callPackage ./nix/packages/protobuffs.nix { };
luaPinnacleApi = import ./nix/packages/pinnacle-api-lua.nix;

pinnacleLib = import ./nix/lib {
inherit (pkgs) lib newScope;
inherit craneLib pinnacle-api luaPinnacleApi pinnacle protobuffs;
crateArgs = individualCrateArgs;
};

in {
formatter = pkgs.nixfmt;
checks = {
# Build the crates as part of `nix flake check` for convenience
inherit pinnacle pinnacle-api-defs pinnacle-api-macros pinnacle-api;

# Run clippy (and deny all warnings) on the workspace source,
# again, reusing the dependency artifacts from above.
#
# Note that this is done as a separate derivation so that
# we can block the {}CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
pinnacle-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});

pinnacle-doc =
craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; });

# Check formatting
pinnacle-fmt = craneLib.cargoFmt { inherit src; };

# Audit dependencies

pinnacle-audit = craneLib.cargoAudit { inherit src advisory-db; };

# Run tests with cargo-nextest
#
# test currently modify state, so I've disabled them in the check
#
# pinnacle-nextest = craneLib.cargoNextest (commonArgs // {
# inherit cargoArtifacts;
# partitions = 1;
# partitionType = "count";
# });
};
lib = pinnacleLib;
packages = {
inherit pinnacle protobuffs;
inherit (pinnacleLib) pinnacleWithRust pinnacleWithLua;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these two functions directly in packages, breaks nix flake check, because that expects all the packages to be derivations. Maybe we can move them to pinnacle.withRust and pinnacle.withLua using passthru.

};

apps = { pinnacle = flake-utils.lib.mkApp { drv = pinnacle; }; };

devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};

runtimeDependencies = with pkgs; [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the wlcs wrapper script and cargo-outdated got lost along the way, I think

wayland
mesa
libglvnd # libEGL
];

LD_LIBRARY_PATH =
"${pkgs.wayland}/lib:${pkgs.libGL}/lib:${pkgs.libxkbcommon}/lib";
"${pkgs.wayland}/lib:${pkgs.libGL}/lib:${pkgs.libxkbcommon}/${pkgs.libglvnd}/lib:${pkgs.mesa.drivers}/lib";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${pkgs.libxkbcommon}/${pkgs.libglvnd}/lib should probably be ${pkgs.libxkbcommon}/lib:${pkgs.libglvnd}/lib

# Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";

# Extra inputs can be added here; cargo and rustc are provided by default.
packages = [ pkgs.luajitPackages.luarocks ];
};
});
}
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ install-protos-root:
proto_dir="{{root_xdg_data_dir}}/protobuf"
rm -rf "${proto_dir}"
mkdir -p "{{root_xdg_data_dir}}"
cp -r "{{rootdir}}/api/protocol" "${proto_dir}"
cp -r "{{rootdir}}pinnacle-api-defs/protocol" "${proto_dir}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cp -r "{{rootdir}}pinnacle-api-defs/protocol" "${proto_dir}"
cp -r "{{rootdir}}/pinnacle-api-defs/protocol" "${proto_dir}"

Also line 35 hasn't been updated


# [root] Install the Lua library (requires Luarocks)
install-lua-lib-root:
Expand Down
27 changes: 27 additions & 0 deletions nix/lib/buildPinnacleLuaConfig.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ lua, luaPinnacleApi, lib, stdenv, makeWrapper }:
{ src, extraLuaDeps ? [ ], entrypoint ? "init.lua" }:
let
name = "pinnacle-config";
pname = "pinnacle-config";

#luaPackages = lua.pkgs;
luaEnv = lua.withPackages (luaPackages:
let
lp = luaPackages // {
pinnacle =
luaPackages.callPackage ./nix/packages/pinnacle-api-lua.nix { };
};
in (lib.attrVals extraLuaDeps lp)
++ [ (lp.callPackage luaPinnacleApi { }) ]);
in stdenv.mkDerivation {
inherit src name pname;
version = "";
buildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/share/pinnacle/config
cp * $out/share/pinnacle/config/ # placing this here for now, not sure if there's a better space
makeWrapper ${luaEnv}/bin/lua $out/bin/${pname} --add-flags $out/share/pinnacle/config/${entrypoint}
ln $out/bin/${pname} $out/share/pinnacle/config/${pname};
'';
}
14 changes: 14 additions & 0 deletions nix/lib/buildPinnacleRustConfig.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ craneLib, crateArgs, pinnacle-api }:
{ src }:
(craneLib.buildPackage (crateArgs // rec {
inherit src;
inherit (pinnacle-api) cargoArtifacts; # use pinnacle api cargo artifacts
pname = "pinnacle-config";
installPhaseCommand = ''
mkdir -p $out/share/pinnacle/config/
mkdir $out/bin
mv target/release/${pname} $out/bin/
mv metaconfig.toml $out/share/pinnacle/config/
ln $out/bin/${pname} $out/share/pinnacle/config/${pname};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do find this structure in the derivation a bit weird, with the config being in both share/pinnacle/config/pinnacle-config and bin/pinnacle-config. I would expected only next to the metaconfig.toml.

'';
}))
Loading
Loading