style(treewide): Switch to nixfmt

This commit is contained in:
Tristan Daniël Maat 2025-11-20 15:46:17 +08:00
parent 4b0e6f0a8c
commit 82c1d22d3d
Signed by: tlater
GPG key ID: 02E935006CF2E8E7
8 changed files with 154 additions and 126 deletions

View file

@ -14,19 +14,22 @@
}; };
}; };
outputs = { outputs =
{
self, self,
nixpkgs, nixpkgs,
dream2nix, dream2nix,
fenix, fenix,
}: let }:
let
# At the moment, we only deploy to x86_64-linux. Update when we # At the moment, we only deploy to x86_64-linux. Update when we
# care about another platform. # care about another platform.
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
fenixPkgs = fenix.packages.${system}; fenixPkgs = fenix.packages.${system};
ownPkgs = self.packages.${system}; ownPkgs = self.packages.${system};
in { in
{
packages.${system} = dream2nix.lib.importPackages { packages.${system} = dream2nix.lib.importPackages {
projectRoot = ./.; projectRoot = ./.;
projectRootFile = "flake.nix"; projectRootFile = "flake.nix";
@ -38,19 +41,25 @@
}; };
apps.${system} = { apps.${system} = {
default = let default =
let
inherit (ownPkgs) server templates; inherit (ownPkgs) server templates;
inherit (pkgs) writeShellScript; inherit (pkgs) writeShellScript;
in { in
{
type = "app"; type = "app";
program = builtins.toString (writeShellScript "tlaternet-webserver" '' program = builtins.toString (
writeShellScript "tlaternet-webserver" ''
${server}/bin/tlaternet-webserver --template-directory ${templates} ${server}/bin/tlaternet-webserver --template-directory ${templates}
''); ''
);
}; };
update = let update =
let
update-script = pkgs.callPackage ./nix/update.nix { inherit self; }; update-script = pkgs.callPackage ./nix/update.nix { inherit self; };
in { in
{
type = "app"; type = "app";
program = "${update-script}/bin/update"; program = "${update-script}/bin/update";
}; };
@ -76,8 +85,6 @@
}; };
}; };
checks.${system} = import ./nix/checks { checks.${system} = import ./nix/checks { inherit self pkgs; };
inherit self pkgs;
};
}; };
} }

View file

@ -1,9 +1,8 @@
{ { pkgs, self }:
pkgs, let
self,
}: let
callPackage = pkgs.lib.callPackageWith (pkgs // { inherit self; }); callPackage = pkgs.lib.callPackageWith (pkgs // { inherit self; });
in { in
{
lintNix = callPackage ./lint-nix.nix { }; lintNix = callPackage ./lint-nix.nix { };
openHomepage = callPackage ./open-homepage.nix { }; openHomepage = callPackage ./open-homepage.nix { };
} }

View file

@ -2,10 +2,11 @@
self, self,
lib, lib,
stdenv, stdenv,
alejandra, nixfmt-rfc-style,
deadnix, deadnix,
statix, statix,
}: let }:
let
inherit (lib) sourceFilesBySuffices; inherit (lib) sourceFilesBySuffices;
in in
stdenv.mkDerivation { stdenv.mkDerivation {
@ -17,10 +18,14 @@ in
name = "lint-nix"; name = "lint-nix";
src = sourceFilesBySuffices self [ ".nix" ]; src = sourceFilesBySuffices self [ ".nix" ];
checkInputs = [alejandra deadnix statix]; checkInputs = [
nixfmt-rfc-style
deadnix
statix
];
checkPhase = '' checkPhase = ''
mkdir -p $out mkdir -p $out
alejandra --check . | tee $out/alejandra.log nixfmt --strict --check . | tee $out/nixfmt.log
deadnix --fail | tee $out/deadnix.log deadnix --fail | tee $out/deadnix.log
statix check | tee $out/statix.log statix check | tee $out/statix.log
''; '';

View file

@ -1,7 +1,4 @@
{ { self, nixosTest }:
self,
nixosTest,
}:
nixosTest { nixosTest {
name = "open-homepage"; name = "open-homepage";

View file

@ -1,18 +1,14 @@
{ { self, system }:
self, { config, lib, ... }:
system, let
}: {
config,
lib,
...
}: let
inherit (lib) mkEnableOption mkIf mkOption; inherit (lib) mkEnableOption mkIf mkOption;
inherit (lib.types) str int; inherit (lib.types) str int;
inherit (lib.strings) escapeShellArgs; inherit (lib.strings) escapeShellArgs;
inherit (self.packages.${system}) server templates; inherit (self.packages.${system}) server templates;
cfg = config.services.tlaternet-webserver; cfg = config.services.tlaternet-webserver;
in { in
{
options = { options = {
services.tlaternet-webserver = { services.tlaternet-webserver = {
enable = mkEnableOption "tlaternet web server"; enable = mkEnableOption "tlaternet web server";
@ -60,14 +56,21 @@ in {
ProtectKernelModules = true; ProtectKernelModules = true;
ProtectKernelLogs = true; ProtectKernelLogs = true;
ProtectControlGroups = true; ProtectControlGroups = true;
RestrictAddressFamilies = ["AF_UNIX" "AF_INET" "AF_INET6"]; RestrictAddressFamilies = [
"AF_UNIX"
"AF_INET"
"AF_INET6"
];
RestrictNamespaces = true; RestrictNamespaces = true;
LockPersonality = true; LockPersonality = true;
MemoryDenyWriteExecute = true; MemoryDenyWriteExecute = true;
RestrictRealtime = true; RestrictRealtime = true;
RestrictSUIDSGID = true; RestrictSUIDSGID = true;
SystemCallArchitectures = "native"; SystemCallArchitectures = "native";
SystemCallFilter = ["@system-service" "~@privileged @resources @setuid @keyring"]; SystemCallFilter = [
"@system-service"
"~@privileged @resources @setuid @keyring"
];
}; };
}; };
}; };

View file

@ -6,20 +6,25 @@
git, git,
nix, nix,
yq-go, yq-go,
}: let }:
let
selfPackages = self.packages.${system}; selfPackages = self.packages.${system};
inherit (selfPackages.server.config.deps) cargo; inherit (selfPackages.server.config.deps) cargo;
inherit (selfPackages.templates.config.deps) npm; inherit (selfPackages.templates.config.deps) npm;
npm-check-updates = npm-check-updates =
(builtins.elemAt (lib.attrValues (builtins.elemAt (lib.attrValues selfPackages.templates.config.nodejs-granular-v3.deps.npm-check-updates) 0)
selfPackages.templates.config.nodejs-granular-v3.deps.npm-check-updates) .package-func.result;
0)
.package-func
.result;
in in
writeShellApplication { writeShellApplication {
name = "update"; name = "update";
runtimeInputs = [cargo git nix npm npm-check-updates yq-go]; runtimeInputs = [
cargo
git
nix
npm
npm-check-updates
yq-go
];
text = builtins.readFile ./scripts/update.sh; text = builtins.readFile ./scripts/update.sh;
} }

View file

@ -1,11 +1,14 @@
{ dream2nix, lib, ... }: { { dream2nix, lib, ... }:
{
imports = [ imports = [
dream2nix.modules.dream2nix.rust-cargo-lock dream2nix.modules.dream2nix.rust-cargo-lock
dream2nix.modules.dream2nix.rust-cargo-vendor dream2nix.modules.dream2nix.rust-cargo-vendor
dream2nix.modules.dream2nix.rust-crane dream2nix.modules.dream2nix.rust-crane
]; ];
deps = {fenix, ...}: { deps =
{ fenix, ... }:
{
deps.cargo = fenix.stable.minimalToolchain; deps.cargo = fenix.stable.minimalToolchain;
}; };

View file

@ -3,15 +3,24 @@
config, config,
lib, lib,
... ...
}: { }:
{
imports = [ imports = [
dream2nix.modules.dream2nix.nodejs-package-json-v3 dream2nix.modules.dream2nix.nodejs-package-json-v3
dream2nix.modules.dream2nix.nodejs-granular-v3 dream2nix.modules.dream2nix.nodejs-granular-v3
dream2nix.modules.dream2nix.nodejs-devshell-v3 dream2nix.modules.dream2nix.nodejs-devshell-v3
]; ];
deps = {nixpkgs, ...}: { deps =
inherit (nixpkgs) pkg-config runCommandLocal rsync vips yj; { nixpkgs, ... }:
{
inherit (nixpkgs)
pkg-config
runCommandLocal
rsync
vips
yj
;
}; };
name = "tlaternet-templates"; name = "tlaternet-templates";