From 062832fc8ae75b79bef497c606f890d4d0a86321 Mon Sep 17 00:00:00 2001 From: olafklingt Date: Sat, 18 Nov 2023 19:53:34 +0100 Subject: [PATCH 1/2] add flake --- flake.lock | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 45 ++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2f63984 --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1688534083, + "narHash": "sha256-/bI5vsioXscQTsx+Hk9X5HfweeNZz/6kVKsbdqfwW7g=", + "owner": "nix-community", + "repo": "naersk", + "rev": "abca1fb7a6cfdd355231fc220c3d0302dbb4369a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700108881, + "narHash": "sha256-+Lqybl8kj0+nD/IlAWPPG/RDTa47gff9nbei0u7BntE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7414e9ee0b3e9903c24d3379f577a417f0aae5f1", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1699963925, + "narHash": "sha256-LE7OV/SwkIBsCpAlIPiFhch/J+jBDGEZjNfdnzCnCrY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bf744fe90419885eefced41b3e5ae442d732712d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1f09cc3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # because we need rustc 1.70 + utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk/master"; + }; + outputs = { self, nixpkgs, utils, naersk }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + naerskLib = pkgs.callPackage naersk { }; + name = "smrec"; + nativeBuildInputs = with pkgs; [ + cargo + rustc + pkg-config + ]; + buildInputs = with pkgs; [ + alsa-lib + jack2 + ]; + in + { + devShells.default = pkgs.mkShell + { + inherit buildInputs nativeBuildInputs; + }; + packages.default = pkgs.rustPlatform.buildRustPackage { + pname = name; + version = "0.2.0"; + inherit buildInputs nativeBuildInputs; + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + outputHashes = { + "asio-sys-0.2.1" = "sha256-MPknKFVyxTDI7r4xC860RSOa9zmB/iQsCZeAlvE8cdk="; + }; + }; + }; + apps.default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/${name}"; + }; + }); +} From 515d9b04b57c41a4e61cebb0ec02c85ed6c15d74 Mon Sep 17 00:00:00 2001 From: olafklingt Date: Mon, 20 Nov 2023 22:06:30 +0100 Subject: [PATCH 2/2] add comments to flake --- flake.nix | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index 1f09cc3..82d1887 100644 --- a/flake.nix +++ b/flake.nix @@ -1,44 +1,70 @@ { + # Define the inputs required for this flake. inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # because we need rustc 1.70 + # The version of nixpkgs we're using. We need a newer rustc that is available on the unstable banch. + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + # The flake-utils provide helpful utilities for managing flakes. utils.url = "github:numtide/flake-utils"; + + # naersk is used for building Rust projects with Nix. naersk.url = "github:nix-community/naersk/master"; }; + + # Define the outputs of the flake, which depend on the inputs and the current flake. outputs = { self, nixpkgs, utils, naersk }: + # Use flake-utils to generate outputs for each system supported by default. utils.lib.eachDefaultSystem (system: let + # Import the nixpkgs for the given system. pkgs = import nixpkgs { inherit system; }; + + # Instantiate naersk with the current package set. naerskLib = pkgs.callPackage naersk { }; + + # Name of the Rust project. name = "smrec"; + + # Build-time dependencies. nativeBuildInputs = with pkgs; [ - cargo - rustc - pkg-config + cargo # Cargo, the Rust package manager. + rustc # The Rust compiler. + pkg-config # Helper tool used when compiling applications and libraries. ]; + + # Runtime dependencies. buildInputs = with pkgs; [ - alsa-lib - jack2 + alsa-lib # ALSA library for audio. + jack2 # JACK Audio Connection Kit. ]; in { + # Define a development shell for this project. devShells.default = pkgs.mkShell { + # Pass both build-time and runtime dependencies to the shell environment. inherit buildInputs nativeBuildInputs; }; + + # Define the Rust package. packages.default = pkgs.rustPlatform.buildRustPackage { - pname = name; - version = "0.2.0"; + pname = name; # Package name. + version = "0.2.1"; # Version of the package. inherit buildInputs nativeBuildInputs; - src = ./.; + src = ./.; # Source directory for the Rust project. cargoLock = { - lockFile = ./Cargo.lock; + lockFile = ./Cargo.lock; # Path to the Cargo.lock file. + # Specific output hashes for dependencies, required for reproducibility. outputHashes = { "asio-sys-0.2.1" = "sha256-MPknKFVyxTDI7r4xC860RSOa9zmB/iQsCZeAlvE8cdk="; }; }; }; + + # Define the application produced by this project. apps.default = { - type = "app"; + type = "app"; # Type is an application. + # The path to the executable that will run the app. program = "${self.packages.${system}.default}/bin/${name}"; }; });