diff --git a/.github/workflows/binary-cache.yaml b/.github/workflows/binary-cache.yaml new file mode 100644 index 0000000..e089b42 --- /dev/null +++ b/.github/workflows/binary-cache.yaml @@ -0,0 +1,39 @@ +name: "Deploy binary cache" + +on: + push: + branches: + - "main" + paths: + - "src/**" + - "patches/**" + - "queries/**" + - "Cargo.*" + - "flake.*" + +env: + CACHE_NAME: "YOUR_CACHE_NAME" + +jobs: + build: + if: "startsWith(github.event.head_commit.message, 'bump:')" + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + steps: + - uses: actions/checkout@v6 + - name: Install nix + uses: DeterminateSystems/nix-installer-action@main + - name: Cache build artifacts + uses: DeterminateSystems/flakehub-cache-action@main + - uses: cachix/cachix-action@v16 + with: + name: ${{ env.CACHE_NAME }} + # If you chose API tokens for write access OR if you have a private cache + authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" + - name: Build default package + run: | + nix build --no-link --print-out-paths | cachix push ${{ env.CACHE_NAME }} diff --git a/.gitignore b/.gitignore index b09fe79..3083ca2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ target target/ .repomap* public/ +result diff --git a/docs/content/getting-started.md b/docs/content/getting-started.md index 3376339..98b7742 100644 --- a/docs/content/getting-started.md +++ b/docs/content/getting-started.md @@ -18,9 +18,16 @@ cargo install --path . ### With Nix +Run directly: + +```bash +nix run github:nrdxp/sukr -- --help +``` + +Or install with Nix: + ```bash -nix build github:nrdxp/sukr -./result/bin/sukr --help +nix profile install github:nrdxp/sukr ``` ## Create Your First Site diff --git a/flake.lock b/flake.lock index 1e2be3c..c1f1c36 100644 --- a/flake.lock +++ b/flake.lock @@ -21,6 +21,23 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1772408722, + "narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, "nixpkgs": { "locked": { "lastModified": 1769268028, @@ -37,9 +54,25 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1772328832, + "narHash": "sha256-e+/T/pmEkLP6BHhYjx6GmwP5ivonQQn0bJdH9YrRB+Q=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "c185c7a5e5dd8f9add5b2f8ebeff00888b070742", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "root": { "inputs": { "fenix": "fenix", + "flake-parts": "flake-parts", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index 719cff7..38d88ea 100644 --- a/flake.nix +++ b/flake.nix @@ -10,51 +10,84 @@ }; outputs = - { - self, - nixpkgs, - fenix, + inputs@{ + flake-parts, + ... }: - let + flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn system); - in - { - devShells = forAllSystems ( - system: + perSystem = + { + self', + pkgs, + inputs', + ... + }: let - pkgs = nixpkgs.legacyPackages.${system}; - fenixPkgs = fenix.packages.${system}; - toolchain = fenixPkgs.fromToolchainFile { + fenix = inputs'.fenix.packages; + # rustChannel = "stable"; + toolchain = fenix.fromToolchainFile { file = ./rust-toolchain.toml; - sha256 = "sha256-vra6TkHITpwRyA5oBKAHSX0Mi6CBDNQD+ryPSpxFsfg="; + sha256 = "sha256-qqF33vNuAdU5vua96VKVIwuc43j4EFeEXbjQ6+l4mO4="; + }; + rustplatform = pkgs.makeRustPlatform { + cargo = toolchain; + rustc = toolchain; }; in { - default = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } { - RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; - packages = [ - toolchain - pkgs.treefmt - pkgs.shfmt - pkgs.rust-analyzer - pkgs.taplo - pkgs.pkg-config - pkgs.nixfmt - pkgs.nodePackages.prettier - pkgs.miniserve # Dev server for testing - ] - ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ - pkgs.apple-sdk - pkgs.libiconv - ]; + packages.sukr = rustplatform.buildRustPackage { + pname = "sukr"; + version = "0.1.0"; + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; + # Programs and libraries used at build-time + nativeBuildInputs = + with pkgs; + # Left empty on purpose to easily add if needed + [ ] + ++ lib.optionals stdenv.isDarwin [ + apple-sdk + libiconv + ]; + }; + packages.default = self'.packages.sukr; + + # Default shell opened with `nix develop` + devShells.default = pkgs.mkShell { + name = "dev"; + + # Available packages on https://search.nixos.org/packages + buildInputs = + with pkgs; + [ + toolchain + treefmt + shfmt + rust-analyzer + taplo + pkg-config + nixfmt + nodePackages.prettier + miniserve # Dev server for testing + ] + ++ lib.optionals stdenv.isDarwin [ + apple-sdk + libiconv + ]; + + shellHook = '' + echo "Welcome to the rust devshell!" + ''; }; - } - ); + }; }; }