fix: writers & overlays
This commit is contained in:
24
flake.nix
24
flake.nix
@@ -42,15 +42,31 @@
|
|||||||
}@inputs: let
|
}@inputs: let
|
||||||
flake = ./.;
|
flake = ./.;
|
||||||
nixpkgs = nixpkgs-25-05;
|
nixpkgs = nixpkgs-25-05;
|
||||||
overlays = [ self.overlays.default ];
|
|
||||||
self-lib = import ./lib { inherit flake self inputs; };
|
self-lib = import ./lib { inherit flake self inputs; };
|
||||||
|
|
||||||
|
# Create overlay that includes legacy packages
|
||||||
|
overlayWithLegacy = system: final: prev:
|
||||||
|
let
|
||||||
|
baseOverlay = (import ./overlay { inherit flake self inputs nixpkgs; }) final prev;
|
||||||
|
legacyPackages = import ./legacy { inherit system pkgs self; };
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [ (import rust-overlay) ];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
baseOverlay // legacyPackages;
|
||||||
|
|
||||||
|
overlays = [ self.overlays.default ];
|
||||||
in self-lib.forAllSystemsWithPkgs ([(import rust-overlay)] ++ overlays) ({
|
in self-lib.forAllSystemsWithPkgs ([(import rust-overlay)] ++ overlays) ({
|
||||||
system,
|
system,
|
||||||
pkgs,
|
pkgs,
|
||||||
}: {
|
}: {
|
||||||
packages.${system} = import ./package { inherit system pkgs self; };
|
packages.${system} = import ./package { inherit system self pkgs; };
|
||||||
legacyPackages.${system} = import ./legacy { inherit system pkgs self; };
|
devShells.${system} = import ./devshell { inherit system self pkgs; };
|
||||||
devShells.${system} = import ./devshell { inherit system pkgs self; };
|
legacyPackages.${system} = import ./legacy {
|
||||||
|
inherit system self;
|
||||||
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
};
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
"devvm-manual|${system}" = import ./nixos/system/devvm-manual/default.nix
|
"devvm-manual|${system}" = import ./nixos/system/devvm-manual/default.nix
|
||||||
{ inherit flake self inputs system; };
|
{ inherit flake self inputs system; };
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
{ self, system, pkgs }:
|
{ self, system, pkgs }:
|
||||||
{
|
let
|
||||||
writers = pkgs.callPackage ./writer { };
|
writers = pkgs.callPackage ./writer { };
|
||||||
}
|
in {
|
||||||
|
# NOTE(yukkop): duplicate writers in root of legacyPackages and writers due nixpkgs legacyPackages consistency
|
||||||
|
writers = writers;
|
||||||
|
} // writers
|
||||||
|
|||||||
@@ -1,41 +1,11 @@
|
|||||||
{
|
{
|
||||||
lib,
|
callPackage
|
||||||
writers,
|
}: rec {
|
||||||
gcc,
|
writeShellApplication = callPackage ./writeShellApplication.nix {};
|
||||||
}: let
|
writeC = callPackage ./writeC.nix {};
|
||||||
writeC = name: argsOrScript:
|
writeCBin = name: writeC "/bin/${name}";
|
||||||
if lib.isAttrs argsOrScript && !lib.isDerivation argsOrScript
|
writeMinCBin = name: includes: body: writeMinC "/bin/${name}" includes body;
|
||||||
then
|
writeMinC = name: includes: body:
|
||||||
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:
|
|
||||||
writeC name ''
|
writeC name ''
|
||||||
${builtins.concatStringsSep "\n" (map (h: "#include " + h) includes)}
|
${builtins.concatStringsSep "\n" (map (h: "#include " + h) includes)}
|
||||||
|
|
||||||
@@ -43,9 +13,4 @@
|
|||||||
${body}
|
${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
35
legacy/writer/writeC.nix
Normal 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
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
{
|
||||||
|
writeTextFile,
|
||||||
|
lib,
|
||||||
|
shellcheck-minimal,
|
||||||
|
stdenv,
|
||||||
|
runtimeShell,
|
||||||
|
}:
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
The name of the script to write.
|
The name of the script to write.
|
||||||
@@ -87,6 +94,8 @@
|
|||||||
Type: Bool
|
Type: Bool
|
||||||
*/
|
*/
|
||||||
inheritPath ? true,
|
inheritPath ? true,
|
||||||
|
|
||||||
|
shell ? runtimeShell,
|
||||||
}:
|
}:
|
||||||
writeTextFile {
|
writeTextFile {
|
||||||
inherit
|
inherit
|
||||||
@@ -99,27 +108,26 @@ writeTextFile {
|
|||||||
destination = "/bin/${name}";
|
destination = "/bin/${name}";
|
||||||
allowSubstitutes = true;
|
allowSubstitutes = true;
|
||||||
preferLocalBuild = false;
|
preferLocalBuild = false;
|
||||||
text =
|
text = ''
|
||||||
''
|
#!${shell}
|
||||||
#!${dash}/bin/dash
|
${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions}
|
||||||
${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions}
|
''
|
||||||
''
|
+ lib.optionalString (runtimeEnv != null) (
|
||||||
+ lib.optionalString (runtimeEnv != null) (
|
lib.concatStrings (
|
||||||
lib.concatStrings (
|
lib.mapAttrsToList (name: value: ''
|
||||||
lib.mapAttrsToList (name: value: ''
|
${lib.toShellVar name value}
|
||||||
${lib.toShellVar name value}
|
export ${name}
|
||||||
export ${name}
|
'') runtimeEnv
|
||||||
'') 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 =
|
checkPhase =
|
||||||
let
|
let
|
||||||
@@ -140,11 +148,10 @@ writeTextFile {
|
|||||||
if checkPhase == null then
|
if checkPhase == null then
|
||||||
''
|
''
|
||||||
runHook preCheck
|
runHook preCheck
|
||||||
#dryrun
|
${stdenv.shellDryRun} "$target"
|
||||||
${dash}/bin/dash -n -O extglob "$target"
|
|
||||||
${shellcheckCommand}
|
${shellcheckCommand}
|
||||||
runHook postCheck
|
runHook postCheck
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
checkPhase;
|
checkPhase;
|
||||||
};
|
}
|
||||||
@@ -49,7 +49,7 @@ in {
|
|||||||
extensions = let
|
extensions = let
|
||||||
packages = {
|
packages = {
|
||||||
inherit (cfg.package.pkgs) pg_net pgjwt pg_cron http pg_smtp_client plsh;
|
inherit (cfg.package.pkgs) pg_net pgjwt pg_cron http pg_smtp_client plsh;
|
||||||
hemar = inputs.hutil.packages.${system}.pg-15-hemar;
|
hemar = self.packages.${system}.pg-15-hemar;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.attrValues (
|
lib.attrValues (
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ in final: prev: (
|
|||||||
packages = self.packages.${prev.system};
|
packages = self.packages.${prev.system};
|
||||||
legacyPackages = self.legacyPackages.${prev.system};
|
legacyPackages = self.legacyPackages.${prev.system};
|
||||||
in {
|
in {
|
||||||
hectic = packages;
|
hectic = packages // legacyPackages;
|
||||||
postgresql_17 = prev.postgresql_17 // {pkgs = prev.postgresql_17.pkgs // {
|
postgresql_17 = prev.postgresql_17 // {pkgs = prev.postgresql_17.pkgs // {
|
||||||
http = packages.pg-17-ext-http;
|
http = packages.pg-17-ext-http;
|
||||||
pg_smtp_client = packages.pg-17-ext-smtp-client;
|
pg_smtp_client = packages.pg-17-ext-smtp-client;
|
||||||
@@ -27,6 +27,5 @@ in final: prev: (
|
|||||||
plsh = packages.pg-15-ext-plsh;
|
plsh = packages.pg-15-ext-plsh;
|
||||||
hemar = packages.pg-15-ext-hemar;
|
hemar = packages.pg-15-ext-hemar;
|
||||||
};};
|
};};
|
||||||
writers = prev.writers // legacyPackages.writers;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
{
|
|
||||||
/*
|
|
||||||
The name of the script to write.
|
|
||||||
|
|
||||||
Type: String
|
|
||||||
*/
|
|
||||||
name,
|
|
||||||
/*
|
|
||||||
The shell script's text, not including a shebang.
|
|
||||||
|
|
||||||
Type: String
|
|
||||||
*/
|
|
||||||
text,
|
|
||||||
/*
|
|
||||||
Inputs to add to the shell script's `$PATH` at runtime.
|
|
||||||
|
|
||||||
Type: [String|Derivation]
|
|
||||||
*/
|
|
||||||
runtimeInputs ? [ ],
|
|
||||||
/*
|
|
||||||
Extra environment variables to set at runtime.
|
|
||||||
|
|
||||||
Type: AttrSet
|
|
||||||
*/
|
|
||||||
runtimeEnv ? null,
|
|
||||||
/*
|
|
||||||
`stdenv.mkDerivation`'s `meta` argument.
|
|
||||||
|
|
||||||
Type: AttrSet
|
|
||||||
*/
|
|
||||||
meta ? { },
|
|
||||||
/*
|
|
||||||
`stdenv.mkDerivation`'s `passthru` argument.
|
|
||||||
|
|
||||||
Type: AttrSet
|
|
||||||
*/
|
|
||||||
passthru ? { },
|
|
||||||
/*
|
|
||||||
The `checkPhase` to run. Defaults to `shellcheck` on supported
|
|
||||||
platforms and `bash -n`.
|
|
||||||
|
|
||||||
The script path will be given as `$target` in the `checkPhase`.
|
|
||||||
|
|
||||||
Type: String
|
|
||||||
*/
|
|
||||||
checkPhase ? null,
|
|
||||||
/*
|
|
||||||
Checks to exclude when running `shellcheck`, e.g. `[ "SC2016" ]`.
|
|
||||||
|
|
||||||
See <https://www.shellcheck.net/wiki/> for a list of checks.
|
|
||||||
|
|
||||||
Type: [String]
|
|
||||||
*/
|
|
||||||
excludeShellChecks ? [ ],
|
|
||||||
/*
|
|
||||||
Extra command-line flags to pass to ShellCheck.
|
|
||||||
|
|
||||||
Type: [String]
|
|
||||||
*/
|
|
||||||
extraShellCheckFlags ? [ ],
|
|
||||||
/*
|
|
||||||
Bash options to activate with `set -o` at the start of the script.
|
|
||||||
|
|
||||||
Defaults to `[ "errexit" "nounset" "pipefail" ]`.
|
|
||||||
|
|
||||||
Type: [String]
|
|
||||||
*/
|
|
||||||
bashOptions ? [
|
|
||||||
"errexit"
|
|
||||||
"nounset"
|
|
||||||
"pipefail"
|
|
||||||
],
|
|
||||||
/*
|
|
||||||
Extra arguments to pass to `stdenv.mkDerivation`.
|
|
||||||
|
|
||||||
:::{.caution}
|
|
||||||
Certain derivation attributes are used internally,
|
|
||||||
overriding those could cause problems.
|
|
||||||
:::
|
|
||||||
|
|
||||||
Type: AttrSet
|
|
||||||
*/
|
|
||||||
derivationArgs ? { },
|
|
||||||
/*
|
|
||||||
Whether to inherit the current `$PATH` in the script.
|
|
||||||
|
|
||||||
Type: Bool
|
|
||||||
*/
|
|
||||||
inheritPath ? true,
|
|
||||||
}:
|
|
||||||
writeTextFile {
|
|
||||||
inherit
|
|
||||||
name
|
|
||||||
meta
|
|
||||||
passthru
|
|
||||||
derivationArgs
|
|
||||||
;
|
|
||||||
executable = true;
|
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
+ lib.optionalString (runtimeInputs != [ ]) ''
|
|
||||||
|
|
||||||
export PATH="${lib.makeBinPath runtimeInputs}${lib.optionalString inheritPath ":$PATH"}"
|
|
||||||
''
|
|
||||||
+ ''
|
|
||||||
|
|
||||||
${text}
|
|
||||||
'';
|
|
||||||
|
|
||||||
checkPhase =
|
|
||||||
let
|
|
||||||
excludeFlags = lib.optionals (excludeShellChecks != [ ]) [
|
|
||||||
"--exclude"
|
|
||||||
(lib.concatStringsSep "," excludeShellChecks)
|
|
||||||
];
|
|
||||||
# GHC (=> shellcheck) isn't supported on some platforms (such as risc-v)
|
|
||||||
# but we still want to use writeShellApplication on those platforms
|
|
||||||
shellcheckCommand = lib.optionalString shellcheck-minimal.compiler.bootstrapAvailable ''
|
|
||||||
# use shellcheck which does not include docs
|
|
||||||
# pandoc takes long to build and documentation isn't needed for just running the cli
|
|
||||||
${lib.getExe shellcheck-minimal} ${
|
|
||||||
lib.escapeShellArgs (excludeFlags ++ extraShellCheckFlags)
|
|
||||||
} "$target"
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
if checkPhase == null then
|
|
||||||
''
|
|
||||||
runHook preCheck
|
|
||||||
#dryrun
|
|
||||||
${dash}/bin/dash -n -O extglob "$target"
|
|
||||||
${shellcheckCommand}
|
|
||||||
runHook postCheck
|
|
||||||
''
|
|
||||||
else
|
|
||||||
checkPhase;
|
|
||||||
};
|
|
||||||
@@ -1,25 +1,35 @@
|
|||||||
{ symlinkJoin, writeShellApplication, socat, dash, hectic, curl }:
|
{ symlinkJoin, writeShellApplication, socat, dash, hectic, curl }:
|
||||||
let
|
let
|
||||||
base64 = writeShellApplication {
|
shell = "${dash}/bin/dash";
|
||||||
|
bashOptions = [
|
||||||
|
"errexit"
|
||||||
|
"nounset"
|
||||||
|
];
|
||||||
|
|
||||||
|
base64 = hectic.writeShellApplication {
|
||||||
|
inherit shell bashOptions;
|
||||||
name = "base64";
|
name = "base64";
|
||||||
runtimeInputs = [ ];
|
runtimeInputs = [ ];
|
||||||
text = builtins.readFile ./base64.sh;
|
text = builtins.readFile ./base64.sh;
|
||||||
};
|
};
|
||||||
|
|
||||||
# TODO: writeDashApplication
|
# TODO: writeDashApplication
|
||||||
probe = writeShellApplication {
|
probe = hectic.writeShellApplication {
|
||||||
|
inherit shell bashOptions;
|
||||||
name = "probe";
|
name = "probe";
|
||||||
runtimeInputs = [ socat dash probe-loop ];
|
runtimeInputs = [ socat dash probe-loop ];
|
||||||
text = builtins.readFile ./probe.sh;
|
text = builtins.readFile ./probe.sh;
|
||||||
};
|
};
|
||||||
|
|
||||||
probe-loop = writeShellApplication {
|
probe-loop = hectic.writeShellApplication {
|
||||||
|
inherit shell bashOptions;
|
||||||
name = "probe-loop";
|
name = "probe-loop";
|
||||||
runtimeInputs = [ base64 ];
|
runtimeInputs = [ base64 ];
|
||||||
text = builtins.readFile ./probe-loop.sh;
|
text = builtins.readFile ./probe-loop.sh;
|
||||||
};
|
};
|
||||||
|
|
||||||
sentinel = writeShellApplication {
|
sentinel = hectic.writeShellApplication {
|
||||||
|
inherit shell bashOptions;
|
||||||
name = "sentinel";
|
name = "sentinel";
|
||||||
runtimeInputs = [ hectic.shellplot curl ];
|
runtimeInputs = [ hectic.shellplot curl ];
|
||||||
text = builtins.readFile ./sentinel.sh;
|
text = builtins.readFile ./sentinel.sh;
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
#!/usr/bin/env dash
|
#!/usr/bin/env dash
|
||||||
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
socat -V >/dev/null
|
socat -V >/dev/null
|
||||||
dash -c 'echo ok' >/dev/null
|
dash -c 'echo ok' >/dev/null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user