From d2996ba52120267a09fe6f44b1fab30d81992d45 Mon Sep 17 00:00:00 2001 From: Rexiel Scarlet <37258415+Rexcrazy804@users.noreply.github.com> Date: Thu, 14 Aug 2025 01:05:58 +0400 Subject: [PATCH 1/2] nix: incremental builds with crane --- flake.lock | 16 +++++++++++++ flake.nix | 6 ++++- nix/package.nix | 61 +++++++++++++++++++++++++++++++++++-------------- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index 7469d87..02d5006 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "crane": { + "locked": { + "lastModified": 1754269165, + "narHash": "sha256-0tcS8FHd4QjbCVoxN9jI+PjHgA4vc/IjkUSp+N3zy0U=", + "owner": "ipetkov", + "repo": "crane", + "rev": "444e81206df3f7d92780680e45858e31d2f07a08", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1754725699, @@ -18,6 +33,7 @@ }, "root": { "inputs": { + "crane": "crane", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 3648b82..9be3b14 100644 --- a/flake.nix +++ b/flake.nix @@ -1,16 +1,20 @@ { inputs.nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; + inputs.crane.url = "github:ipetkov/crane"; outputs = { self, nixpkgs, + crane, }: let systems = ["x86_64-linux" "aarch64-linux"]; forEachSystem = nixpkgs.lib.genAttrs systems; pkgsForEach = nixpkgs.legacyPackages; in { packages = forEachSystem (system: { - default = pkgsForEach.${system}.callPackage ./nix/package.nix {}; + default = pkgsForEach.${system}.callPackage ./nix/package.nix { + craneLib = crane.mkLib pkgsForEach.${system}; + }; }); devShells = forEachSystem (system: { diff --git a/nix/package.nix b/nix/package.nix index 5eff278..a4340f9 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,11 +1,12 @@ { lib, - rustPlatform, -}: -rustPlatform.buildRustPackage (finalAttrs: { + craneLib, + runCommandNoCCLocal, +}: let + inherit (craneLib) buildDepsOnly buildPackage mkDummySrc; + pname = "stash"; version = (builtins.fromTOML (builtins.readFile ../Cargo.toml)).package.version; - src = let fs = lib.fileset; s = ../.; @@ -19,18 +20,44 @@ rustPlatform.buildRustPackage (finalAttrs: { ]; }; - cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock"; - enableParallelBuilding = true; + # basically avoid crane rebuilding everything + # when the package version changes + replacedSrc = let + rgxIn = '' + name = "${pname}" + version = "${version}" + ''; + rgxOut = '' + name = "${pname}" + version = "0.9.6" + ''; + in + runCommandNoCCLocal "bakaSrc" {} '' + cp -r ${src} $out + substituteInPlace $out/Cargo.toml \ + --replace-fail '${rgxIn}' '${rgxOut}' + substituteInPlace $out/Cargo.lock \ + --replace-fail '${rgxIn}' '${rgxOut}' + ''; - postInstall = '' - mkdir -p $out - install -Dm755 ${../vendor/stash.service} $out/share/stash.service - ''; - - meta = { - description = "Wayland clipboard manager with fast persistent history and multi-media support"; - maintainers = [lib.maintainers.NotAShelf]; - license = lib.licenses.mpl20; - mainProgram = "stash"; + cargoArtifacts = buildDepsOnly { + name = "${pname}-deps"; + strictDeps = true; + dummySrc = mkDummySrc {src = replacedSrc;}; }; -}) +in + buildPackage { + inherit cargoArtifacts pname src version; + strictDeps = true; + postInstall = '' + mkdir -p $out + install -Dm755 ${../vendor/stash.service} $out/share/stash.service + ''; + + meta = { + description = "Wayland clipboard manager with fast persistent history and multi-media support"; + maintainers = [lib.maintainers.NotAShelf]; + license = lib.licenses.mpl20; + mainProgram = "stash"; + }; + } From 464daf3d71b16fd135f89727defa581be87f104d Mon Sep 17 00:00:00 2001 From: Rexiel Scarlet <37258415+Rexcrazy804@users.noreply.github.com> Date: Thu, 14 Aug 2025 18:25:32 +0400 Subject: [PATCH 2/2] workflows: addition of nix cache workflow --- .github/workflows/nix-cache.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/nix-cache.yaml diff --git a/.github/workflows/nix-cache.yaml b/.github/workflows/nix-cache.yaml new file mode 100644 index 0000000..472768f --- /dev/null +++ b/.github/workflows/nix-cache.yaml @@ -0,0 +1,19 @@ +name: "Populate cachix cache" +on: + workflow_dispatch: + push: + branches: [ master ] + paths: [ 'src/**.rs', 'Cargo.toml', 'Cargo.lock', 'nix/package.nix' ] +jobs: + populate-cache: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v25 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: cachix/cachix-action@v14 + with: + name: nyx + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix build