Skip to content

Instantly share code, notes, and snippets.

@joshbode
Last active October 27, 2024 04:11
Show Gist options
  • Save joshbode/e0407642c2c5c92f35326ae654dbede8 to your computer and use it in GitHub Desktop.
Save joshbode/e0407642c2c5c92f35326ae654dbede8 to your computer and use it in GitHub Desktop.
Build Nix Package from Flake

Testing Nix Packages

To test a nix package derivation, drop the flake.nix into the directory of the default.nix and temporarily add it to the local clone of the nixpkgs git repository.

$ git add --intent-to-add flake.nix

Then, to build the package and use the output in a dev shell:

$ nix develop
...
(nix:nix-shell-env) $
{
description = "build target package";
inputs = {
target = {
url = "path:default.nix";
flake = false;
};
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};
outputs =
{
systems,
nixpkgs,
...
}@inputs:
let
inherit (nixpkgs) lib;
overlays = [
(
final: prev:
let
pkgs = nixpkgs.legacyPackages.${prev.system};
in
{
target = pkgs.callPackage inputs.target { };
}
)
];
eachSystem =
f:
lib.genAttrs (import systems) (
system:
f (
import nixpkgs {
inherit system overlays;
}
)
);
in
{
devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
target
];
};
});
packages = eachSystem (pkgs: {
default = pkgs.target;
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment