Last active
March 10, 2025 09:32
-
-
Save izelnakri/de8e2f48f3f6b00809a7977bba20e2cd to your computer and use it in GitHub Desktop.
flake.nix - Most universal template for any software project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ]; | |
}; | |
}); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of a binary packaging(storing a frozen binary with deps bypassing compiler build) in nix: | |
# $ nix run --impure --expr 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage ./studio-link.nix {}' | |
{ stdenv, lib | |
, fetchurl | |
, alsa-lib | |
, openssl | |
, zlib | |
, pulseaudio | |
, autoPatchelfHook | |
}: | |
stdenv.mkDerivation rec { | |
pname = "studio-link"; | |
version = "21.07.0"; | |
src = fetchurl { | |
url = "https://download.studio.link/releases/v${version}-stable/linux/studio-link-standalone-v${version}.tar.gz"; | |
hash = "sha256-4CkijAlenhht8tyk3nBULaBPE0GBf6DVII699/RmmWI="; | |
}; | |
nativeBuildInputs = [ | |
autoPatchelfHook | |
]; | |
buildInputs = [ | |
alsa-lib | |
openssl | |
zlib | |
pulseaudio | |
]; | |
sourceRoot = "."; # Necessary | |
installPhase = '' | |
runHook preInstall | |
install -m755 -D studio-link-standalone-v${version} $out/bin/studio-link | |
runHook postInstall | |
''; | |
meta = with lib; { | |
homepage = "https://studio-link.com"; | |
description = "Voip transfer"; | |
platforms = platforms.linux; | |
mainProgram = "studio-link"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment