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..df9d767 --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + 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 + rustfmt + makeWrapper + ]; + in { + devShells.default = pkgs.mkShell { + buildInputs = nativeBuildInputs; + }; + + packages.default = pkgs.rustPlatform.buildRustPackage { + pname = "cddl-codegen"; + version = "0.1.0"; + src = ./.; + + inherit nativeBuildInputs; + + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; + + # the regular tests don't run yet + checkPhase = '' + cargo test comment_ast + ''; + + postInstall = '' + wrapProgram $out/bin/cddl-codegen \ + --set PATH ${pkgs.lib.makeBinPath [pkgs.rustfmt pkgs.which]} \ + --add-flags "--static-dir ${./static}" + ''; + + 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 = []; + }; + }; + } + ); +}