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

123
flake.nix
View file

@ -14,70 +14,77 @@
}; };
}; };
outputs = { outputs =
self, {
nixpkgs, self,
dream2nix, nixpkgs,
fenix, dream2nix,
}: let fenix,
# At the moment, we only deploy to x86_64-linux. Update when we }:
# care about another platform. let
system = "x86_64-linux"; # At the moment, we only deploy to x86_64-linux. Update when we
pkgs = nixpkgs.legacyPackages.${system}; # care about another platform.
fenixPkgs = fenix.packages.${system}; system = "x86_64-linux";
ownPkgs = self.packages.${system}; pkgs = nixpkgs.legacyPackages.${system};
in { fenixPkgs = fenix.packages.${system};
packages.${system} = dream2nix.lib.importPackages { ownPkgs = self.packages.${system};
projectRoot = ./.; in
projectRootFile = "flake.nix"; {
packagesDir = ./packages; packages.${system} = dream2nix.lib.importPackages {
packageSets = { projectRoot = ./.;
nixpkgs = pkgs; projectRootFile = "flake.nix";
fenix = fenixPkgs; packagesDir = ./packages;
}; packageSets = {
}; nixpkgs = pkgs;
fenix = fenixPkgs;
apps.${system} = { };
default = let
inherit (ownPkgs) server templates;
inherit (pkgs) writeShellScript;
in {
type = "app";
program = builtins.toString (writeShellScript "tlaternet-webserver" ''
${server}/bin/tlaternet-webserver --template-directory ${templates}
'');
}; };
update = let apps.${system} = {
update-script = pkgs.callPackage ./nix/update.nix {inherit self;}; default =
in { let
type = "app"; inherit (ownPkgs) server templates;
program = "${update-script}/bin/update"; inherit (pkgs) writeShellScript;
in
{
type = "app";
program = builtins.toString (
writeShellScript "tlaternet-webserver" ''
${server}/bin/tlaternet-webserver --template-directory ${templates}
''
);
};
update =
let
update-script = pkgs.callPackage ./nix/update.nix { inherit self; };
in
{
type = "app";
program = "${update-script}/bin/update";
};
}; };
};
nixosModules.default = import ./nix/module.nix {inherit self system;}; nixosModules.default = import ./nix/module.nix { inherit self system; };
devShells.${system} = { devShells.${system} = {
server = pkgs.mkShell { server = pkgs.mkShell {
packages = [ packages = [
(fenixPkgs.stable.withComponents [ (fenixPkgs.stable.withComponents [
"rustc" "rustc"
"cargo" "cargo"
"rustfmt" "rustfmt"
"rust-std" "rust-std"
"rust-docs" "rust-docs"
"clippy" "clippy"
"rust-src" "rust-src"
"rust-analysis" "rust-analysis"
]) ])
fenixPkgs.rust-analyzer fenixPkgs.rust-analyzer
]; ];
};
}; };
};
checks.${system} = import ./nix/checks { checks.${system} = import ./nix/checks { inherit self pkgs; };
inherit self pkgs;
}; };
};
} }

View file

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

View file

@ -2,26 +2,31 @@
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 {
dontPatch = true; dontPatch = true;
dontConfigure = true; dontConfigure = true;
dontBuild = true; dontBuild = true;
dontInstall = true; dontInstall = true;
doCheck = true; doCheck = true;
name = "lint-nix"; name = "lint-nix";
src = sourceFilesBySuffices self [".nix"]; src = sourceFilesBySuffices self [ ".nix" ];
checkInputs = [alejandra deadnix statix]; checkInputs = [
checkPhase = '' nixfmt-rfc-style
mkdir -p $out deadnix
alejandra --check . | tee $out/alejandra.log statix
deadnix --fail | tee $out/deadnix.log ];
statix check | tee $out/statix.log checkPhase = ''
''; mkdir -p $out
} nixfmt --strict --check . | tee $out/nixfmt.log
deadnix --fail | tee $out/deadnix.log
statix check | tee $out/statix.log
'';
}

View file

@ -1,19 +1,16 @@
{ { self, nixosTest }:
self,
nixosTest,
}:
nixosTest { nixosTest {
name = "open-homepage"; name = "open-homepage";
nodes = { nodes = {
# Host with just the default configuration # Host with just the default configuration
defaults = { defaults = {
imports = [self.nixosModules.default]; imports = [ self.nixosModules.default ];
services.tlaternet-webserver.enable = true; services.tlaternet-webserver.enable = true;
}; };
host = { host = {
imports = [self.nixosModules.default]; imports = [ self.nixosModules.default ];
services.tlaternet-webserver = { services.tlaternet-webserver = {
enable = true; enable = true;
@ -23,10 +20,10 @@ nixosTest {
}; };
}; };
networking.firewall.allowedTCPPorts = [8080]; networking.firewall.allowedTCPPorts = [ 8080 ];
}; };
client = {}; client = { };
}; };
testScript = '' testScript = ''

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";
@ -35,8 +31,8 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.services.tlaternet-webserver = { systemd.services.tlaternet-webserver = {
description = "tlaternet webserver"; description = "tlaternet webserver";
wantedBy = ["multi-user.target"]; wantedBy = [ "multi-user.target" ];
after = ["network.target"]; after = [ "network.target" ];
script = escapeShellArgs [ script = escapeShellArgs [
"${server}/bin/tlaternet-webserver" "${server}/bin/tlaternet-webserver"
@ -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 = [
text = builtins.readFile ./scripts/update.sh; cargo
} git
nix
npm
npm-check-updates
yq-go
];
text = builtins.readFile ./scripts/update.sh;
}

View file

@ -1,13 +1,16 @@
{ 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 =
deps.cargo = fenix.stable.minimalToolchain; { fenix, ... }:
}; {
deps.cargo = fenix.stable.minimalToolchain;
};
inherit inherit
((lib.pipe ./Cargo.toml [ ((lib.pipe ./Cargo.toml [

View file

@ -3,28 +3,37 @@
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";
version = "0.1.0"; version = "0.1.0";
mkDerivation = { mkDerivation = {
src = config.deps.runCommandLocal "source" {nativeBuildInputs = [config.deps.yj];} '' src = config.deps.runCommandLocal "source" { nativeBuildInputs = [ config.deps.yj ]; } ''
cp -r ${./.} $out/ cp -r ${./.} $out/
chmod -R u+w $out chmod -R u+w $out
yj < $out/package.yaml > $out/package.json yj < $out/package.yaml > $out/package.json
''; '';
nativeBuildInputs = [config.deps.yj]; nativeBuildInputs = [ config.deps.yj ];
# The default phase (which is hidden in `preInstallPhases`) will # The default phase (which is hidden in `preInstallPhases`) will
# copy the full node_modules directory to the output, and symlink # copy the full node_modules directory to the output, and symlink
@ -32,7 +41,7 @@
# #
# Since this package's output is static HTML/JS, we do not want # Since this package's output is static HTML/JS, we do not want
# that. # that.
preInstallPhases = lib.mkForce []; preInstallPhases = lib.mkForce [ ];
installPhase = '' installPhase = ''
cp -r dist $out cp -r dist $out
''; '';