-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
253 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,7 @@ testem.log | |
.DS_Store | ||
Thumbs.db | ||
|
||
.nx/cache | ||
# direnv | ||
.direnv/ | ||
|
||
.nx/cache |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,125 @@ | ||
{ | ||
description = "A nfo file generator for your anime. Source from Bangumi."; | ||
|
||
inputs = { | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
devshell.url = "github:numtide/devshell"; | ||
crane = { | ||
url = "github:ipetkov/crane"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
rust-overlay.url = "github:oxalica/rust-overlay"; | ||
rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; | ||
treefmt-nix.url = "github:numtide/treefmt-nix"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
overlays = | ||
[ (import rust-overlay) (final: prev: { nodejs = prev.nodejs_20; }) ]; | ||
pkgs = import nixpkgs { inherit system overlays; }; | ||
|
||
# workaround for rust compile failed with | ||
# ld: framework not found Security | ||
# source: | ||
# https://discourse.nixos.org/t/compile-a-rust-binary-on-macos-dbcrossbar/8612 | ||
securityFrameworks = if pkgs.stdenv.isDarwin then [ | ||
pkgs.darwin.apple_sdk.frameworks.Security | ||
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration | ||
] else | ||
[ ]; | ||
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; | ||
in with pkgs; { | ||
packages.server = pkgs.rustPlatform.buildRustPackage { | ||
pname = "server"; | ||
nativeBuildInputs = [ pkgs.pkg-config rust ] ++ securityFrameworks; | ||
version = "0.0.0"; | ||
src = ./.; | ||
cargoBuildFlags = "-p server"; | ||
doCheck = false; | ||
cargoLock = { | ||
lockFile = ./Cargo.lock; | ||
outputHashes = { | ||
"ts-rs-6.2.0" = | ||
"sha256-3FVqiUDB9DZe6WpseNaac/Lxxv2CALMao8x8xmEAGvc="; | ||
}; | ||
outputs = | ||
inputs @ { flake-parts, crane, ... }: | ||
flake-parts.lib.mkFlake { inherit inputs; } { | ||
imports = [ | ||
inputs.devshell.flakeModule | ||
inputs.treefmt-nix.flakeModule | ||
]; | ||
|
||
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; | ||
perSystem = { config, self', inputs', pkgs, system, ... }: | ||
let | ||
targets = [ "wasm32-unknown-unknown" "x86_64-unknown-linux-gnu" ]; | ||
|
||
rustToolchain = pkgs.rust-bin.stable.latest.default.override { | ||
extensions = [ "rust-src" ]; | ||
inherit targets; | ||
}; | ||
|
||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; | ||
}; | ||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; | ||
src = craneLib.cleanCargoSource (craneLib.path ./.); | ||
|
||
securityFrameworks = | ||
if pkgs.stdenv.isDarwin then [ | ||
pkgs.darwin.apple_sdk.frameworks.Security | ||
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration | ||
] else [ ]; | ||
|
||
commonArgs = { | ||
pname = "boluo-deps"; | ||
version = "0.0.0"; | ||
|
||
inherit src; | ||
strictDeps = true; | ||
|
||
nativeBuildInputs = with pkgs; [ pkg-config ]; | ||
buildInputs = with pkgs; [ openssl ] ++ securityFrameworks; | ||
}; | ||
|
||
cargoArtifacts = craneLib.buildDepsOnly commonArgs; | ||
server = craneLib.buildPackage ( | ||
commonArgs | ||
// { | ||
pname = "server"; | ||
version = "0.0.0"; | ||
|
||
packages.manage = pkgs.rustPlatform.buildRustPackage { | ||
pname = "manage-cli"; | ||
nativeBuildInputs = [ pkgs.pkg-config rust ] ++ securityFrameworks; | ||
version = "0.0.0"; | ||
src = ./.; | ||
cargoBuildFlags = "-p manage-cli"; | ||
doCheck = false; | ||
cargoLock = { | ||
lockFile = ./Cargo.lock; | ||
outputHashes = { | ||
"ts-rs-6.2.0" = | ||
"sha256-3FVqiUDB9DZe6WpseNaac/Lxxv2CALMao8x8xmEAGvc="; | ||
inherit cargoArtifacts; | ||
cargoExtraArgs = "--package=server"; | ||
} | ||
); | ||
in | ||
{ | ||
_module.args.pkgs = import inputs.nixpkgs { | ||
inherit system; | ||
overlays = [ | ||
inputs.rust-overlay.overlays.default | ||
]; | ||
config = { }; | ||
}; | ||
|
||
packages = { | ||
server = server; | ||
default = self'.packages.current; | ||
}; | ||
|
||
checks = { | ||
# Build the crate as part of `nix flake check` for convenience | ||
inherit server; | ||
|
||
# Run clippy (and deny all warnings) on the crate source, | ||
# again, resuing the dependency artifacts from above. | ||
# | ||
# Note that this is done as a separate derivation so that | ||
# we can block the CI if there are issues here, but not | ||
# prevent downstream consumers from building our crate by itself. | ||
crate-clippy = craneLib.cargoClippy (commonArgs | ||
// { | ||
inherit cargoArtifacts; | ||
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; | ||
}); | ||
|
||
crate-doc = craneLib.cargoDoc (commonArgs | ||
// { | ||
inherit cargoArtifacts; | ||
}); | ||
|
||
# Check formatting | ||
crate-fmt = craneLib.cargoFmt { | ||
inherit src; | ||
}; | ||
}; | ||
|
||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; | ||
}; | ||
devshells.default = { | ||
packages = with pkgs; [ | ||
clang | ||
config.treefmt.build.wrapper | ||
rust-analyzer | ||
rustToolchain | ||
]; | ||
}; | ||
|
||
devShells.default = mkShell { | ||
buildInputs = [ rust nodejs just nodePackages.pnpm ] | ||
++ securityFrameworks; | ||
nativeBuildInputs = [ pkgs.pkg-config ]; | ||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; | ||
treefmt = { | ||
projectRootFile = "flake.nix"; | ||
programs = { | ||
nixpkgs-fmt.enable = true; | ||
rustfmt.enable = true; | ||
prettier.enable = true; | ||
}; | ||
}; | ||
}; | ||
}); | ||
}; | ||
} |