160 lines
3.6 KiB
Nix
160 lines
3.6 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;
|
|
|
|
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
|
|
|
src = linkFarm "dynix-source" {
|
|
inherit (self) dynixCommand dynixModules;
|
|
};
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
mkdir -p "$out"
|
|
cp -r --reflink=auto "$dynixCommand/"* "$out/"
|
|
mkdir -p "$modules"
|
|
cp -r --reflink=auto "$dynixModules/"* "$modules/"
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
#
|
|
# SUB-DERIVATONS
|
|
#
|
|
|
|
dynixCommand = stdenv.mkDerivation (finalAttrs: let
|
|
commandSelf = finalAttrs.finalPackage;
|
|
in {
|
|
pname = "${self.pname}-command";
|
|
inherit (self) version;
|
|
inherit (self) strictDeps __structuredAttrs;
|
|
inherit (self) doCheck doInstallCheck;
|
|
|
|
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
|
|
];
|
|
|
|
meta = {
|
|
mainProgram = "dynix";
|
|
};
|
|
});
|
|
|
|
dynixModules = stdenv.mkDerivation (finalAttrs: let
|
|
modulesSelf = finalAttrs.finalPackage;
|
|
in {
|
|
pname = "${self.pname}-modules";
|
|
inherit (self) version;
|
|
inherit (self) strictDeps __structuredAttrs;
|
|
inherit (self) doCheck doInstallCheck;
|
|
|
|
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 ''
|
|
runHook preInstall
|
|
|
|
mkdir -p "$modulesOut"
|
|
cp -r "$src/"* "$modulesOut/"
|
|
|
|
runHook postInstall
|
|
'';
|
|
});
|
|
|
|
#
|
|
# ----------------------------------------------------------------------------
|
|
#
|
|
|
|
passthru.mkDevShell = {
|
|
path,
|
|
mkShell,
|
|
python3Packages,
|
|
fenixToolchain,
|
|
}: let
|
|
mkShell' = mkShell.override { inherit stdenv; };
|
|
pyEnv = python3Packages.python.withPackages (p: [ p.beartype ]);
|
|
in mkShell' {
|
|
name = "devshell-for-${self.name}";
|
|
inputsFrom = [ self ];
|
|
packages = [
|
|
pyEnv
|
|
stdenv.cc
|
|
fenixToolchain
|
|
];
|
|
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 Rust binary.
|
|
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 = [`.
|
|
'';
|
|
mainProgram = "dynix";
|
|
outputsToInstall = [ "out" "modules" ];
|
|
};
|
|
}))
|