Skip to content

Commit

Permalink
Merge pull request #261 from helsing-ai/tk/add-default-overlay
Browse files Browse the repository at this point in the history
Add default overlay.

Allows conveniently installing buffrs within your devShell and/or home-manager.
  • Loading branch information
tomkarw authored Jul 9, 2024
2 parents f8bd7e4 + 9998adc commit 739d002
Showing 1 changed file with 70 additions and 59 deletions.
129 changes: 70 additions & 59 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,75 +18,86 @@
};

outputs = { self, flake-utils, rust-overlay, crane, advisory-db, nixpkgs, }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) lib callPackage;
rustToolchain = callPackage ./nix/toolchain.nix { };
let
perSystemOutputs = flake-utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) lib callPackage;
rustToolchain = callPackage ./nix/toolchain.nix { };

darwinFrameworks = with pkgs.darwin.apple_sdk.frameworks; [
Security
SystemConfiguration
];
darwinFrameworks = with pkgs.darwin.apple_sdk.frameworks; [
Security
SystemConfiguration
];

devTools = [ rustToolchain ];
devTools = [ rustToolchain ];

dependencies = with pkgs;
[ libiconv ] ++ lib.lists.optionals stdenv.isDarwin darwinFrameworks;
dependencies = with pkgs;
[ libiconv ]
++ lib.lists.optionals stdenv.isDarwin darwinFrameworks;

nativeBuildInputs = with pkgs; [ pkg-config ] ++ dependencies;
nativeBuildInputs = with pkgs; [ pkg-config ] ++ dependencies;

buildEnvVars = {
NIX_LDFLAGS = [ "-L" "${pkgs.libiconv}/lib" ];
OPENSSL_NO_VENDOR = 1;
};
buildEnvVars = {
NIX_LDFLAGS = [ "-L" "${pkgs.libiconv}/lib" ];
OPENSSL_NO_VENDOR = 1;
};

buffrs = callPackage ./nix/buffrs.nix {
inherit crane advisory-db buildEnvVars nativeBuildInputs
rustToolchain;
buffrs = callPackage ./nix/buffrs.nix {
inherit crane advisory-db buildEnvVars nativeBuildInputs
rustToolchain;

buildInputs = [ rustToolchain ];
};
in {
# NB: if this does not build and you need to modify the file,
# please ensure you also make the corresponding changes in the devshell
packages.default = buffrs.package;
apps.default = flake-utils.lib.mkApp { drv = buffrs.package; };
buildInputs = [ rustToolchain ];
};

lib.vendorDependencies =
pkgs.callPackage ./nix/cache.nix { buffrs = buffrs.package; };
app = flake-utils.lib.mkApp { drv = buffrs.package; };
in {
# NB: if this does not build and you need to modify the file,
# please ensure you also make the corresponding changes in the devshell
packages.default = buffrs.package;
apps.default = app;

devShells.default = pkgs.mkShell ({
nativeBuildInputs = nativeBuildInputs ++ [ pkgs.protobuf ];
buildInputs = devTools ++ dependencies;
} // buildEnvVars);
lib.vendorDependencies =
pkgs.callPackage ./nix/cache.nix { buffrs = buffrs.package; };

formatter = with pkgs;
writeShellApplication {
name = "nixfmt-nix-files";
runtimeInputs = [ fd nixfmt-classic ];
text = "fd \\.nix\\$ --hidden --type f | xargs nixfmt";
};
devShells.default = pkgs.mkShell ({
nativeBuildInputs = nativeBuildInputs ++ [ pkgs.protobuf ];
buildInputs = devTools ++ dependencies;
} // buildEnvVars);

checks = ({
nix-files-are-formatted = pkgs.stdenvNoCC.mkDerivation {
name = "fmt-check";
dontBuild = true;
src = ./.;
doCheck = true;
nativeBuildInputs = with pkgs; [ fd nixfmt-classic ];
checkPhase = ''
set -e
# find all nix files, and verify that they're formatted correctly
fd \.nix\$ --hidden --type f | xargs nixfmt -c
'';
installPhase = ''
mkdir "$out"
'';
};
} // buffrs.checks);
formatter = with pkgs;
writeShellApplication {
name = "nixfmt-nix-files";
runtimeInputs = [ fd nixfmt-classic ];
text = "fd \\.nix\\$ --hidden --type f | xargs nixfmt";
};

checks = ({
nix-files-are-formatted = pkgs.stdenvNoCC.mkDerivation {
name = "fmt-check";
dontBuild = true;
src = ./.;
doCheck = true;
nativeBuildInputs = with pkgs; [ fd nixfmt-classic ];
checkPhase = ''
set -e
# find all nix files, and verify that they're formatted correctly
fd \.nix\$ --hidden --type f | xargs nixfmt -c
'';
installPhase = ''
mkdir "$out"
'';
};
} // buffrs.checks);

overlays.default = (_final: _prev: { buffrs = app; });
});
in perSystemOutputs // {
overlays.default = (final: _prev: {
buffrs = perSystemOutputs.packages.${final.stdenv.system}.default;
});
};
}

0 comments on commit 739d002

Please sign in to comment.