Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f33eee054f |
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 1,
|
|
||||||
"sourceRepo": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos.git",
|
|
||||||
"sourceCommit": "8354a2e04f56eea0a647e878ca19c5398c1e1f89",
|
|
||||||
"sourcePath": "quixos-instance/quixos-nix-helpers",
|
|
||||||
"exportName": "quixos-nix-helpers",
|
|
||||||
"mirrorRemote": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos-nix-helpers.git"
|
|
||||||
}
|
|
||||||
+1
-202
@@ -491,208 +491,7 @@ EOF
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
mkCaminoSourcePackage =
|
|
||||||
{
|
|
||||||
pkgs,
|
|
||||||
src,
|
|
||||||
name ? "quixos-package-source",
|
|
||||||
}:
|
|
||||||
pkgs.stdenvNoCC.mkDerivation {
|
|
||||||
inherit name;
|
|
||||||
src = pkgs.lib.cleanSource src;
|
|
||||||
dontConfigure = true;
|
|
||||||
dontBuild = true;
|
|
||||||
installPhase = ''
|
|
||||||
runHook preInstall
|
|
||||||
cp -R . "$out"
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
mkCaminoTsYarnNixifyFlake =
|
|
||||||
{
|
|
||||||
inputs,
|
|
||||||
nixpkgs,
|
|
||||||
flake-utils,
|
|
||||||
packageRoot,
|
|
||||||
packageName ? null,
|
|
||||||
sourceName ? "quixos-package-source",
|
|
||||||
promptName ? null,
|
|
||||||
nodejsAttr ? "nodejs_24",
|
|
||||||
buildCommand ? "yarn build",
|
|
||||||
sourcePortals ? { },
|
|
||||||
buildEnv ? { },
|
|
||||||
nativeBuildInputs ? [ ],
|
|
||||||
devShellPackages ? [ ],
|
|
||||||
devShellHook ? "",
|
|
||||||
bundle ? null,
|
|
||||||
installServer ? null,
|
|
||||||
}:
|
|
||||||
flake-utils.lib.eachDefaultSystem (
|
|
||||||
system:
|
|
||||||
let
|
|
||||||
pkgs = import nixpkgs { inherit system; };
|
|
||||||
lib = pkgs.lib;
|
|
||||||
nodejs = pkgs.${nodejsAttr};
|
|
||||||
|
|
||||||
callOption = value:
|
|
||||||
if builtins.isFunction value
|
|
||||||
then value { inherit inputs pkgs system; }
|
|
||||||
else value;
|
|
||||||
|
|
||||||
packageJson = builtins.fromJSON (builtins.readFile "${packageRoot}/package.json");
|
|
||||||
packageNameFinal = if packageName != null then packageName else packageJson.name or "quixos-package";
|
|
||||||
promptNameFinal =
|
|
||||||
if promptName != null
|
|
||||||
then promptName
|
|
||||||
else lib.strings.sanitizeDerivationName packageNameFinal;
|
|
||||||
|
|
||||||
sourcePackage = mkCaminoSourcePackage {
|
|
||||||
inherit pkgs;
|
|
||||||
src = packageRoot;
|
|
||||||
name = sourceName;
|
|
||||||
};
|
|
||||||
|
|
||||||
exportsFor = attrs:
|
|
||||||
lib.concatStringsSep "\n" (
|
|
||||||
lib.mapAttrsToList
|
|
||||||
(name: value: "export ${name}=${lib.escapeShellArg (toString value)}")
|
|
||||||
attrs
|
|
||||||
);
|
|
||||||
|
|
||||||
portalLinksFor = attrs:
|
|
||||||
lib.concatStringsSep "\n" (
|
|
||||||
lib.mapAttrsToList
|
|
||||||
(target: source: "ln -sfn ${source} ${lib.escapeShellArg target}")
|
|
||||||
attrs
|
|
||||||
);
|
|
||||||
|
|
||||||
bundleConfig = if bundle == null then { } else bundle;
|
|
||||||
bundleOutfile = bundleConfig.outfile or "server.mjs";
|
|
||||||
bundlePlatform = bundleConfig.platform or "node";
|
|
||||||
bundleTarget = bundleConfig.target or "node24";
|
|
||||||
bundleFormat = bundleConfig.format or "esm";
|
|
||||||
bundleBanner = bundleConfig.banner or nodeRequireBanner;
|
|
||||||
bundleAliases = bundleConfig.aliases or {
|
|
||||||
"@automerge/automerge" = "./node_modules/@automerge/automerge/dist/mjs/entrypoints/fullfat_base64.js";
|
|
||||||
};
|
|
||||||
bundleAliasArgs = lib.concatStringsSep " " (
|
|
||||||
lib.mapAttrsToList
|
|
||||||
(from: to: "--alias:${from}=${lib.escapeShellArg to}")
|
|
||||||
bundleAliases
|
|
||||||
);
|
|
||||||
nodeRequireBanner = "import { createRequire } from 'module';const require = createRequire(import.meta.url);";
|
|
||||||
bundleCommand =
|
|
||||||
if bundle == null
|
|
||||||
then ""
|
|
||||||
else ''
|
|
||||||
esbuild ${lib.escapeShellArg bundleConfig.entry} \
|
|
||||||
--bundle \
|
|
||||||
--platform=${bundlePlatform} \
|
|
||||||
--target=${bundleTarget} \
|
|
||||||
--format=${bundleFormat} \
|
|
||||||
${bundleAliasArgs} \
|
|
||||||
${lib.optionalString (bundleConfig.preserveSymlinks or true) "--preserve-symlinks \\"}
|
|
||||||
--banner:js=${lib.escapeShellArg bundleBanner} \
|
|
||||||
--outfile=${lib.escapeShellArg bundleOutfile}
|
|
||||||
'';
|
|
||||||
|
|
||||||
installConfig = if installServer == null then { } else installServer;
|
|
||||||
serverBin = installConfig.binName or "server";
|
|
||||||
serverLibexecName =
|
|
||||||
installConfig.libexecName or (lib.strings.sanitizeDerivationName packageNameFinal);
|
|
||||||
serverFile = installConfig.serverFile or bundleOutfile;
|
|
||||||
descriptorPath = installConfig.descriptorPath or "descriptor.quixos-package.txtpb";
|
|
||||||
extraFiles = installConfig.extraFiles or [ ];
|
|
||||||
installExtraFile = file:
|
|
||||||
let
|
|
||||||
source = toString file.source;
|
|
||||||
target = file.target or (baseNameOf source);
|
|
||||||
mode = file.mode or "0644";
|
|
||||||
in ''
|
|
||||||
install -Dm${toString mode} ${lib.escapeShellArg source} "$out/libexec/${serverLibexecName}/${target}"
|
|
||||||
'';
|
|
||||||
installServerPhase =
|
|
||||||
if installServer == null
|
|
||||||
then null
|
|
||||||
else ''
|
|
||||||
runHook preInstall
|
|
||||||
install -Dm755 ${lib.escapeShellArg serverFile} "$out/libexec/${serverLibexecName}/${serverFile}"
|
|
||||||
${lib.concatMapStringsSep "\n" installExtraFile extraFiles}
|
|
||||||
mkdir -p "$out/bin"
|
|
||||||
cat > "$out/bin/${serverBin}" <<EOF
|
|
||||||
#!${pkgs.runtimeShell}
|
|
||||||
exec ${nodejs}/bin/node "$out/libexec/${serverLibexecName}/${serverFile}" "\$@"
|
|
||||||
EOF
|
|
||||||
chmod +x "$out/bin/${serverBin}"
|
|
||||||
${lib.optionalString (installConfig ? descriptorPath && descriptorPath != null) ''
|
|
||||||
cp ${lib.escapeShellArg descriptorPath} "$out/${descriptorPath}"
|
|
||||||
''}
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
|
|
||||||
project = (pkgs.callPackage "${packageRoot}/yarn-project.nix" { inherit nodejs; }) {
|
|
||||||
src = packageRoot;
|
|
||||||
overrideAttrs = old: {
|
|
||||||
nativeBuildInputs =
|
|
||||||
(old.nativeBuildInputs or [ ])
|
|
||||||
++ lib.optional (bundle != null) pkgs.esbuild
|
|
||||||
++ callOption nativeBuildInputs;
|
|
||||||
preConfigure = (old.preConfigure or "") + ''
|
|
||||||
${portalLinksFor (callOption sourcePortals)}
|
|
||||||
'';
|
|
||||||
buildPhase = ''
|
|
||||||
runHook preBuild
|
|
||||||
${exportsFor (callOption buildEnv)}
|
|
||||||
${buildCommand}
|
|
||||||
${bundleCommand}
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
|
||||||
} // lib.optionalAttrs (installServerPhase != null) {
|
|
||||||
installPhase = installServerPhase;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
devShellHookBase = ''
|
|
||||||
if [ -n "''${PS1-}" ]; then
|
|
||||||
if [ -n "''${QX_DEV_SHELL_PROMPT-}" ]; then
|
|
||||||
PS1="''${PS1#\[qx:''${QX_DEV_SHELL_PROMPT}\] }"
|
|
||||||
fi
|
|
||||||
export QX_DEV_SHELL_PROMPT=${lib.escapeShellArg promptNameFinal}
|
|
||||||
PS1="[qx:${promptNameFinal}] $PS1"
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
|
|
||||||
maybeServerOutputs =
|
|
||||||
if installServer == null
|
|
||||||
then { }
|
|
||||||
else {
|
|
||||||
packages.server = project;
|
|
||||||
apps.default = {
|
|
||||||
type = "app";
|
|
||||||
program = "${project}/bin/${serverBin}";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.default = project;
|
inherit mkQuixosPackageFlake mkTsPackageServer mkSchemaSupport;
|
||||||
packages.source = sourcePackage;
|
|
||||||
devShells.default = pkgs.mkShell {
|
|
||||||
packages = [
|
|
||||||
nodejs
|
|
||||||
pkgs.yarn-berry_4
|
|
||||||
] ++ callOption devShellPackages;
|
|
||||||
shellHook = devShellHookBase + callOption devShellHook;
|
|
||||||
};
|
|
||||||
} // maybeServerOutputs
|
|
||||||
);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit
|
|
||||||
mkQuixosPackageFlake
|
|
||||||
mkTsPackageServer
|
|
||||||
mkSchemaSupport
|
|
||||||
mkCaminoSourcePackage
|
|
||||||
mkCaminoTsYarnNixifyFlake;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user