Skip to content

Commit

Permalink
Merge pull request #163 from ralexstokes/nixos-module
Browse files Browse the repository at this point in the history
Nixos module
  • Loading branch information
ralexstokes authored Oct 24, 2023
2 parents 2cfd7e6 + 6de635a commit 08973a2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 83 deletions.
83 changes: 18 additions & 65 deletions flake.lock

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

35 changes: 19 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
Expand All @@ -18,20 +14,27 @@
};

outputs = { self, flake-utils, nixpkgs, rust-overlay, crane }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
mev-rs = system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
mev = pkgs.callPackage ./nix/mev.nix { inherit pkgs; crane = craneLib; };
in
{
devShells.default = import ./shell.nix { inherit pkgs; };
overlays.default = _: _: {
inherit mev;
};
packages.mev = mev;
});
pkgs.callPackage ./nix/mev-rs.nix { inherit pkgs; crane = craneLib; };
in
{
nixosModules.mev-rs = import ./nix/module.nix { inherit mev-rs; };
nixosModules.default = self.nixosModules.mev-rs;

packages.x86_64-darwin.mev-rs = mev-rs "x86_64-darwin";
packages.x86_64-darwin.default = self.packages.x86_64-darwin.mev-rs;

packages.aarch64-darwin.mev-rs = mev-rs "aarch64-darwin";
packages.aarch64-darwin.default = self.packages.aarch64-darwin.mev-rs;

packages.x86_64-linux.mev-rs = mev-rs "x86_64-linux";
packages.x86_64-linux.default = self.packages.x86_64-linux.mev-rs;
};
}
3 changes: 2 additions & 1 deletion nix/mev.nix → nix/mev-rs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let
buildInputs = lib.optionals pkgs.stdenv.isLinux [
openssl
] ++ lib.optionals pkgs.stdenv.isDarwin [
darwin.apple_sdk.frameworks.Network
darwin.apple_sdk.frameworks.CFNetwork
darwin.apple_sdk.frameworks.SystemConfiguration
];
nativeBuildInputs = lib.optionals pkgs.stdenv.isLinux [
clang
Expand Down
47 changes: 47 additions & 0 deletions nix/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
pkg:
{ config, lib, pkgs, ... }:
let
cfg = config.services.mev-rs;

mev-rs = pkg.mev-rs pkgs.system;

name = "mev-${cfg.enable}-rs";

cmd = ''
${mev-rs}/bin/mev \
${cfg.enable} \
${cfg.config-file}
'';
in
{
options.services.mev-rs = {
enable = lib.mkOption {
type = lib.types.enum [ "boost" "build" ];
description = "which subcommand of `mev-rs` to run";
};
config-file = lib.mkOption {
type = lib.types.str;
description = ''
path to a config file suitable for the `mev-rs` toolkit
'';
};
};

config = {
environment.systemPackages = [
mev-rs
];

systemd.services."${name}" = {
description = name;
wantedBy = [ "multi-user.target" ];
after = [ "vc.service" ];
serviceConfig = {
ExecStart = cmd;
Restart = "on-failure";
RestartSec = "10s";
SyslogIdentifier = name;
};
};
};
}
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mkShell {
openssl
] ++ lib.optionals pkgs.stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.Network
darwin.apple_sdk.frameworks.CFNetwork
] ++ [
just
mdbook
Expand Down

0 comments on commit 08973a2

Please sign in to comment.