# SPDX-FileCopyrightText: 2026 Qyriad # # SPDX-License-Identifier: EUPL-1.1 { lib, clangStdenv, callPackage, linkFarm, llvmPackages, rustHooks, rustPackages, versionCheckHook, wrapBintoolsWith, }: lib.callWith' rustPackages ({ rustPlatform, cargo, }: let # Use LLD for faster link times. stdenv = clangStdenv.override { cc = clangStdenv.cc.override { bintools = wrapBintoolsWith { bintools = llvmPackages.bintools; }; }; }; 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" ]; # These are propagated to sub-derivations. doCheck = true; doInstallCheck = true; buildCommand = '' mkdir -p "$out" cp -r --reflink=auto "$dynixCommand/"* "$out/" mkdir -p "$modules" cp -r --reflink=auto "$dynixModules/"* "$modules/" ''; # # SUB-DERIVATONS # dynixCommand = stdenv.mkDerivation { 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"; description = "The Rust part of Dynix"; inherit (self.meta) license; }; }; dynixModules = stdenv.mkDerivation { 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; }; }; # # ---------------------------------------------------------------------------- # passthru.mkDevShell = { path, mkShell, python3Packages, fenixToolchain, cargo, }: 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"; }; in mkShell' { name = "devshell-for-${self.name}"; inputsFrom = [ self ]; packages = [ pyEnv stdenv.cc fenixToolchain cargoCompletions ]; env.PYTHONPATH = [ "${pyEnv}/${pyEnv.sitePackages}" # Cursed. "${path}/nixos/lib/test-driver/src" ] |> lib.concatStringsSep ":"; passthru = { inherit cargoCompletions; }; }; 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 ]; mainProgram = "dynix"; outputsToInstall = [ "out" "modules" ]; }; }))