Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] flake updates #48

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 76 additions & 46 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,103 @@
description = "Build a cargo project without extra checks";

inputs = {
nixpkgs.url = "nixpkgs/nixos-23.11";
crane = {
url = "github:ipetkov/crane";
nixpkgs.url = "nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, crane, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
outputs = {
self,
nixpkgs,
rust-overlay,
crane,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};

craneLib = crane.lib.${system};
msrv = "1.63.0";
rustVersions = with pkgs.rust-bin;
builtins.mapAttrs (_name: rust-bin:
rust-bin.override {
extensions = ["rust-src" "rustfmt" "llvm-tools-preview"];
})
{
msrv = stable.${msrv}.default;
stable = stable.latest.default;
nightly = nightly.latest.default;
};

craneLibVersions = builtins.mapAttrs (name: rust-bin: (crane.mkLib pkgs).overrideToolchain (_: rust-bin)) rustVersions;
craneLib = craneLibVersions.nightly;

nginxWithStream = pkgs.nginxMainline.overrideAttrs (oldAttrs: {
configureFlags = oldAttrs.configureFlags ++ [
nginxWithStream = pkgs.nginxMainline.overrideAttrs (oldAttrs: {
configureFlags =
oldAttrs.configureFlags
++ [
"--with-stream"
"--with-stream_ssl_module"
"--error-log-path=/dev/null"
];
});
});

ohttp-relay = craneLib.buildPackage {
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type: builtins.match ".*\\.template$" path != null || craneLib.filterCargoSources path type;
};
strictDeps = true;
ohttp-relay = craneLib.buildPackage {
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type: builtins.match ".*\\.template$" path != null || craneLib.filterCargoSources path type;
};
strictDeps = true;

buildInputs = [
buildInputs =
[
nginxWithStream
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.libiconv
pkgs.darwin.apple_sdk.frameworks.Security
];

preBuild = ''
export PATH=${nginxWithStream}/bin:$PATH
'';
};
in
{
checks = {
inherit ohttp-relay;
};
preBuild = ''
export PATH=${nginxWithStream}/bin:$PATH
'';
};

packages.nginx-with-stream = nginxWithStream;
packages.default = ohttp-relay;
devShells = builtins.mapAttrs (_name: craneLib:
craneLib.devShell {
packages = with pkgs;
[
nginxWithStream
cargo-edit
cargo-nextest
cargo-watch
rust-analyzer
]
++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [
cargo-llvm-cov
];
})
craneLibVersions;
in {
checks = {
inherit ohttp-relay;
};

apps.default = flake-utils.lib.mkApp {
drv = ohttp-relay;
};
packages.nginx-with-stream = nginxWithStream;
packages.default = ohttp-relay;

devShells.default = craneLib.devShell {
checks = self.checks.${system};
apps.default = flake-utils.lib.mkApp {
drv = ohttp-relay;
};

packages = [
nginxWithStream
pkgs.rustup
];
devShells = devShells // {default = devShells.nightly;};

shellHook = ''
rustup default nightly
rustup component add rust-src
export PATH=${pkgs.rustup}/bin:$PATH
'';
};
});
formatter = pkgs.alejandra;
});
}
Loading