-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: main
Are you sure you want to change the base?
Revamp nix flake #215
Changes from all commits
7502029
1d7c7e8
79ddaa4
ae224bf
26819f7
818a758
8ef577e
02f07c3
8889d07
915ed1e
5bf3abb
b21f39f
20f8441
37394b8
caf18fc
052dd15
12ab52a
a0cde88
6489ef4
3155647
1a21071
8177ace
9d5e1c8
ecfa5f1
75c2290
02d75f9
de625e4
5a0f8a6
9ab2820
6ba90b6
c25fec7
a72ea51
66b6854
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having these two functions directly in packages, breaks |
||
}; | ||
|
||
apps = { pinnacle = flake-utils.lib.mkApp { drv = pinnacle; }; }; | ||
|
||
devShells.default = craneLib.devShell { | ||
# Inherit inputs from checks. | ||
checks = self.checks.${system}; | ||
|
||
runtimeDependencies = with pkgs; [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# 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 ]; | ||
}; | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also line 35 hasn't been updated |
||||||
|
||||||
# [root] Install the Lua library (requires Luarocks) | ||||||
install-lua-lib-root: | ||||||
|
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}; | ||
''; | ||
} |
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}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
''; | ||
})) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.