style(nix): alejandra -> nixfmt-rfc-style

This commit is contained in:
seth 2024-08-06 23:26:02 -04:00 committed by Sefa Eyeoglu
parent bdb2ef7c4c
commit 068da95e36
4 changed files with 127 additions and 106 deletions

146
flake.nix
View file

@ -10,83 +10,91 @@
}; };
}; };
outputs = { outputs =
self, {
nixpkgs, self,
rust-overlay, nixpkgs,
}: let rust-overlay,
systems = [ }:
"x86_64-linux" let
"aarch64-linux" systems = [
"x86_64-darwin" "x86_64-linux"
"aarch64-darwin" "aarch64-linux"
]; "x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system}); forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
in { in
devShells = forAllSystems (pkgs: { {
default = pkgs.mkShell { devShells = forAllSystems (pkgs: {
packages = with pkgs; [ default = pkgs.mkShell {
redis packages = with pkgs; [
redis
# linters & formatters # linters & formatters
actionlint actionlint
nodePackages.prettier nodePackages.prettier
# rust tools # rust tools
clippy clippy
rustfmt rustfmt
rust-analyzer rust-analyzer
# nix tools # nix tools
self.formatter.${system} self.formatter.${system}
deadnix deadnix
nil nil
statix statix
]; ];
inputsFrom = [self.packages.${pkgs.system}.refraction]; inputsFrom = [ self.packages.${pkgs.system}.refraction ];
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
};
});
formatter = forAllSystems (pkgs: pkgs.alejandra);
nixosModules.default = import ./nix/module.nix self;
packages = forAllSystems ({
lib,
pkgs,
system,
...
}: let
packages' = self.packages.${system};
mkStatic = pkgs.callPackage ./nix/static.nix {
inherit (self.packages.${pkgs.system}) refraction;
rust-overlay = rust-overlay.packages.${system};
};
mkContainerFor = refraction:
pkgs.dockerTools.buildLayeredImage {
name = "refraction";
tag = "latest-${refraction.stdenv.hostPlatform.qemuArch}";
config.Cmd = [(lib.getExe refraction)];
inherit (refraction) architecture;
}; };
in { });
refraction = pkgs.callPackage ./nix/derivation.nix {inherit self;};
static-x86_64 = mkStatic {arch = "x86_64";}; formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
static-aarch64 = mkStatic {arch = "aarch64";};
container-x86_64 = mkContainerFor packages'.static-x86_64;
container-aarch64 = mkContainerFor packages'.static-aarch64;
default = packages'.refraction; nixosModules.default = import ./nix/module.nix self;
});
overlays.default = _: prev: { packages = forAllSystems (
refraction = prev.callPackage ./nix/derivation.nix {inherit self;}; {
lib,
pkgs,
system,
...
}:
let
packages' = self.packages.${system};
mkStatic = pkgs.callPackage ./nix/static.nix {
inherit (self.packages.${pkgs.system}) refraction;
rust-overlay = rust-overlay.packages.${system};
};
mkContainerFor =
refraction:
pkgs.dockerTools.buildLayeredImage {
name = "refraction";
tag = "latest-${refraction.stdenv.hostPlatform.qemuArch}";
config.Cmd = [ (lib.getExe refraction) ];
inherit (refraction) architecture;
};
in
{
refraction = pkgs.callPackage ./nix/derivation.nix { inherit self; };
static-x86_64 = mkStatic { arch = "x86_64"; };
static-aarch64 = mkStatic { arch = "aarch64"; };
container-x86_64 = mkContainerFor packages'.static-x86_64;
container-aarch64 = mkContainerFor packages'.static-aarch64;
default = packages'.refraction;
}
);
overlays.default = _: prev: {
refraction = prev.callPackage ./nix/derivation.nix { inherit self; };
};
}; };
};
} }

View file

@ -31,19 +31,24 @@ rustPlatform.buildRustPackage {
lockFile = ../Cargo.lock; lockFile = ../Cargo.lock;
}; };
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ buildInputs = lib.optionals stdenv.hostPlatform.isDarwin (
CoreFoundation with darwin.apple_sdk.frameworks;
Security [
SystemConfiguration CoreFoundation
]); Security
SystemConfiguration
]
);
env = let env =
toRustFlags = lib.mapAttrs' ( let
name: toRustFlags = lib.mapAttrs' (
lib.nameValuePair name:
"CARGO_PROFILE_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}" lib.nameValuePair "CARGO_PROFILE_RELEASE_${
); lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] name)
in }"
);
in
lib.optionalAttrs lto (toRustFlags { lib.optionalAttrs lto (toRustFlags {
lto = "thin"; lto = "thin";
}) })
@ -62,6 +67,9 @@ rustPlatform.buildRustPackage {
description = "Discord bot for Prism Launcher"; description = "Discord bot for Prism Launcher";
homepage = "https://github.com/PrismLauncher/refraction"; homepage = "https://github.com/PrismLauncher/refraction";
license = licenses.gpl3Plus; license = licenses.gpl3Plus;
maintainers = with maintainers; [getchoo Scrumplex]; maintainers = with maintainers; [
getchoo
Scrumplex
];
}; };
} }

View file

@ -1,14 +1,15 @@
self: { self:
{
config, config,
lib, lib,
pkgs, pkgs,
... ...
}: let }:
let
cfg = config.services.refraction; cfg = config.services.refraction;
defaultUser = "refraction"; defaultUser = "refraction";
inherit inherit (lib)
(lib)
getExe getExe
literalExpression literalExpression
mdDoc mdDoc
@ -19,10 +20,11 @@ self: {
optionals optionals
types types
; ;
in { in
{
options.services.refraction = { options.services.refraction = {
enable = mkEnableOption "refraction"; enable = mkEnableOption "refraction";
package = mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "refraction" {}; package = mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "refraction" { };
user = mkOption { user = mkOption {
description = mdDoc '' description = mdDoc ''
@ -84,10 +86,8 @@ in {
systemd.services."refraction" = { systemd.services."refraction" = {
enable = true; enable = true;
wantedBy = ["multi-user.target"]; wantedBy = [ "multi-user.target" ];
after = after = [ "network.target" ] ++ optionals (cfg.redisUrl == "local") [ "redis-refraction.service" ];
["network.target"]
++ optionals (cfg.redisUrl == "local") ["redis-refraction.service"];
script = '' script = ''
${getExe cfg.package} ${getExe cfg.package}
@ -95,9 +95,10 @@ in {
environment = { environment = {
BOT_REDIS_URL = BOT_REDIS_URL =
if cfg.redisUrl == "local" if cfg.redisUrl == "local" then
then "unix:${config.services.redis.servers.refraction.unixSocket}" "unix:${config.services.redis.servers.refraction.unixSocket}"
else cfg.redisUrl; else
cfg.redisUrl;
}; };
serviceConfig = { serviceConfig = {
@ -141,9 +142,7 @@ in {
}; };
}; };
groups = mkIf (cfg.group == defaultUser) { groups = mkIf (cfg.group == defaultUser) { ${defaultUser} = { }; };
${defaultUser} = {};
};
}; };
}; };
} }

View file

@ -3,7 +3,9 @@
refraction, refraction,
rust-overlay, rust-overlay,
pkgsCross, pkgsCross,
}: {arch}: let }:
{ arch }:
let
targets = with pkgsCross; { targets = with pkgsCross; {
x86_64 = musl64.pkgsStatic; x86_64 = musl64.pkgsStatic;
aarch64 = aarch64-multiplatform.pkgsStatic; aarch64 = aarch64-multiplatform.pkgsStatic;
@ -11,17 +13,21 @@
getRustcTarget = pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget; getRustcTarget = pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget;
toolchain = rust-overlay.rust.minimal.override { toolchain = rust-overlay.rust.minimal.override {
extensions = ["rust-std"]; extensions = [ "rust-std" ];
targets = lib.mapAttrsToList (lib.const getRustcTarget) targets; targets = lib.mapAttrsToList (lib.const getRustcTarget) targets;
}; };
mkRustPlatformWith = pkgs: mkRustPlatformWith =
pkgs:
pkgs.makeRustPlatform ( pkgs.makeRustPlatform (
lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) lib.genAttrs [
"cargo"
"rustc"
] (lib.const toolchain)
); );
rustPlatforms = lib.mapAttrs (lib.const mkRustPlatformWith) targets; rustPlatforms = lib.mapAttrs (lib.const mkRustPlatformWith) targets;
in in
refraction.override { refraction.override {
rustPlatform = rustPlatforms.${arch}; rustPlatform = rustPlatforms.${arch};
optimizeSize = true; optimizeSize = true;
} }