From 97505c9ad45b81b4a2965ace14afaf445a9e6a21 Mon Sep 17 00:00:00 2001 From: Reed Krantz Date: Sun, 26 Apr 2026 01:18:14 -0500 Subject: [PATCH] chore: instead of using crane directly use the reed/project-templates rust module --- flake.lock | 35 ++++++++++++-- flake.nix | 133 +++++++++++++++++++---------------------------------- 2 files changed, 78 insertions(+), 90 deletions(-) diff --git a/flake.lock b/flake.lock index d517646..22c33d2 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "crane": { "locked": { - "lastModified": 1775839657, - "narHash": "sha256-SPm9ck7jh3Un9nwPuMGbRU04UroFmOHjLP56T10MOeM=", + "lastModified": 1777149905, + "narHash": "sha256-WMC5ktOHtCyJL/jtlf46P+I4Vhw938+oLlSpM8gwQwU=", "owner": "ipetkov", "repo": "crane", - "rev": "7cf72d978629469c4bd4206b95c402514c1f6000", + "rev": "60c829383710f7e26454e6677c4d3adbc56dd3b8", "type": "github" }, "original": { @@ -64,17 +64,42 @@ "type": "github" } }, - "root": { + "project-templates": { "inputs": { "crane": "crane", + "flake-parts": [ + "flake-parts" + ], + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1777183464, + "narHash": "sha256-aKh428176wYLo4KBAcadw5sqseSPAQ64pN0Qi8f2tXs=", + "ref": "refs/heads/master", + "rev": "b1a2a8d97b6beae0cbea89908306a496425c610c", + "revCount": 14, + "type": "git", + "url": "ssh://gitea@git.krantz.one/reed/project-templates" + }, + "original": { + "type": "git", + "url": "ssh://gitea@git.krantz.one/reed/project-templates" + } + }, + "root": { + "inputs": { "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", - "treefmt-nix": "treefmt-nix" + "project-templates": "project-templates" } }, "treefmt-nix": { "inputs": { "nixpkgs": [ + "project-templates", "nixpkgs" ] }, diff --git a/flake.nix b/flake.nix index 4cfaf47..f346cd5 100644 --- a/flake.nix +++ b/flake.nix @@ -6,130 +6,93 @@ flake-parts.url = "github:hercules-ci/flake-parts"; - treefmt-nix = { - url = "github:numtide/treefmt-nix"; + project-templates = { + url = "git+ssh://gitea@git.krantz.one/reed/project-templates"; inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-parts.follows = "flake-parts"; }; - - crane.url = "github:ipetkov/crane"; }; outputs = { self, flake-parts, - treefmt-nix, - crane, + project-templates, ... } @ inputs: flake-parts.lib.mkFlake {inherit inputs;} { imports = [ - treefmt-nix.flakeModule + project-templates.flakeModules.rust ]; - systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin"]; + systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"]; perSystem = { - pkgs, lib, + config, + pkgs, + self', ... - }: let - craneLib = crane.mkLib pkgs; - src = let - unfilteredRoot = ./.; - in - lib.fileset.toSource { - root = unfilteredRoot; - fileset = lib.fileset.unions [ - # Default files from crane (Rust and cargo files) - (craneLib.fileset.commonCargoSources unfilteredRoot) - (lib.fileset.maybeMissing ./qt-plugin.version) + }: { + krantz.rust = let + craneLib = config.krantz.rust.craneLib; + + # pkgs.qt6.env already includes pkgs.qt6.qtbase + # And using `with` to prevent a lot of typing. + qtEnv = with pkgs.qt6; + env "qt-rshell-${qtbase.version}" [ + qtdeclarative + qttools ]; - }; - manifest = (lib.importTOML "${src}/Cargo.toml").package; + in { + enable = true; + srcFiltered = let + unfilteredRoot = ./.; + in + lib.fileset.toSource { + root = unfilteredRoot; + fileset = lib.fileset.unions [ + # Default files from crane (Rust and cargo files) + (craneLib.fileset.commonCargoSources unfilteredRoot) + (lib.fileset.maybeMissing ./qt-plugin.version) + ]; + }; - # pkgs.qt6.env already includes pkgs.qt6.qtbase - # And using `with` to prevent a lot of typing. - qtEnv = with pkgs.qt6; - env "qt-rshell-${qtbase.version}" [ - qtdeclarative - qttools + runtimeDeps = [ + qtEnv ]; - - # runtime dependencies - buildInputs = with pkgs; [ - qtEnv - ]; - - # build dependencies - nativeBuildInputs = with pkgs; [ - # pkg-config - # rustPlatform.bindgenHook - ]; - - # Build *just* the cargo dependencies, so we can reuse - # all of that work (e.g. via cachix) when running in CI - cargoArtifacts = craneLib.buildDepsOnly { - inherit src buildInputs nativeBuildInputs; - }; - in rec { - # Dev Shell that lets you enter an environment with all the necessary utilites - # Available through 'nix develop' - # Also can be activated automatically if direnv is installed on the system with 'direnv allow' - devShells.default = craneLib.devShell { - inherit checks; - - # extra tooling dependencies - packages = with pkgs; [ + devDeps = with pkgs; [ rust-analyzer quickshell ]; - shellHook = - /* - bash - */ - '' - export QML2_IMPORT_PATH=$(git rev-parse --show-toplevel)/result/:$QML2_IMPORT_PATH - ''; - - inputsFrom = [packages.default]; - }; - - # Formatter for nix files, available through 'nix fmt' - treefmt = { - programs.alejandra.enable = true; - programs.rustfmt = { - enable = true; - edition = manifest.edition; + devShell.extraAttrs = { + shellHook = + /* + bash + */ + '' + export QML2_IMPORT_PATH=$(git rev-parse --show-toplevel)/result/:$QML2_IMPORT_PATH + ''; }; + + package.name = "lib"; }; # Your custom packages # Accessible through 'nix build', 'nix shell', 'nix run', etc - packages = rec { - lib = craneLib.buildPackage { - inherit src buildInputs nativeBuildInputs cargoArtifacts; - }; - + packages = { qmlModule = pkgs.runCommand "rshell-qml-dir" {} '' mkdir -p $out cat << EOF > $out/qmldir ${'' module one.krantz.rshell - plugin rshell ${lib}/lib + plugin rshell ${self'.packages.lib}/lib ''} EOF ''; - default = qmlModule; - }; - - checks = { - clippy = craneLib.cargoClippy { - inherit src buildInputs nativeBuildInputs cargoArtifacts; - cargoClippyExtraArgs = "-- --deny warnings"; - }; + default = self'.packages.qmlModule; }; };