style: ~apply alejandra

This commit is contained in:
zerosummed
2025-04-17 03:57:54 +03:00
parent 3dfe3d61f6
commit 29ff6989e5
7 changed files with 299 additions and 234 deletions

View File

@@ -26,16 +26,15 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
{ lib
, cargo-pgrx
, pkg-config
, rustPlatform
, stdenv
, Security
, writeShellScriptBin
{
lib,
cargo-pgrx,
pkg-config,
rustPlatform,
stdenv,
Security,
writeShellScriptBin,
}:
# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
# we hand most of the arguments down.
#
@@ -46,23 +45,21 @@
# If the generated rust bindings aren't needed to use the extension, its a
# unnecessary and heavy dependency. If you set this to true, you also
# have to add `rustfmt` to `nativeBuildInputs`.
{ buildAndTestSubdir ? null
, buildType ? "release"
, buildFeatures ? [ ]
, cargoBuildFlags ? [ ]
, postgresql
{
buildAndTestSubdir ? null,
buildType ? "release",
buildFeatures ? [],
cargoBuildFlags ? [],
postgresql,
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.
# if you include the generated code in the output via postInstall.
, useFakeRustfmt ? true
, usePgTestCheckFeature ? true
, ...
} @ args:
let
useFakeRustfmt ? true,
usePgTestCheckFeature ? true,
...
} @ args: let
rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or []);
in
assert lib.asserts.assertMsg ((args.installPhase or "") == "")
"buildPgrxExtensions overwrites the installPhase, so providing one does nothing";
assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
@@ -70,9 +67,7 @@ assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
assert lib.asserts.assertMsg (useFakeRustfmt -> !rustfmtInNativeBuildInputs)
"The parameter useFakeRustfmt is set to true, but rustfmt is included in nativeBuildInputs. Either set useFakeRustfmt to false or remove rustfmt from nativeBuildInputs.";
assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs)
"The parameter useFakeRustfmt is set to false, but rustfmt is not included in nativeBuildInputs. Either set useFakeRustfmt to true or add rustfmt from nativeBuildInputs.";
let
"The parameter useFakeRustfmt is set to false, but rustfmt is not included in nativeBuildInputs. Either set useFakeRustfmt to true or add rustfmt from nativeBuildInputs."; let
fakeRustfmt = writeShellScriptBin "rustfmt" ''
exit 0
'';
@@ -101,15 +96,20 @@ let
# so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
# we forgot parentheses
finalArgs = argsForBuildRustPackage // {
finalArgs =
argsForBuildRustPackage
// {
buildInputs = (args.buildInputs or []) ++ lib.optionals stdenv.hostPlatform.isDarwin [Security];
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
nativeBuildInputs =
(args.nativeBuildInputs or [])
++ [
cargo-pgrx
postgresql
pkg-config
rustPlatform.bindgenHook
] ++ lib.optionals useFakeRustfmt [ fakeRustfmt ];
]
++ lib.optionals useFakeRustfmt [fakeRustfmt];
buildPhase = ''
runHook preBuild

103
flake.nix
View File

@@ -204,17 +204,29 @@
modules = [
self.nixosModules."preset.default"
self.nixosModules."hardware.hetzner"
({modulesPath, pkgs, ...}: {
({
modulesPath,
pkgs,
...
}: {
imports = [
(modulesPath + "/profiles/qemu-guest.nix")
];
users.users.root.openssh.authorizedKeys.keys = [];
environment.systemPackages = with pkgs; [
(pkgs.writers.writeMinCBin "minc-hello-world" ["<stdio.h>"] /*c*/ ''
(pkgs.writers.writeMinCBin "minc-hello-world" ["<stdio.h>"]
/*
c
*/
''
printf("hello world\n");
'')
(pkgs.writers.writeMinCBin "minc-env" ["<stdio.h>" "<stdlib.h>"] /*c*/ ''
(pkgs.writers.writeMinCBin "minc-env" ["<stdio.h>" "<stdlib.h>"]
/*
c
*/
''
char *env_name;
if (argc > 1) {
env_name = argv[1];
@@ -228,7 +240,11 @@
printf("Environment variable %s not found.\n", env_name);
}
'')
(pkgs.writers.writeMinCBin "minc-env-check" ["<stdio.h>" "<stdlib.h>"] /*c*/ ''
(pkgs.writers.writeMinCBin "minc-env-check" ["<stdio.h>" "<stdlib.h>"]
/*
c
*/
''
char *env_name;
if (argc > 1) {
env_name = argv[1];
@@ -279,7 +295,10 @@
};
})
];
pkgs = import nixpkgs {inherit system; overlays = [ self.overlays.default ];};
pkgs = import nixpkgs {
inherit system;
overlays = [self.overlays.default];
};
};
})
// {
@@ -380,8 +399,7 @@
inherit (pkgs-unstable.darwin.apple_sdk.frameworks) Security;
};
buildPostgresqlExtension =
prev.callPackage (import (builtins.path {
buildPostgresqlExtension = prev.callPackage (import (builtins.path {
name = "extension-builder";
path = ./buildPostgresqlExtension.nix;
}));
@@ -410,7 +428,8 @@
};
buildPlHaskellExt = versionSuffix: let
version = "4.0";
in buildPostgresqlExtension {
in
buildPostgresqlExtension {
postgresql = prev."postgresql_${versionSuffix}";
} {
pname = "plhaskell";
@@ -439,36 +458,61 @@
};
in {
hectic = self.packages.${prev.system};
postgresql_17 = prev.postgresql_17 // {pkgs = prev.postgresql_17.pkgs // {
postgresql_17 =
prev.postgresql_17
// {
pkgs =
prev.postgresql_17.pkgs
// {
http = buildHttpExt "17";
pg_smtp_client = buildSmtpExt "17";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_17;};
};};
postgresql_16 = prev.postgresql_16 // {pkgs = prev.postgresql_16.pkgs // {
};
};
postgresql_16 =
prev.postgresql_16
// {
pkgs =
prev.postgresql_16.pkgs
// {
http = buildHttpExt "16";
pg_smtp_client = buildSmtpExt "16";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_16;};
};};
postgresql_15 = prev.postgresql_15 // {pkgs = prev.postgresql_15.pkgs // {
};
};
postgresql_15 =
prev.postgresql_15
// {
pkgs =
prev.postgresql_15.pkgs
// {
http = buildHttpExt "15";
pg_smtp_client = buildSmtpExt "15";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_15;};
};};
postgresql_14 = prev.postgresql_14 // {pkgs = prev.postgresql_14.pkgs // {
};
};
postgresql_14 =
prev.postgresql_14
// {
pkgs =
prev.postgresql_14.pkgs
// {
http = buildHttpExt "14";
pg_smtp_client = buildSmtpExt "14";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_14;};
};};
};
};
writers = let
writeC =
name: argsOrScript:
if lib.isAttrs argsOrScript && !lib.isDerivation argsOrScript then
writeC = name: argsOrScript:
if lib.isAttrs argsOrScript && !lib.isDerivation argsOrScript
then
prev.writers.makeBinWriter (
argsOrScript // {
argsOrScript
// {
compileScript = ''
# Force gcc to treat the input file as C code
${prev.gcc}/bin/gcc -fsyntax-only -xc $contentPath
@@ -479,7 +523,8 @@
${prev.gcc}/bin/gcc -xc -o $out $contentPath
'';
}
) name
)
name
else
prev.writers.makeBinWriter {
compileScript = ''
@@ -491,9 +536,10 @@
fi
${prev.gcc}/bin/gcc -xc -o $out $contentPath
'';
} name argsOrScript;
writeMinC =
name: includes: body:
}
name
argsOrScript;
writeMinC = name: includes: body:
writeC name ''
${builtins.concatStringsSep "\n" (map (h: "#include " + h) includes)}
@@ -501,7 +547,9 @@
${body}
}
'';
in prev.writers // {
in
prev.writers
// {
writeCBin = name: writeC "/bin/${name}";
writeC = writeC;
writeMinCBin = name: includes: body: writeMinC "/bin/${name}" includes body;
@@ -513,7 +561,10 @@
# -- For all systems --
inherit dotEnv minorEnvironment parseEnv forAllSystemsWithPkgs forSpecSystemsWithPkgs;
readEnvironment = { envVarsToRead, prefix ? "" }:
readEnvironment = {
envVarsToRead,
prefix ? "",
}:
builtins.listToAttrs
(map (name: {
inherit name;

View File

@@ -1,5 +1,10 @@
{ stdenv, gcc, lib, bash, inotify-tools }:
{
stdenv,
gcc,
lib,
bash,
inotify-tools,
}:
stdenv.mkDerivation {
pname = "hectic";
version = "1.0";

View File

@@ -4,7 +4,6 @@
postgresql,
...
}:
stdenv.mkDerivation {
pname = "postgreact";
version = "0.1";

View File

@@ -1,5 +1,10 @@
{ stdenv, gcc, lib, bash, c-hectic }:
{
stdenv,
gcc,
lib,
bash,
c-hectic,
}:
stdenv.mkDerivation {
pname = "prettify";
version = "1.0";

View File

@@ -1,5 +1,10 @@
{ stdenv, gcc, lib, bash, gdb }:
{
stdenv,
gcc,
lib,
bash,
gdb,
}:
stdenv.mkDerivation {
pname = "watch";
version = "1.0";