WIP: nix package

This commit is contained in:
2026-04-25 19:29:13 +09:00
parent 1f68f0df5d
commit a7c00b3220
3 changed files with 127 additions and 1 deletions
Generated
+16
View File
@@ -1,5 +1,20 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1776635034,
"narHash": "sha256-OEOJrT3ZfwbChzODfIH4GzlNTtOFuZFWPtW7jIeR8xU=",
"owner": "ipetkov",
"repo": "crane",
"rev": "dc7496d8ea6e526b1254b55d09b966e94673750f",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1776877367,
@@ -18,6 +33,7 @@
},
"root": {
"inputs": {
"crane": "crane",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
+29 -1
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;
@@ -31,6 +33,32 @@
};
in f system pkgs toolchain);
in {
apps = forAllSystems (system: _: _: {
default = self.apps.${system}.kagami;
kagami = {
type = "app";
program = lib.getExe self.packages.${system}.kagami;
};
});
packages = forAllSystems (system: pkgs: _: {
default = self.packages.${system}.kagami;
kagami = let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cargoLock = ./Cargo.lock;
craneLib = crane.mkLib pkgs;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
];
};
in pkgs.callPackage ./nix/package.nix {
useCrane = true;
inherit cargoToml cargoLock src craneLib;
};
});
devShells = forAllSystems (system: pkgs: toolchain: {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
+82
View File
@@ -0,0 +1,82 @@
{
lib
, rustPlatform
, stdenv
, buildPackages
, installShellFiles
, versionCheckHook
, pkg-config
, openssl
, cargoToml
, cargoLock
, src
, useCrane ? false
, craneLib ? null
}:
let
mainProgram = (lib.head cargoToml.bin).name;
buildFunction = if useCrane then craneLib.buildPackage else rustPlatform.buildRustPackage;
pnameCraneSuffix = lib.optionalString useCrane "-crane";
pname = "${cargoToml.package.name}${pnameCraneSuffix}";
rustPlatformArgs = {
buildType = "release-lto";
cargoLock.lockFile = cargoLock;
doCheck = true;
useNextest = true;
nativeCheckInputs = [
versionCheckHook
];
};
craneArgs = {
cargoLock = cargoLock;
cargoArtifacts = craneLib.buildDepsOnly {
inherit pname;
inherit (cargoToml.package) version;
src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.unions [
(craneLib.fileset.cargoTomlAndLock ../.)
];
};
cargoLock = cargoLock;
};
};
in
buildFunction ({
inherit pname;
inherit (cargoToml.package) version;
inherit src;
nativeBuildInputs = [
installShellFiles
pkg-config
];
buildInputs = [
openssl
];
postInstall = let
emulatorAvailable = stdenv.hostPlatform.emulatorAvailable buildPackages;
emulator = stdenv.hostPlatform.emulator buildPackages;
in lib.optionalString emulatorAvailable ''
installShellCompletion --cmd ty \
--bash <(${emulator} $out/bin/kagami generate-completions --shell bash) \
--fish <(${emulator} $out/bin/kagami generate-completions --shell fish) \
--zsh <(${emulator} $out/bin/kagami generate-completions --shell zsh)
'';
meta = with lib; {
license = licenses.bsd3;
platforms = platforms.unix ++ platforms.windows;
inherit mainProgram;
};
}
//
(if useCrane then craneArgs else rustPlatformArgs)
)