Skip to content

Instantly share code, notes, and snippets.

@izelnakri
Last active March 10, 2025 09:32
Show Gist options
  • Save izelnakri/de8e2f48f3f6b00809a7977bba20e2cd to your computer and use it in GitHub Desktop.
Save izelnakri/de8e2f48f3f6b00809a7977bba20e2cd to your computer and use it in GitHub Desktop.
flake.nix - Most universal template for any software project
# Example of a binary packaging(storing a frozen binary with deps WITH compiler build) in nix:
# $ nix run --impure --expr 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./bitbox-bridge.nix {}'
{
lib,
stdenv,
fetchFromGitHub,
rustPlatform,
pkg-config,
libudev-zero,
}:
rustPlatform.buildRustPackage rec {
pname = "bitbox-bridge";
version = "1.6.1";
src = fetchFromGitHub {
owner = "BitBoxSwiss";
repo = "bitbox-bridge";
tag = "v${version}";
fetchSubmodules = true;
hash = "sha256-+pMXWXGHyyBx3N0kiro9NS0mPmSQzzBmp+pkoBLH7z0=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-6vD0XjGH1PXjiRjgnHWSZSixXOc2Yecui8U5FAGefBU=";
nativeBuildInputs = [
pkg-config
];
buildInputs = [
libudev-zero
];
meta = {
description = "A bridge service that connects web wallets like Rabbit to BitBox02";
homepage = "https://github.com/BitBoxSwiss/bitbox-bridge";
downloadPage = "https://bitbox.swiss/download/";
changelog = "https://github.com/BitBoxSwiss/bitbox-bridge/blob/v${version}/CHANGELOG.md";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [
izelnakri
tensor5
];
mainProgram = "bitbox-bridge";
platforms = with lib.platforms; darwin ++ linux;
};
}
# Optional if you want to run $ nix build -f ./default.nix | index.js for nix
# $ nix build -f ./default.nix # nix-build -A foo => would target the key "foo" inside an attribute set(object in nix)
let
pkgs = import <nixpkgs> { system = builtins.currentSystem; };
in
pkgs.callPackage ./studio-link.nix {}
# This showcases the most important nix workflow: how to package and run a binary in the most standard way in nix:
# Commands:
# $ nix run . => (.) is optional
# $ nix build . => (.) is optional
# Target a single file instead:
# $ nix build --impure --expr 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./studio-link.nix {}'
# $ nix run --impure --expr 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./studio-link.nix {}'
# Target a ./default.nix file
# $ nix build -f ./default.nix # nix-build -A foo => would target the key "foo" inside an attribute set(object in nix)
# $ nix run -f ./default.nix # nix run un -A foo => would target the key "foo" inside an attribute set(object in nix)
{
description = "Studio Link standalone package or more";
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
outputs = { self, nixpkgs }:
let
forAllSystems = f: nixpkgs.lib.genAttrs [ "x86_64-linux" ] (system:
f (import nixpkgs { inherit system; })
);
in {
packages = forAllSystems (pkgs: {
default = pkgs.callPackage ./studio-link.nix {};
});
apps = forAllSystems (pkgs: {
default = {
type = "app";
program = "${self.packages.${pkgs.system}.default}/bin/studio-link";
};
});
# Allow `nix develop` to create a shell with dependencies
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
buildInputs = with pkgs; [ alsaLib openssl zlib pulseaudio ];
};
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment