dynix/package.nix
2026-02-16 19:05:02 +01:00

106 lines
2.1 KiB
Nix

{
lib,
clangStdenv,
callPackage,
linkFarm,
rustHooks,
rustPackages,
versionCheckHook,
}: lib.callWith' rustPackages ({
rustPlatform,
cargo,
}: let
stdenv = clangStdenv;
cargoToml = lib.importTOML ./Cargo.toml;
cargoPackage = cargoToml.package;
in stdenv.mkDerivation (finalAttrs: let
self = finalAttrs.finalPackage;
in {
pname = cargoPackage.name;
version = cargoPackage.version;
strictDeps = true;
__structuredAttrs = true;
outputs = [ "out" "modules" ];
doCheck = true;
doInstallCheck = true;
modulesSrc = lib.fileset.toSource {
root = ./modules/dynamicism;
fileset = lib.fileset.unions [
./modules/dynamicism
];
};
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./src
];
};
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = rustHooks.asList ++ [
cargo
];
nativeInstallCheckInputs = [
versionCheckHook
];
modulesOut = "${placeholder "modules"}/share/nixos/modules/dynix";
postInstall = lib.dedent ''
mkdir -p "$modulesOut"
cp -r "$modulesSrc/"* "$modulesOut/"
'';
passthru.mkDevShell = {
path,
mkShell,
python3Packages,
}: let
mkShell' = mkShell.override { inherit stdenv; };
pyEnv = python3Packages.python.withPackages (p: [
p.beartype
]);
in mkShell' {
name = "devshell-for-${self.name}";
inputsFrom = [ self ];
packages = [
pyEnv
rustPackages.rustc
rustPackages.rustfmt
];
env.PYTHONPATH = [
"${pyEnv}/${pyEnv.sitePackages}"
# Cursed.
"${path}/nixos/lib/test-driver/src"
] |> lib.concatStringsSep ":";
};
passthru.modulesPath = self.modules + "/share/nixos/modules";
passthru.dynix = self.modulesPath + "/dynix";
passthru.tests = lib.fix (callPackage ./tests {
dynix = self;
}).packages;
passthru.allTests = linkFarm "dynix-all-tests" self.tests;
meta = {
longDescription = lib.dedent ''
Default output contains the modules at top-level, meant for `import`.
The `modules` output contains the modules prefixed under `/share/nixos/modules/dynix`.
'';
mainProgram = "dynix";
outputsToInstall = [ "out" "modules" ];
};
}))