fix: writers & overlays

This commit is contained in:
2025-10-11 14:56:25 +00:00
parent 65fa944df8
commit 6dd7d112c5
10 changed files with 111 additions and 236 deletions

View File

@@ -1,41 +1,11 @@
{
lib,
writers,
gcc,
}: let
writeC = name: argsOrScript:
if lib.isAttrs argsOrScript && !lib.isDerivation argsOrScript
then
writers.makeBinWriter (
argsOrScript
// {
compileScript = ''
# Force gcc to treat the input file as C code
${gcc}/bin/gcc -fsyntax-only -xc $contentPath
if [ $? -ne 0 ]; then
echo "Syntax check failed"
exit 1
fi
${gcc}/bin/gcc -xc -o $out $contentPath
'';
}
)
name
else
writers.makeBinWriter {
compileScript = ''
# Force gcc to treat the input file as C code
${gcc}/bin/gcc -fsyntax-only -xc $contentPath
if [ $? -ne 0 ]; then
echo "Syntax check failed"
exit 1
fi
${gcc}/bin/gcc -xc -o $out $contentPath
'';
}
name
argsOrScript;
writeMinC = name: includes: body:
callPackage
}: rec {
writeShellApplication = callPackage ./writeShellApplication.nix {};
writeC = callPackage ./writeC.nix {};
writeCBin = name: writeC "/bin/${name}";
writeMinCBin = name: includes: body: writeMinC "/bin/${name}" includes body;
writeMinC = name: includes: body:
writeC name ''
${builtins.concatStringsSep "\n" (map (h: "#include " + h) includes)}
@@ -43,9 +13,4 @@
${body}
}
'';
in {
writeCBin = name: writeC "/bin/${name}";
writeC = writeC;
writeMinCBin = name: includes: body: writeMinC "/bin/${name}" includes body;
writeMinC = writeMinC;
}

35
legacy/writer/writeC.nix Normal file
View File

@@ -0,0 +1,35 @@
{ lib, writers, gcc }:
name: argsOrScript:
if
lib.isAttrs argsOrScript
&& !lib.isDerivation argsOrScript
then
writers.makeBinWriter (
argsOrScript
// {
compileScript = ''
# Force gcc to treat the input file as C code
${gcc}/bin/gcc -fsyntax-only -xc $contentPath
if [ $? -ne 0 ]; then
echo "Syntax check failed"
exit 1
fi
${gcc}/bin/gcc -xc -o $out $contentPath
'';
}
)
name
else
writers.makeBinWriter {
compileScript = ''
# Force gcc to treat the input file as C code
${gcc}/bin/gcc -fsyntax-only -xc $contentPath
if [ $? -ne 0 ]; then
echo "Syntax check failed"
exit 1
fi
${gcc}/bin/gcc -xc -o $out $contentPath
'';
}
name
argsOrScript

View File

@@ -1,3 +1,10 @@
{
writeTextFile,
lib,
shellcheck-minimal,
stdenv,
runtimeShell,
}:
{
/*
The name of the script to write.
@@ -87,6 +94,8 @@
Type: Bool
*/
inheritPath ? true,
shell ? runtimeShell,
}:
writeTextFile {
inherit
@@ -99,27 +108,26 @@ writeTextFile {
destination = "/bin/${name}";
allowSubstitutes = true;
preferLocalBuild = false;
text =
''
#!${dash}/bin/dash
${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions}
''
+ lib.optionalString (runtimeEnv != null) (
lib.concatStrings (
lib.mapAttrsToList (name: value: ''
${lib.toShellVar name value}
export ${name}
'') runtimeEnv
)
text = ''
#!${shell}
${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions}
''
+ lib.optionalString (runtimeEnv != null) (
lib.concatStrings (
lib.mapAttrsToList (name: value: ''
${lib.toShellVar name value}
export ${name}
'') runtimeEnv
)
+ lib.optionalString (runtimeInputs != [ ]) ''
)
+ lib.optionalString (runtimeInputs != [ ]) ''
export PATH="${lib.makeBinPath runtimeInputs}${lib.optionalString inheritPath ":$PATH"}"
''
+ ''
export PATH="${lib.makeBinPath runtimeInputs}${lib.optionalString inheritPath ":$PATH"}"
''
+ ''
${text}
'';
${text}
'';
checkPhase =
let
@@ -140,11 +148,10 @@ writeTextFile {
if checkPhase == null then
''
runHook preCheck
#dryrun
${dash}/bin/dash -n -O extglob "$target"
${stdenv.shellDryRun} "$target"
${shellcheckCommand}
runHook postCheck
''
else
checkPhase;
};
}