dynix/package.nix

121 lines
2.5 KiB
Nix
Raw Normal View History

2026-01-21 15:23:04 +01:00
{
lib,
2026-02-16 18:02:39 +01:00
clangStdenv,
2026-02-11 13:16:54 +01:00
callPackage,
2026-02-11 13:19:59 +01:00
linkFarm,
2026-02-16 18:02:39 +01:00
rustHooks,
rustPackages,
versionCheckHook,
}: lib.callWith' rustPackages ({
rustPlatform,
cargo,
2026-01-21 15:23:04 +01:00
}: let
2026-02-16 18:02:39 +01:00
stdenv = clangStdenv;
cargoToml = lib.importTOML ./Cargo.toml;
cargoPackage = cargoToml.package;
2026-02-11 13:19:59 +01:00
in stdenv.mkDerivation (finalAttrs: let
self = finalAttrs.finalPackage;
in {
2026-02-16 18:02:39 +01:00
pname = cargoPackage.name;
version = cargoPackage.version;
2026-01-21 15:23:04 +01:00
strictDeps = true;
__structuredAttrs = true;
2026-02-11 13:16:54 +01:00
outputs = [ "out" "modules" ];
2026-01-21 15:23:04 +01:00
2026-02-16 18:02:39 +01:00
doCheck = true;
doInstallCheck = true;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./src
];
};
dynixModules = stdenv.mkDerivation (modulesSelf: {
pname = "dynix-modules";
inherit (self) version;
src = lib.fileset.toSource {
root = ./modules/dynamicism;
fileset = lib.fileset.unions [
./modules/dynamicism
];
};
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
modulesOut = "${placeholder "out"}/share/nixos/modules/dynix";
installPhase = lib.dedent ''
mkdir -p "$modulesOut"
cp -r "$src/"* "$modulesOut/"
'';
});
2026-02-16 18:02:39 +01:00
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
2026-01-21 15:23:04 +01:00
2026-02-16 18:02:39 +01:00
nativeBuildInputs = rustHooks.asList ++ [
cargo
];
2026-02-11 13:19:59 +01:00
2026-02-16 18:02:39 +01:00
nativeInstallCheckInputs = [
versionCheckHook
];
2026-01-21 15:23:04 +01:00
postFixup = lib.dedent ''
mkdir -p "$modules"
cp -r --reflink=auto "$dynixModules/"* "$modules/"
2026-02-11 13:16:54 +01:00
'';
2026-01-21 15:23:04 +01:00
passthru.mkDevShell = {
2026-02-11 13:16:54 +01:00
path,
2026-01-21 15:23:04 +01:00
mkShell,
2026-02-11 13:16:54 +01:00
python3Packages,
2026-02-16 18:02:39 +01:00
fenixToolchain,
2026-01-21 15:23:04 +01:00
}: let
2026-02-11 13:16:54 +01:00
mkShell' = mkShell.override { inherit stdenv; };
pyEnv = python3Packages.python.withPackages (p: [
p.beartype
]);
2026-01-21 15:23:04 +01:00
in mkShell' {
2026-02-11 13:19:59 +01:00
name = "devshell-for-${self.name}";
2026-02-16 18:02:39 +01:00
inputsFrom = [ self ];
packages = [
pyEnv
2026-02-16 18:02:39 +01:00
stdenv.cc
fenixToolchain
2026-02-16 18:02:39 +01:00
];
2026-02-11 13:16:54 +01:00
env.PYTHONPATH = [
"${pyEnv}/${pyEnv.sitePackages}"
# Cursed.
"${path}/nixos/lib/test-driver/src"
] |> lib.concatStringsSep ":";
2026-01-21 15:23:04 +01:00
};
2026-02-11 13:19:59 +01:00
passthru.modulesPath = self.modules + "/share/nixos/modules";
2026-02-16 18:02:39 +01:00
passthru.dynix = self.modulesPath + "/dynix";
2026-01-21 15:23:04 +01:00
2026-02-11 13:16:54 +01:00
passthru.tests = lib.fix (callPackage ./tests {
2026-02-11 13:19:59 +01:00
dynix = self;
2026-02-11 13:16:54 +01:00
}).packages;
2026-01-21 15:23:04 +01:00
2026-02-11 13:19:59 +01:00
passthru.allTests = linkFarm "dynix-all-tests" self.tests;
2026-01-21 15:23:04 +01:00
meta = {
2026-02-11 13:19:59 +01:00
longDescription = lib.dedent ''
Default output contains the Rust binary.
2026-02-11 13:19:59 +01:00
The `modules` output contains the modules prefixed under `/share/nixos/modules/dynix`.
The `dynix` passthru attr is a shortcut for the modules output *with* the modules prefix,
and thus `dynix.dynix` can be passed directly to `imports = [`.
2026-02-11 13:19:59 +01:00
'';
2026-02-16 18:02:39 +01:00
mainProgram = "dynix";
outputsToInstall = [ "out" "modules" ];
2026-01-21 15:23:04 +01:00
};
2026-02-16 18:02:39 +01:00
}))