2023-12-19 10:35:34 -06:00
{
2024-07-30 10:06:09 -05:00
inputs = {
nixpkgs . url = " g i t h u b : N i x O S / n i x p k g s / n i x o s - u n s t a b l e " ;
git-hooks . url = " g i t h u b : c a c h i x / g i t - h o o k s . n i x " ;
git-hooks . inputs . nixpkgs . follows = " n i x p k g s " ;
2024-07-31 21:00:21 -05:00
crane . url = " g i t h u b : i p e t k o v / c r a n e " ;
crane . inputs . nixpkgs . follows = " n i x p k g s " ;
rust-overlay . url = " g i t h u b : o x a l i c a / r u s t - o v e r l a y " ;
rust-overlay . inputs . nixpkgs . follows = " n i x p k g s " ;
2024-07-30 10:06:09 -05:00
} ;
2023-12-19 10:35:34 -06:00
outputs = {
self ,
2024-07-30 10:06:09 -05:00
git-hooks ,
2024-07-31 21:00:21 -05:00
rust-overlay ,
crane ,
2023-12-19 10:35:34 -06:00
nixpkgs ,
} : let
2023-12-19 11:17:49 -06:00
inherit ( self ) outputs ;
2024-07-30 10:06:09 -05:00
inherit ( outputs ) overlays ;
systems = [ " a a r c h 6 4 - l i n u x " " a a r c h 6 4 - d a r w i n " " x 8 6 _ 6 4 - d a r w i n " " x 8 6 _ 6 4 - l i n u x " ] ;
forSystems = nixpkgs . lib . genAttrs systems ;
2024-07-31 21:00:21 -05:00
pkgsFor = system : ( ( import nixpkgs { inherit system ; } ) . extend overlays . default ) . extend rust-overlay . overlays . default ;
2024-07-30 10:06:09 -05:00
genPkgs = func : ( forSystems ( system : func ( pkgsFor system ) ) ) ;
2024-07-30 11:55:22 -05:00
buildTimeDeps = pkgs :
2024-07-30 11:45:04 -05:00
with pkgs ; [
pkg-config
clang
mold
wayland
clang
2024-07-30 11:55:22 -05:00
] ;
linkTimeDeps = pkgs :
with pkgs ; [
mold
wayland
clang
2024-07-30 11:45:04 -05:00
udev
alsa-lib
vulkan-loader
libxkbcommon
2024-07-30 11:55:22 -05:00
xorg . libX11
xorg . libXcursor
xorg . libXi
xorg . libXrandr
2024-07-30 11:45:04 -05:00
] ;
2023-12-19 10:35:34 -06:00
in {
2024-07-30 11:16:36 -05:00
checks = genPkgs ( pkgs : {
git-hooks = git-hooks . lib . ${ pkgs . system } . run {
2024-07-30 10:06:09 -05:00
src = ./. ;
hooks = {
alejandra . enable = true ;
2024-07-30 11:16:36 -05:00
# NOTE: These do not work well with `nix flake check` due to pure environments
# https://github.com/cachix/git-hooks.nix/issues/452
# cargo-check.enable = true;
# clippy = {
# enable = true;
# packageOverrides.cargo = pkgs.cargo;
# packageOverrides.clippy = pkgs.rustPackages.clippy;
# };
rustfmt = {
enable = true ;
packageOverrides . rustfmt = pkgs . rustfmt ;
} ;
2024-07-30 10:06:09 -05:00
} ;
} ;
2024-07-30 11:16:36 -05:00
build = outputs . packages . ${ pkgs . system } . default ;
2024-07-30 10:06:09 -05:00
} ) ;
2024-07-31 21:00:21 -05:00
packages = genPkgs ( pkgs : let
2024-08-01 14:02:38 -05:00
rustToolchainFor = p : p . rust-bin . stable . latest . default ;
2024-07-31 21:00:21 -05:00
rustToolchain = rustToolchainFor pkgs ;
craneLib = ( crane . mkLib pkgs ) . overrideToolchain rustToolchainFor ;
src = let
# per https://github.com/ipetkov/crane/blob/529c1a0b1f29f0d78fa3086b8f6a134c71ef3aaf/docs/source-filtering.md we need the font file since we bake it into the binary as the default bevy font
fontFilter = path : _type : builtins . match " . * t t f $ " path != null ;
filteredSources = path : type :
( fontFilter path type ) || ( craneLib . filterCargoSources path type ) ;
in
pkgs . lib . cleanSourceWith {
src = ./. ; # The original, unfiltered source
filter = filteredSources ;
name = " s o u r c e " ; # Be reproducible, regardless of the directory name
} ;
in {
kodotag = craneLib . buildPackage {
inherit src ;
strictDeps = true ;
cargoVendorDir = craneLib . vendorMultipleCargoDeps {
inherit ( craneLib . findCargoFiles src ) cargoConfigs ;
cargoLockList = [
./Cargo.lock
# Unfortunately this approach requires IFD (import-from-derivation)
# otherwise Nix will refuse to read the Cargo.lock from our toolchain
# (unless we build with `--impure`).
#
# Another way around this is to manually copy the rustlib `Cargo.lock`
# to the repo and import it with `./path/to/rustlib/Cargo.lock` which
# will avoid IFD entirely but will require manually keeping the file
# up to date!
" ${ rustToolchain . passthru . availableComponents . rust-src } / l i b / r u s t l i b / s r c / r u s t / C a r g o . l o c k "
] ;
} ;
# cargoExtraArgs = "-Z build-std --target x86_64-unknown-linux-gnu";
nativeBuildInputs = buildTimeDeps pkgs ;
buildInputs = linkTimeDeps pkgs ;
2023-12-19 10:35:34 -06:00
} ;
2024-08-02 21:43:30 -05:00
ZSTD_SYS_USE_PKG_CONFIG = " 1 " ;
LIBSSH2_SYS_USE_PKG_CONFIG = " 1 " ;
RUSTFLAGS = pkgs . lib . optionalString pkgs . stdenv . isLinux " - C l i n k - a r g = - f u s e - l d = m o l d " ;
2024-08-01 14:02:38 -05:00
default = outputs . packages . ${ pkgs . system } . kodotag ;
2023-12-19 10:35:34 -06:00
} ) ;
2024-07-30 10:06:09 -05:00
2024-08-02 21:43:30 -05:00
apps = forSystems ( system : {
kodotag = outputs . packages . ${ system } . kodotag ;
default = outputs . apps . ${ system } . kodotag ;
} ) ;
2024-07-30 11:16:36 -05:00
devShells = genPkgs ( pkgs : {
default = pkgs . mkShell {
inherit ( self . checks . ${ pkgs . system } . git-hooks ) shellHook ;
inputsFrom = [ outputs . packages . ${ pkgs . system } . default ] ;
packages = with pkgs ; [
rustPackages . clippy
rust-analyzer
rustfmt
] ;
2024-07-30 11:55:22 -05:00
LD_LIBRARY_PATH = pkgs . lib . makeLibraryPath ( linkTimeDeps pkgs ) ;
2024-07-30 11:16:36 -05:00
} ;
} ) ;
2024-07-30 10:06:09 -05:00
overlays = {
default = final : prev : { } ;
} ;
formatter = genPkgs ( p : p . alejandra ) ;
2023-12-19 10:35:34 -06:00
} ;
}