Skip to content

Modules #6

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

Merged
merged 4 commits into from
Dec 7, 2024
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master
workflow_dispatch:
schedule:
- cron: '30 13 * * *'
- cron: "30 13 * * *"

jobs:
check:
Expand All @@ -29,6 +29,8 @@ jobs:
run: echo "BN_NEXT_VERSION=$(nix eval .#version.x86_64-linux --raw)" >> $GITHUB_ENV
- name: Run `nix build`
run: nix build
- name: Run `nix flake check`
run: nix flake check
- name: Commit updated version
run: |-
git config --global user.email "noreply@localhost"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jobs:
fail-mode: true
- name: Run `nix build`
run: nix build
- name: Run `nix flake check`
run: nix flake check
126 changes: 110 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,132 @@ More testing is needed; currently only `x86-64_linux` is tested, and only a bit.
Additionally, more variants (e.g. an FHS variant) might be desirable.

## Usage
1. Include the flake in your Nix configuration flake's inputs:

### Run directly

You can run Binary Ninja directly from this flake:

```console
nix run github:jchv/nix-binary-ninja
```

> [!IMPORTANT]
> The experimental features `flakes` and `nix-command` must be enabled for this to succeed.
> For more information, see [Flakes on NixOS Wiki](https://nixos.wiki/wiki/Flakes).

If you want to run a specific edition, you can select an attribute like so:

```console
nix run github:jchv/nix-binary-ninja#binary-ninja-free-wayland
```

For a list of available package attributes, see the [Packages section](#Packages).

### NixOS module

To include Binary Ninja in your NixOS system using this flake, follow these steps:

1. **Add this flake to your NixOS configuration flake's inputs:**

```nix
binaryninja = {
url = "github:jchv/nix-binary-ninja";
inputs.nixpkgs.follows = "nixpkgs";
};
{
inputs = {
nixpkgs = { ... };

# This is what you will want to add.
binaryninja = {
url = "github:jchv/nix-binary-ninja";

# Optional, but recommended.
inputs.nixpkgs.follows = "nixpkgs";
};
};
```
- Also, include the flake input as an argument to your `outputs` function.
2. Include the installer in the nix-store, if not using the free version:

2. **Include the NixOS module in your NixOS system:**

```nix
{
...
# You will need to add a corresponding `binaryninja` parameter to your
# `outputs` function.
outputs = { nixpkgs, binaryninja, ... }:
{
nixosConfigurations.myMachine = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
...

# Then, you'll need to add the module itself.
binaryninja.nixosModules.binaryninja
];
}
}
}
```

This will add new options you can use in your NixOS configuration.

3. **Enable Binary Ninja in your NixOS configuration:**

This can go in any NixOS configuration module imported by your configuration:

```nix
{
programs.binary-ninja.enable = true;
}
```

If you want to use a specific version, you can select this using `programs.binary-ninja.package`:

```nix
{ pkgs, ... }: {
programs.binary-ninja = {
enable = true;
package = pkgs.binary-ninja-free-wayland;
}
}
```

For a list of available package attributes, see the [Packages section](#Packages).

4. **Add the installer to the nix-store, if not using the free version:**

```bash
nix-store --add-fixed sha256 <path-to-installer>.zip
```
- You can get a copy of the latest release using your registered e-mail address [here](https://binary.ninja/recover/).
3. Include the appropriate package edition from the [Packages section](#Packages) in your packages:

You can get a copy of the latest release using your registered e-mail address [here](https://binary.ninja/recover/).

If you want, it is possible to include a copy of Binary Ninja in your NixOS configuration to avoid this step.
If you choose to do this, please be mindful to not accidentally leak your copy of Binary Ninja.

To do this, you need to override the Binary Ninja package, like this:

```nix
environment.systemPackages = with pkgs; [
binaryninja.packages.${pkgs.system}.<package-attribute>
];
{ pkgs, ... }: {
programs.binary-ninja = {
enable = true;
package = pkgs.binary-ninja-personal-wayland.override {
# The path of the filename here should be relative to the Nix file
# it's written in.
overrideSource = ./binaryninja_personal_linux.zip;
};
}
}
```
- replace `<package-attribute>` with your chosen edition

## Packages
The following package attributes are available:

- `binary-ninja-free`
- `binary-ninja-personal`
- `binary-ninja-commercial`
- `binary-ninja-enterprise`
- `binary-ninja-ultimate`
- `binary-ninja-free-wayland`
- `binary-ninja-personal-wayland`
- `binary-ninja-commercial-wayland`
- `binary-ninja-enterprise-wayland`
- `binary-ninja-ultimate-wayland`

For the free version, please see the License section.

Expand Down Expand Up @@ -65,7 +159,7 @@ platform and add it to the Nix store, using, for example, the following command:
$ nix-store --add-fixed sha256 ./binary-linux-commercial.zip
```

Of course, your usage of personal, commercial and enterprise Binary Ninja is
Of course, your usage of personal, commercial and ultimate Binary Ninja is
governed by your respective agreements.

### Nix Flake
Expand Down
13 changes: 7 additions & 6 deletions flake.lock

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

51 changes: 37 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,54 @@
description = "Flake for building Binary Ninja";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{ nixpkgs, flake-utils, ... }:
inputs@{
self,
nixpkgs,
flake-utils,
}:
let
mkPackages =
pkgs:
let
lib = pkgs.lib;
sources = import ./sources.nix pkgs;
editions = lib.mapAttrs' (binaryNinjaEdition: value: {
name = "binary-ninja-${binaryNinjaEdition}";
value = pkgs.callPackage ./package.nix { inherit binaryNinjaEdition; };
}) sources.editions;
editionsWayland = lib.mapAttrs' (name: value: {
name = "${name}-wayland";
value = value.override { forceWayland = true; };
}) editions;
in
editions // editionsWayland;
in
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
sources = pkgs.callPackage ./sources.nix { };
editions = lib.mapAttrs' (binaryNinjaEdition: value: {
name = "binary-ninja-${binaryNinjaEdition}";
value = pkgs.callPackage ./package.nix { inherit binaryNinjaEdition; };
}) sources.editions;
editionsWayland = lib.mapAttrs' (name: value: {
name = "${name}-wayland";
value = value.override { forceWayland = true; };
}) editions;
packages = editions // editionsWayland // { default = editions.binary-ninja-free; };
packages = mkPackages pkgs;
in
{
inherit (sources) version;
inherit packages;
checks = {
simple = pkgs.callPackage ./tests/simple-nixos.nix { inherit self; };
};
packages = packages // {
default = packages.binary-ninja-free;
};
}
);
)
// {
overlays.default = final: prev: mkPackages prev;
nixosModules.binaryninja = import ./module.nix inputs;
darwinModules.binaryninja = import ./module.nix inputs;
hmModules.binaryninja = import ./hm-module.nix inputs;
};
}
15 changes: 15 additions & 0 deletions hm-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ self, ... }:
{ config, lib, ... }:
let
cfg = config.programs.binary-ninja;
in
{
imports = [
./options.nix
];

config = lib.mkIf cfg.enable {
nixpkgs.overlays = [ self.overlays.default ];
home.packages = [ cfg.package ];
};
}
15 changes: 15 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ self, ... }:
{ config, lib, ... }:
let
cfg = config.programs.binary-ninja;
in
{
imports = [
./options.nix
];

config = lib.mkIf cfg.enable {
nixpkgs.overlays = [ self.overlays.default ];
environment.systemPackages = [ cfg.package ];
};
}
33 changes: 33 additions & 0 deletions options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ lib, pkgs, ... }:
{
options = {
programs.binary-ninja = {
enable = lib.mkEnableOption "Binary Ninja";
package = lib.mkOption {
type = lib.types.package;
description = ''
Package to install. Defaults to the free (as in beer) edition of Binary Ninja.

This overlay provides the following editions:
- `binary-ninja-free`
- `binary-ninja-personal`
- `binary-ninja-commercial`
- `binary-ninja-ultimate`
- `binary-ninja-free-wayland`
- `binary-ninja-personal-wayland`
- `binary-ninja-commercial-wayland`
- `binary-ninja-ultimate-wayland`
'';
default = pkgs.binary-ninja-free;
defaultText = lib.literalExpression ''pkgs.binary-ninja-free'';
example = lib.literalExpression ''
pkgs.binary-ninja-personal-wayland.override {
# Use a local copy of Binary Ninja, stored in your Nix configuration.
# (Please be mindful to not leak your licensed copy of binary ninja.)
overrideSource = ./binaryninja_personal_linux.zip;
};
'';
};
};
};
}
5 changes: 4 additions & 1 deletion package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@

binaryNinjaEdition ? "personal",
forceWayland ? false,
overrideSource ? null,
}:
let
sources = callPackage ./sources.nix { };
platformSources = sources.editions.${binaryNinjaEdition};
source =
if builtins.hasAttr stdenv.hostPlatform.system platformSources then
if overrideSource != null then
overrideSource
else if builtins.hasAttr stdenv.hostPlatform.system platformSources then
platformSources.${stdenv.hostPlatform.system}
else
throw "No source for system ${stdenv.hostPlatform.system}";
Expand Down
3 changes: 2 additions & 1 deletion sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
lib,
requireFile,
fetchurl,
...
}:
let
data = builtins.fromJSON (builtins.readFile ./hashes.js);
Expand All @@ -10,7 +11,7 @@ let
"free"
"personal"
"commercial"
"enterprise"
"ultimate"
];
mkFreeSource =
name:
Expand Down
Loading