Switch to nixfmt-rfc-style

This commit is contained in:
Evan Goode 2025-08-21 23:15:00 -04:00
parent e022009a8c
commit ce83821e8a
2 changed files with 190 additions and 157 deletions

View File

@ -16,10 +16,10 @@ repos:
rev: v1.1.1 rev: v1.1.1
hooks: hooks:
- id: swag-fmt - id: swag-fmt
- repo: https://github.com/kamadorueda/alejandra - repo: https://github.com/NixOS/nixfmt
rev: 3.0.0 rev: v1.0.0
hooks: hooks:
- id: alejandra-system - id: nixfmt
# - repo: https://github.com/pre-commit/mirrors-prettier # - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v3.0.3 # rev: v3.0.3
# hooks: # hooks:

113
flake.nix
View File

@ -5,41 +5,55 @@
nixpkgs.url = "nixpkgs/nixos-unstable"; nixpkgs.url = "nixpkgs/nixos-unstable";
}; };
outputs = { outputs =
{
self, self,
nixpkgs, nixpkgs,
}: let }:
version = let let
version =
let
buildConfig = builtins.readFile ./build_config.go; buildConfig = builtins.readFile ./build_config.go;
lines = nixpkgs.lib.strings.splitString "\n" buildConfig; lines = nixpkgs.lib.strings.splitString "\n" buildConfig;
versionExpr = "^const VERSION = \"([^\"]+)\"$"; versionExpr = "^const VERSION = \"([^\"]+)\"$";
findVersion = lines: findVersion =
if builtins.length lines == 0 lines:
then builtins.error "VERSION not found in build_config.go" if builtins.length lines == 0 then
else let builtins.error "VERSION not found in build_config.go"
else
let
match = builtins.match versionExpr (nixpkgs.lib.head lines); match = builtins.match versionExpr (nixpkgs.lib.head lines);
in in
if match == null if match == null then findVersion (nixpkgs.lib.tail lines) else builtins.elemAt match 0;
then findVersion (nixpkgs.lib.tail lines)
else builtins.elemAt match 0;
in in
findVersion lines; findVersion lines;
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems; forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
overlays = []; overlays = [ ];
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system overlays;}); nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system overlays; });
nixpkgsCross = nixpkgsCross = forAllSystems (
forAllSystems (localSystem: localSystem:
forAllSystems (crossSystem: import nixpkgs {inherit localSystem crossSystem overlays;})); forAllSystems (crossSystem: import nixpkgs { inherit localSystem crossSystem overlays; })
in { );
packages = forAllSystems (system: let in
buildDrasl = pkgs: let {
packages = forAllSystems (
system:
let
buildDrasl =
pkgs:
let
nodejs = pkgs.nodejs_20; nodejs = pkgs.nodejs_20;
npmDeps = pkgs.importNpmLock.buildNodeModules { npmDeps = pkgs.importNpmLock.buildNodeModules {
inherit nodejs; inherit nodejs;
@ -60,7 +74,7 @@
# Update whenever Go dependencies change # Update whenever Go dependencies change
vendorHash = "sha256-4Rk59bnDFYpraoGvkBUW6Z5fiXUmm2RLwS1wxScWAMQ="; vendorHash = "sha256-4Rk59bnDFYpraoGvkBUW6Z5fiXUmm2RLwS1wxScWAMQ=";
outputs = ["out"]; outputs = [ "out" ];
preConfigure = '' preConfigure = ''
substituteInPlace build_config.go --replace-fail "\"/usr/share/drasl\"" "\"$out/share/drasl\"" substituteInPlace build_config.go --replace-fail "\"/usr/share/drasl\"" "\"$out/share/drasl\""
@ -77,13 +91,15 @@
''; '';
}; };
buildOCIImage = pkgs: buildOCIImage =
pkgs:
pkgs.dockerTools.buildLayeredImage { pkgs.dockerTools.buildLayeredImage {
name = "unmojang/drasl"; name = "unmojang/drasl";
contents = with pkgs; [cacert]; contents = with pkgs; [ cacert ];
config.Cmd = ["${buildDrasl pkgs}/bin/drasl"]; config.Cmd = [ "${buildDrasl pkgs}/bin/drasl" ];
}; };
in rec { in
rec {
drasl = buildDrasl nixpkgsFor.${system}; drasl = buildDrasl nixpkgsFor.${system};
drasl-cross-x86_64-linux = buildDrasl nixpkgsCross.${system}.x86_64-linux; drasl-cross-x86_64-linux = buildDrasl nixpkgsCross.${system}.x86_64-linux;
@ -97,23 +113,27 @@
# oci-cross-x86_64-darwin = buildOCIImage nixpkgsCross.${system}.x86_64-darwin; # oci-cross-x86_64-darwin = buildOCIImage nixpkgsCross.${system}.x86_64-darwin;
oci-cross-aarch64-linux = buildOCIImage nixpkgsCross.${system}.aarch64-linux; oci-cross-aarch64-linux = buildOCIImage nixpkgsCross.${system}.aarch64-linux;
# oci-cross-aarch64-darwin = buildOCIImage nixpkgsCross.${system}.aarch64-darwin; # oci-cross-aarch64-darwin = buildOCIImage nixpkgsCross.${system}.aarch64-darwin;
}); }
);
nixosModules.drasl = { nixosModules.drasl =
{
config, config,
lib, lib,
pkgs, pkgs,
... ...
}: }:
with lib; let with lib;
let
cfg = config.services.drasl; cfg = config.services.drasl;
format = pkgs.formats.toml {}; format = pkgs.formats.toml { };
in { in
{
options.services.drasl = { options.services.drasl = {
enable = mkEnableOption (lib.mdDoc ''drasl''); enable = mkEnableOption (lib.mdDoc ''drasl'');
settings = mkOption { settings = mkOption {
type = format.type; type = format.type;
default = {}; default = { };
description = lib.mdDoc '' description = lib.mdDoc ''
config.toml for drasl config.toml for drasl
''; '';
@ -122,14 +142,22 @@
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.services.drasl = { systemd.services.drasl = {
description = "drasl"; description = "drasl";
wantedBy = ["multi-user.target"]; wantedBy = [ "multi-user.target" ];
after = ["network-online.target" "nss-lookup.target"]; after = [
wants = ["network-online.target" "nss-lookup.target"]; "network-online.target"
"nss-lookup.target"
];
wants = [
"network-online.target"
"nss-lookup.target"
];
serviceConfig = let serviceConfig =
let
pkg = self.defaultPackage.${pkgs.system}; pkg = self.defaultPackage.${pkgs.system};
config = format.generate "config.toml" cfg.settings; config = format.generate "config.toml" cfg.settings;
in { in
{
ExecStart = "${pkg}/bin/drasl -config ${config}"; ExecStart = "${pkg}/bin/drasl -config ${config}";
DynamicUser = true; DynamicUser = true;
StateDirectory = "drasl"; StateDirectory = "drasl";
@ -139,14 +167,18 @@
}; };
}; };
devShells = forAllSystems (system: let devShells = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system}; pkgs = nixpkgsFor.${system};
in { in
{
default = pkgs.mkShell { default = pkgs.mkShell {
# https://github.com/go-delve/delve/issues/3085 # https://github.com/go-delve/delve/issues/3085
hardeningDisable = ["fortify"]; hardeningDisable = [ "fortify" ];
buildInputs = with pkgs; [ buildInputs = with pkgs; [
alejandra cabal-install
nixfmt-rfc-style
delve delve
go go
go-swag go-swag
@ -162,7 +194,8 @@
gettext gettext
]; ];
}; };
}); }
);
defaultPackage = forAllSystems (system: self.packages.${system}.drasl); defaultPackage = forAllSystems (system: self.packages.${system}.drasl);
}; };