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

View file

@ -10,11 +10,13 @@
}; };
}; };
outputs = { outputs =
{
self, self,
nixpkgs, nixpkgs,
rust-overlay, rust-overlay,
}: let }:
let
systems = [ systems = [
"x86_64-linux" "x86_64-linux"
"aarch64-linux" "aarch64-linux"
@ -23,7 +25,8 @@
]; ];
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: { devShells = forAllSystems (pkgs: {
default = pkgs.mkShell { default = pkgs.mkShell {
packages = with pkgs; [ packages = with pkgs; [
@ -45,21 +48,23 @@
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); formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
nixosModules.default = import ./nix/module.nix self; nixosModules.default = import ./nix/module.nix self;
packages = forAllSystems ({ packages = forAllSystems (
{
lib, lib,
pkgs, pkgs,
system, system,
... ...
}: let }:
let
packages' = self.packages.${system}; packages' = self.packages.${system};
mkStatic = pkgs.callPackage ./nix/static.nix { mkStatic = pkgs.callPackage ./nix/static.nix {
@ -67,26 +72,29 @@
rust-overlay = rust-overlay.packages.${system}; rust-overlay = rust-overlay.packages.${system};
}; };
mkContainerFor = refraction: mkContainerFor =
refraction:
pkgs.dockerTools.buildLayeredImage { pkgs.dockerTools.buildLayeredImage {
name = "refraction"; name = "refraction";
tag = "latest-${refraction.stdenv.hostPlatform.qemuArch}"; tag = "latest-${refraction.stdenv.hostPlatform.qemuArch}";
config.Cmd = [(lib.getExe refraction)]; config.Cmd = [ (lib.getExe refraction) ];
inherit (refraction) architecture; inherit (refraction) architecture;
}; };
in { in
refraction = pkgs.callPackage ./nix/derivation.nix {inherit self;}; {
refraction = pkgs.callPackage ./nix/derivation.nix { inherit self; };
static-x86_64 = mkStatic {arch = "x86_64";}; static-x86_64 = mkStatic { arch = "x86_64"; };
static-aarch64 = mkStatic {arch = "aarch64";}; static-aarch64 = mkStatic { arch = "aarch64"; };
container-x86_64 = mkContainerFor packages'.static-x86_64; container-x86_64 = mkContainerFor packages'.static-x86_64;
container-aarch64 = mkContainerFor packages'.static-aarch64; container-aarch64 = mkContainerFor packages'.static-aarch64;
default = packages'.refraction; default = packages'.refraction;
}); }
);
overlays.default = _: prev: { overlays.default = _: prev: {
refraction = prev.callPackage ./nix/derivation.nix {inherit self;}; refraction = prev.callPackage ./nix/derivation.nix { inherit self; };
}; };
}; };
} }

View file

@ -31,17 +31,22 @@ 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 (
with darwin.apple_sdk.frameworks;
[
CoreFoundation CoreFoundation
Security Security
SystemConfiguration SystemConfiguration
]); ]
);
env = let env =
let
toRustFlags = lib.mapAttrs' ( toRustFlags = lib.mapAttrs' (
name: name:
lib.nameValuePair lib.nameValuePair "CARGO_PROFILE_RELEASE_${
"CARGO_PROFILE_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}" lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] name)
}"
); );
in in
lib.optionalAttrs lto (toRustFlags { lib.optionalAttrs lto (toRustFlags {
@ -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;
} }