refactor(nix): cleanup package
This commit is contained in:
parent
55bc54722e
commit
8f4afa9d00
3 changed files with 70 additions and 77 deletions
|
@ -85,7 +85,7 @@
|
|||
};
|
||||
in
|
||||
{
|
||||
refraction = pkgs.callPackage ./nix/derivation.nix { inherit self; };
|
||||
refraction = pkgs.callPackage ./nix/package.nix { };
|
||||
|
||||
static-x86_64 = mkStatic { arch = "x86_64"; };
|
||||
static-aarch64 = mkStatic { arch = "aarch64"; };
|
||||
|
@ -97,7 +97,7 @@
|
|||
);
|
||||
|
||||
overlays.default = _: prev: {
|
||||
refraction = prev.callPackage ./nix/derivation.nix { inherit self; };
|
||||
refraction = prev.callPackage ./nix/package.nix { };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
{
|
||||
lib,
|
||||
stdenv,
|
||||
go,
|
||||
rustPlatform,
|
||||
darwin,
|
||||
self,
|
||||
lto ? true,
|
||||
optimizeSize ? false,
|
||||
}:
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "refraction";
|
||||
version =
|
||||
(lib.importTOML ../Cargo.toml).package.version
|
||||
+ "-${self.shortRev or self.dirtyShortRev or "unknown-dirty"}";
|
||||
|
||||
__structuredAttrs = true;
|
||||
|
||||
src = lib.fileset.toSource {
|
||||
root = ../.;
|
||||
fileset = lib.fileset.unions [
|
||||
../src
|
||||
../build.rs
|
||||
../Cargo.lock
|
||||
../Cargo.toml
|
||||
../tags
|
||||
];
|
||||
};
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ../Cargo.lock;
|
||||
};
|
||||
|
||||
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin (
|
||||
with darwin.apple_sdk.frameworks;
|
||||
[
|
||||
CoreFoundation
|
||||
Security
|
||||
SystemConfiguration
|
||||
]
|
||||
);
|
||||
|
||||
env =
|
||||
let
|
||||
toRustFlags = lib.mapAttrs' (
|
||||
name:
|
||||
lib.nameValuePair "CARGO_PROFILE_RELEASE_${
|
||||
lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] name)
|
||||
}"
|
||||
);
|
||||
in
|
||||
lib.optionalAttrs lto (toRustFlags {
|
||||
lto = "thin";
|
||||
})
|
||||
// lib.optionalAttrs optimizeSize (toRustFlags {
|
||||
codegen-units = "1";
|
||||
opt-level = "s";
|
||||
panic = "abort";
|
||||
strip = "symbols";
|
||||
});
|
||||
|
||||
# useful for container images
|
||||
passthru.architecture = go.GOARCH;
|
||||
|
||||
meta = with lib; {
|
||||
mainProgram = "refraction";
|
||||
description = "Discord bot for Prism Launcher";
|
||||
homepage = "https://github.com/PrismLauncher/refraction";
|
||||
license = licenses.gpl3Plus;
|
||||
maintainers = with maintainers; [
|
||||
getchoo
|
||||
Scrumplex
|
||||
];
|
||||
};
|
||||
}
|
68
nix/package.nix
Normal file
68
nix/package.nix
Normal file
|
@ -0,0 +1,68 @@
|
|||
{
|
||||
lib,
|
||||
stdenv,
|
||||
go,
|
||||
rustPlatform,
|
||||
lto ? !optimizeSize,
|
||||
optimizeSize ? false,
|
||||
}:
|
||||
|
||||
let
|
||||
fs = lib.fileset;
|
||||
toRustFlags = flags: toString (lib.mapAttrsToList (name: value: "-C ${name}=${value}") flags);
|
||||
in
|
||||
assert lib.assertMsg (lto -> !optimizeSize) "`lto` and `optimizeSize` are mutually exclusive";
|
||||
rustPlatform.buildRustPackage rec {
|
||||
pname = "refraction";
|
||||
inherit (passthru.cargoToml.package) version;
|
||||
|
||||
src = fs.toSource {
|
||||
root = ../.;
|
||||
fileset = fs.intersection (fs.gitTracked ../.) (
|
||||
fs.unions [
|
||||
../src
|
||||
../build.rs
|
||||
../Cargo.lock
|
||||
../Cargo.toml
|
||||
../tags
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
cargoLock.lockFile = ../Cargo.lock;
|
||||
|
||||
# `panic=abort` breaks tests womp womp
|
||||
doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform && !optimizeSize;
|
||||
|
||||
env = {
|
||||
RUSTFLAGS = toRustFlags (
|
||||
lib.optionalAttrs lto {
|
||||
lto = "thin";
|
||||
embed-bicode = "yes";
|
||||
}
|
||||
// lib.optionalAttrs optimizeSize {
|
||||
codegen-units = "1";
|
||||
opt-level = "s";
|
||||
panic = "abort";
|
||||
strip = "symbols";
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
passthru = {
|
||||
cargoToml = lib.importTOML ../Cargo.toml;
|
||||
# For container images
|
||||
dockerArchitecture = go.GOARCH;
|
||||
};
|
||||
|
||||
meta = {
|
||||
description = "Discord bot for Prism Launcher";
|
||||
homepage = "https://github.com/PrismLauncher/refraction";
|
||||
license = lib.licenses.gpl3Plus;
|
||||
maintainers = with lib.maintainers; [
|
||||
getchoo
|
||||
Scrumplex
|
||||
];
|
||||
mainProgram = "refraction";
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue