flake.nix: build with crane for vm
All checks were successful
Build and test / check (push) Successful in 1m30s
Build and test / build (push) Successful in 3m56s
Build and test / test (push) Successful in 2m55s
Build and test / check-license (push) Successful in 5m32s
Build and test / docs (push) Successful in 6m47s

This commit is contained in:
2025-11-26 01:10:01 +09:00
parent 412e5c1604
commit 39fa228d1c
3 changed files with 47 additions and 17 deletions

16
flake.lock generated
View File

@@ -1,5 +1,20 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1763938834,
"narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=",
"owner": "ipetkov",
"repo": "crane",
"rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1762363567,
@@ -18,6 +33,7 @@
},
"root": {
"inputs": {
"crane": "crane",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}

View File

@@ -4,9 +4,11 @@
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
};
outputs = { self, nixpkgs, rust-overlay }:
outputs = { self, nixpkgs, rust-overlay, crane }:
let
inherit (nixpkgs) lib;
@@ -61,6 +63,9 @@
mysqladm-rs = final: prev: {
inherit (self.packages.${prev.stdenv.hostPlatform.system}) mysqladm-rs;
};
mysqladm-rs-crane = final: prev: {
mysqladm-rs = self.packages.${prev.stdenv.hostPlatform.system}.mysqladm-rs-crane;
};
};
nixosModules = {
@@ -68,21 +73,24 @@
mysqladm-rs = import ./nix/module.nix;
};
packages = let
packages = forAllSystems (system: pkgs: _:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cargoLock = ./Cargo.lock;
src = builtins.filterSource (path: type: let
baseName = baseNameOf (toString path);
in !(lib.any (b: b) [
(!(lib.cleanSourceFilter path type))
(baseName == "target" && type == "directory")
(baseName == "nix" && type == "directory")
(baseName == "flake.nix" && type == "regular")
(baseName == "flake.lock" && type == "regular")
])) ./.;
in forAllSystems (system: pkgs: _: {
default = self.packages.${system}.mysqladm-rs;
craneLib = crane.mkLib pkgs;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
];
};
in {
default = self.packages.${system}.mysqladm-rs-crane;
mysqladm-rs = pkgs.callPackage ./nix/default.nix { inherit cargoToml cargoLock src; };
mysqladm-rs-crane = pkgs.callPackage ./nix/default.nix {
useCrane = true;
inherit cargoToml cargoLock src craneLib;
};
coverage = pkgs.callPackage ./nix/coverage.nix { inherit cargoToml cargoLock src; };
filteredSource = pkgs.runCommandLocal "filtered-source" { } ''
ln -s ${src} $out
@@ -94,7 +102,7 @@
pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [
self.overlays.default
self.overlays.mysqladm-rs-crane
];
};
modules = [

View File

@@ -5,16 +5,22 @@
, cargoLock
, src
, installShellFiles
, useCrane ? false
, craneLib ? null
}:
let
mainProgram = (lib.head cargoToml.bin).name;
buildFunction = if useCrane then craneLib.buildPackage else rustPlatform.buildRustPackage;
cargoLock' = if useCrane then cargoLock else { lockFile = cargoLock; };
pname = if useCrane then "${cargoToml.package.name}-crane" else cargoToml.package.name;
in
rustPlatform.buildRustPackage {
pname = cargoToml.package.name;
buildFunction {
pname = pname;
version = cargoToml.package.version;
inherit src;
cargoLock.lockFile = cargoLock;
cargoLock = cargoLock';
nativeBuildInputs = [ installShellFiles ];
postInstall = let