build: use flake from templates
This commit is contained in:
parent
11d99931f8
commit
430308a2de
2 changed files with 78 additions and 118 deletions
36
flake.lock
generated
36
flake.lock
generated
|
|
@ -1,30 +1,15 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1785782307,
|
|
||||||
"narHash": "sha256-MPaRdVkf6zZP5fCPxYCi8Dr4pZzgmXzg8T9nVEbp3Mw=",
|
|
||||||
"owner": "ipetkov",
|
|
||||||
"repo": "crane",
|
|
||||||
"rev": "2c71e194474d13de031d729b729c968ddbe3507f",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "ipetkov",
|
|
||||||
"repo": "crane",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1731533236,
|
"lastModified": 1794427683,
|
||||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
"narHash": "sha256-o7ey9gEilsxaifqJWnBDlYSKbNWYQYtKwDyXeZU2kaU=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
"rev": "cd489559845d81f673a12885576016c65cbe9363",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -35,11 +20,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1786862985,
|
"lastModified": 1795234589,
|
||||||
"narHash": "sha256-kSR/jfpR4cE26YRZ8exQkoRbEA30vyWimajwZANYYaE=",
|
"narHash": "sha256-pAEASBc6wof0S58XcSEdZoQ2iFQDkCnZwH+wFLrkd1Q=",
|
||||||
"rev": "e5bdc4a41d4c072fe1e3787eaa0320a384741d44",
|
"rev": "2786a2a72088ecf32aea5b3ec52099e6a7cff78f",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1055335.e5bdc4a41d4c/nixexprs.tar.zst?lastModified=1786862985&rev=e5bdc4a41d4c072fe1e3787eaa0320a384741d44"
|
"url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1125864.2786a2a72088/nixexprs.tar.zst?lastModified=1795234589&rev=2786a2a72088ecf32aea5b3ec52099e6a7cff78f"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
|
|
@ -48,18 +33,17 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"crane": "crane",
|
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681028828,
|
"lastModified": 1791244623,
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
"narHash": "sha256-uuanbkFk8a313Zfrxdcz8Us/yQtaxNnKJtX8v0ZPpd8=",
|
||||||
"owner": "nix-systems",
|
"owner": "nix-systems",
|
||||||
"repo": "default",
|
"repo": "default",
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
"rev": "d36eeed142f88b5a636f2e3856a53c61654cf29b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
138
flake.nix
138
flake.nix
|
|
@ -2,8 +2,6 @@
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst";
|
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst";
|
||||||
|
|
||||||
crane.url = "github:ipetkov/crane";
|
|
||||||
|
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -12,105 +10,83 @@
|
||||||
inputs.flake-utils.lib.eachDefaultSystem (
|
inputs.flake-utils.lib.eachDefaultSystem (
|
||||||
system:
|
system:
|
||||||
let
|
let
|
||||||
pkgs = import inputs.nixpkgs { inherit system; };
|
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
||||||
lib = pkgs.lib;
|
lib = inputs.nixpkgs.lib;
|
||||||
craneLib = inputs.crane.mkLib pkgs;
|
|
||||||
|
|
||||||
cargoToml = fromTOML (builtins.readFile ./Cargo.toml);
|
src = lib.sourceFilesBySuffices ./. [
|
||||||
|
"Cargo.toml"
|
||||||
|
"Cargo.lock"
|
||||||
|
".rs"
|
||||||
|
];
|
||||||
|
|
||||||
|
cargoToml = fromTOML (builtins.readFile "${src}/Cargo.toml");
|
||||||
name = cargoToml.package.name;
|
name = cargoToml.package.name;
|
||||||
|
|
||||||
dlDeps =
|
bin =
|
||||||
with pkgs;
|
{
|
||||||
[
|
rustPlatform,
|
||||||
# needed for both x11 and wayland
|
|
||||||
libxkbcommon
|
|
||||||
libGL
|
|
||||||
|
|
||||||
|
autoPatchelfHook,
|
||||||
|
|
||||||
|
libxkbcommon,
|
||||||
|
wayland,
|
||||||
|
vulkan-loader,
|
||||||
|
|
||||||
|
moreSupport ? false,
|
||||||
|
libGL,
|
||||||
|
libx11,
|
||||||
|
libxcursor,
|
||||||
|
libxi,
|
||||||
|
|
||||||
|
libgcc,
|
||||||
|
}:
|
||||||
|
rustPlatform.buildRustPackage {
|
||||||
|
inherit name src;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
autoPatchelfHook
|
||||||
|
];
|
||||||
|
buildInputs = [
|
||||||
|
libgcc
|
||||||
|
];
|
||||||
|
runtimeDependencies = [
|
||||||
|
libxkbcommon
|
||||||
|
wayland
|
||||||
|
vulkan-loader
|
||||||
|
]
|
||||||
|
++ lib.optionals moreSupport [
|
||||||
|
libGL
|
||||||
libx11
|
libx11
|
||||||
libxcursor
|
libxcursor
|
||||||
libxi
|
libxi
|
||||||
libxcb
|
|
||||||
]
|
|
||||||
++ lib.optionals stdenv.hostPlatform.isLinux [
|
|
||||||
vulkan-loader
|
|
||||||
wayland
|
|
||||||
|
|
||||||
dbus.lib
|
|
||||||
];
|
];
|
||||||
|
|
||||||
commonArgs = {
|
cargoLock.lockFile = "${src}/Cargo.lock";
|
||||||
# all that's needed for artifacts and checks
|
|
||||||
nativeBuildInputs = with pkgs; [
|
|
||||||
# pkg-config
|
|
||||||
];
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
];
|
|
||||||
|
|
||||||
strictDeps = true;
|
strictDeps = true;
|
||||||
__structuredAttrs = true;
|
__structuredAttrs = true;
|
||||||
|
|
||||||
src = ./.;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Build *just* the cargo dependencies,
|
default = pkgs.callPackage bin { };
|
||||||
# to reuse them for build and test derivations.
|
|
||||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
||||||
|
|
||||||
# Build the actual crate itself,
|
|
||||||
# reusing the dependency artifacts from above.
|
|
||||||
crate =
|
|
||||||
let
|
|
||||||
desktopItem = pkgs.makeDesktopItem {
|
|
||||||
inherit name;
|
|
||||||
desktopName = name;
|
|
||||||
exec = name;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
craneLib.buildPackage (
|
|
||||||
commonArgs
|
|
||||||
// {
|
|
||||||
inherit cargoArtifacts;
|
|
||||||
|
|
||||||
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
|
|
||||||
pkgs.autoPatchelfHook
|
|
||||||
];
|
|
||||||
|
|
||||||
buildInputs = commonArgs.buildInputs ++ [
|
|
||||||
pkgs.libgcc
|
|
||||||
];
|
|
||||||
|
|
||||||
runtimeDependencies = dlDeps;
|
|
||||||
|
|
||||||
doCheck = false;
|
|
||||||
|
|
||||||
postFixup = ''
|
|
||||||
cp -rs "${desktopItem}"/* "$out"
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
);
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.default = crate;
|
packages.default = default;
|
||||||
|
|
||||||
checks = {
|
devShells.default = pkgs.mkShell {
|
||||||
crate-clippy = craneLib.cargoClippy (
|
inputsFrom = [ default ];
|
||||||
commonArgs
|
|
||||||
// {
|
|
||||||
inherit cargoArtifacts;
|
|
||||||
|
|
||||||
cargoClippyExtraArgs = "-- --deny warnings";
|
env.RUSTFLAGS = builtins.concatStringsSep " " [
|
||||||
}
|
"-Clink-arg=-Wl,-rpath,${lib.makeLibraryPath default.runtimeDependencies}"
|
||||||
);
|
"-Clink-arg=-fuse-ld=mold"
|
||||||
};
|
];
|
||||||
|
|
||||||
devShells.default = craneLib.devShell {
|
packages = with pkgs; [
|
||||||
env.LD_LIBRARY_PATH = lib.makeLibraryPath dlDeps;
|
clippy
|
||||||
|
rustfmt
|
||||||
|
rust-analyzer
|
||||||
|
|
||||||
inputsFrom = [ crate ];
|
mold
|
||||||
packages = [ pkgs.rust-analyzer ];
|
];
|
||||||
|
|
||||||
strictDeps = true;
|
|
||||||
__structuredAttrs = true;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue