From 8d73d99cc1342ff17dd0f707ebc7b70854dfffbb Mon Sep 17 00:00:00 2001 From: Martin Becze Date: Wed, 5 Mar 2025 22:54:45 +0000 Subject: [PATCH 1/3] Added a nix flake for cddl-codegen --- flake.lock | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 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..a595a88 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1741010256, + "narHash": "sha256-WZNlK/KX7Sni0RyqLSqLPbK8k08Kq7H7RijPJbq9KHM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ba487dbc9d04e0634c64e3b1f0d25839a0a68246", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1741141853, + "narHash": "sha256-FauVtC+FbOgkKpGVuQTNxSqrvgbmVc7hFkjn/DacwMo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "02edad1f19d6dec824e0812e4cdc0aa7930ff8ae", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0ab1e9f --- /dev/null +++ b/flake.nix @@ -0,0 +1,64 @@ +{ + description = "cddl-codegen: Generate Rust, WASM and JSON code from CDDL specifications"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + nixpkgs, + flake-utils, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs { + overlays = [(import rust-overlay)]; + inherit system; + }; + + rustToolchain = pkgs.rust-bin.nightly.latest.default; + + nativeBuildInputs = with pkgs; [ + rustToolchain + pkg-config + which + ]; + in { + devShells.default = pkgs.mkShell { + buildInputs = nativeBuildInputs; + }; + + packages.default = pkgs.rustPlatform.buildRustPackage { + pname = "cddl-codegen"; + version = "0.1.0"; + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; + + # the regular tests don't run yet + checkPhase = '' + cargo test comment_ast + ''; + + inherit nativeBuildInputs; + + meta = with pkgs.lib; { + description = "Codegen serialization logic for CBOR automatically from a CDDL specification"; + homepage = "https://github.com/dcSpark/cddl-codegen"; + license = licenses.mit; + maintainers = []; + }; + }; + } + ); +} From 6720c7a2ecc4ab92ebf1f0aa7f475d1805d5c7bd Mon Sep 17 00:00:00 2001 From: Martin Becze Date: Tue, 11 Mar 2025 12:35:18 +0000 Subject: [PATCH 2/3] added makeWrapper --- flake.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 0ab1e9f..9c208f0 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,8 @@ rustToolchain pkg-config which + rustfmt + makeWrapper ]; in { devShells.default = pkgs.mkShell { @@ -40,6 +42,8 @@ version = "0.1.0"; src = ./.; + inherit nativeBuildInputs; + cargoLock = { lockFile = ./Cargo.lock; allowBuiltinFetchGit = true; @@ -50,7 +54,10 @@ cargo test comment_ast ''; - inherit nativeBuildInputs; + postInstall = '' + wrapProgram $out/bin/cddl-codegen \ + --set PATH ${pkgs.lib.makeBinPath [pkgs.rustfmt pkgs.which]} + ''; meta = with pkgs.lib; { description = "Codegen serialization logic for CBOR automatically from a CDDL specification"; From 2cf691ca14c1b65ae59d2367ba3d48b524cc2a60 Mon Sep 17 00:00:00 2001 From: Martin Becze Date: Tue, 11 Mar 2025 13:04:01 +0000 Subject: [PATCH 3/3] set --static-dir ${./static} --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9c208f0..df9d767 100644 --- a/flake.nix +++ b/flake.nix @@ -56,7 +56,8 @@ postInstall = '' wrapProgram $out/bin/cddl-codegen \ - --set PATH ${pkgs.lib.makeBinPath [pkgs.rustfmt pkgs.which]} + --set PATH ${pkgs.lib.makeBinPath [pkgs.rustfmt pkgs.which]} \ + --add-flags "--static-dir ${./static}" ''; meta = with pkgs.lib; {