dynix/package.nix

194 lines
4.7 KiB
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2026 Qyriad <qyriad@qyriad.me>
#
# SPDX-License-Identifier: EUPL-1.1
2026-01-21 15:23:04 +01:00
{
2026-02-17 20:17:39 +01:00
lib,
clangStdenv,
callPackage,
linkFarm,
rustHooks,
rustPackages,
versionCheckHook,
2026-03-25 19:12:45 +01:00
writeScript,
2026-02-16 18:02:39 +01:00
}: lib.callWith' rustPackages ({
2026-02-17 20:17:39 +01:00
rustPlatform,
cargo,
2026-01-21 15:23:04 +01:00
}: let
2026-03-22 17:15:04 +01:00
stdenv = clangStdenv;
2026-02-17 20:17:39 +01:00
cargoToml = lib.importTOML ./Cargo.toml;
cargoPackage = cargoToml.package;
2026-02-11 13:19:59 +01:00
in stdenv.mkDerivation (finalAttrs: let
2026-02-17 20:17:39 +01:00
self = finalAttrs.finalPackage;
2026-02-11 13:19:59 +01:00
in {
2026-02-17 20:17:39 +01:00
pname = cargoPackage.name;
version = cargoPackage.version;
strictDeps = true;
__structuredAttrs = true;
outputs = [ "out" "modules" ];
# These are propagated to sub-derivations.
2026-02-17 20:17:39 +01:00
doCheck = true;
doInstallCheck = true;
buildCommand = ''
2026-02-17 20:17:39 +01:00
mkdir -p "$out"
cp -r --reflink=auto "$dynixCommand/"* "$out/"
mkdir -p "$modules"
cp -r --reflink=auto "$dynixModules/"* "$modules/"
2026-03-25 19:12:45 +01:00
install -Dm a=rx "$dynixTestingClient" "$out/libexec/dynix-testing-client.py"
2026-02-17 20:17:39 +01:00
'';
#
# SUB-DERIVATONS
#
2026-03-25 19:12:45 +01:00
dynixTestingClient = writeScript "dynix-testing-client.py" ''
#!/usr/bin/env python3
import socket, sys, os, json
try:
sockpath = sys.argv[1]
except IndexError:
sockpath = f"{os.environ['XDG_RUNTIME_DIR']}/dynix.sock"
sock = socket.socket(family=socket.AF_UNIX)
sock.connect(sockpath)
sock.sendall(sys.stdin.buffer.read())
sock.settimeout(20)
reply = json.loads(sock.recv(256).decode("utf-8"))
print(json.dumps(reply, indent=2))
sys.exit(reply["status"])
'';
2026-03-05 15:44:58 +01:00
dynixCommand = stdenv.mkDerivation {
2026-02-17 20:17:39 +01:00
pname = "${self.pname}-command";
inherit (self) version;
inherit (self) strictDeps __structuredAttrs;
inherit (self) doCheck doInstallCheck;
2026-03-22 17:15:04 +01:00
outputs = [ "out" "doc" ];
2026-02-17 20:17:39 +01:00
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./src
];
};
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
2026-03-22 17:15:04 +01:00
postInstall = ''
cargo doc --document-private-items
mkdir -p "$doc"
cp -r ./target/doc/* "$doc/"
'';
2026-02-17 20:17:39 +01:00
nativeBuildInputs = rustHooks.asList ++ [
cargo
];
nativeInstallCheckInputs = [
versionCheckHook
];
meta = {
mainProgram = "dynix";
description = "The Rust part of Dynix";
inherit (self.meta) license;
2026-02-17 20:17:39 +01:00
};
2026-03-05 15:44:58 +01:00
};
2026-02-17 20:17:39 +01:00
2026-03-05 15:44:58 +01:00
dynixModules = stdenv.mkDerivation {
2026-02-17 20:17:39 +01:00
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
'';
meta = {
description = "The NixOS modules part of Dynix";
inherit (self.meta) license;
};
2026-03-05 15:44:58 +01:00
};
2026-02-17 20:17:39 +01:00
#
# ----------------------------------------------------------------------------
#
passthru.mkDevShell = {
path,
mkShell,
python3Packages,
fenixToolchain,
cargo,
2026-02-17 20:17:39 +01:00
}: let
mkShell' = mkShell.override { inherit stdenv; };
pyEnv = python3Packages.python.withPackages (p: [ p.beartype ]);
# Fenix's Cargo doesn't have completions, but Nixpkgs' does.
cargoCompletions = linkFarm "cargo-bash-completions" {
"share/bash-completion" = cargo + "/share/bash-completion";
};
2026-02-17 20:17:39 +01:00
in mkShell' {
name = "devshell-for-${self.name}";
inputsFrom = [ self ];
packages = [
pyEnv
stdenv.cc
fenixToolchain
cargoCompletions
2026-02-17 20:17:39 +01:00
];
env.PYTHONPATH = [
"${pyEnv}/${pyEnv.sitePackages}"
# Cursed.
"${path}/nixos/lib/test-driver/src"
] |> lib.concatStringsSep ":";
passthru = { inherit cargoCompletions; };
2026-02-17 20:17:39 +01:00
};
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 = [`.
'';
license = with lib.licenses; [ eupl12 ];
2026-02-17 20:17:39 +01:00
mainProgram = "dynix";
outputsToInstall = [ "out" "modules" ];
};
2026-02-16 18:02:39 +01:00
}))