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, # 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 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
{
{ lib lib,
, cargo-pgrx cargo-pgrx,
, pkg-config pkg-config,
, rustPlatform rustPlatform,
, stdenv stdenv,
, Security Security,
, writeShellScriptBin writeShellScriptBin,
}: }:
# The idea behind: Use it mostly like rustPlatform.buildRustPackage and so # The idea behind: Use it mostly like rustPlatform.buildRustPackage and so
# we hand most of the arguments down. # 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 # 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 # unnecessary and heavy dependency. If you set this to true, you also
# have to add `rustfmt` to `nativeBuildInputs`. # have to add `rustfmt` to `nativeBuildInputs`.
{
{ buildAndTestSubdir ? null buildAndTestSubdir ? null,
, buildType ? "release" buildType ? "release",
, buildFeatures ? [ ] buildFeatures ? [],
, cargoBuildFlags ? [ ] cargoBuildFlags ? [],
, postgresql postgresql,
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the # 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. # 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. # if you include the generated code in the output via postInstall.
, useFakeRustfmt ? true useFakeRustfmt ? true,
, usePgTestCheckFeature ? true usePgTestCheckFeature ? true,
, ... ...
} @ args: } @ args: let
let
rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or []); rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or []);
in in
assert lib.asserts.assertMsg ((args.installPhase or "") == "") assert lib.asserts.assertMsg ((args.installPhase or "") == "")
"buildPgrxExtensions overwrites the installPhase, so providing one does nothing"; "buildPgrxExtensions overwrites the installPhase, so providing one does nothing";
assert lib.asserts.assertMsg ((args.buildPhase or "") == "") assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
@@ -70,9 +67,7 @@ assert lib.asserts.assertMsg ((args.buildPhase or "") == "")
assert lib.asserts.assertMsg (useFakeRustfmt -> !rustfmtInNativeBuildInputs) 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."; "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) 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."; "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
let
fakeRustfmt = writeShellScriptBin "rustfmt" '' fakeRustfmt = writeShellScriptBin "rustfmt" ''
exit 0 exit 0
''; '';
@@ -101,15 +96,20 @@ let
# so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because # so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because
# we forgot parentheses # we forgot parentheses
finalArgs = argsForBuildRustPackage // { finalArgs =
argsForBuildRustPackage
// {
buildInputs = (args.buildInputs or []) ++ lib.optionals stdenv.hostPlatform.isDarwin [Security]; buildInputs = (args.buildInputs or []) ++ lib.optionals stdenv.hostPlatform.isDarwin [Security];
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ nativeBuildInputs =
(args.nativeBuildInputs or [])
++ [
cargo-pgrx cargo-pgrx
postgresql postgresql
pkg-config pkg-config
rustPlatform.bindgenHook rustPlatform.bindgenHook
] ++ lib.optionals useFakeRustfmt [ fakeRustfmt ]; ]
++ lib.optionals useFakeRustfmt [fakeRustfmt];
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild

103
flake.nix
View File

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

View File

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

View File

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

View File

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

View File

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