From 60dab671e3e93f1e21f06231761d4be276228ad6 Mon Sep 17 00:00:00 2001 From: plan9better Date: Mon, 27 Jan 2025 10:51:04 +0100 Subject: [PATCH] Reproducible build environment with nix --- .envrc | 1 + .github/workflows/build_nix.yml | 13 +++++++++++++ .gitignore | 3 +++ README.md | 3 +++ default.nix | 10 ++++++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 19 +++++++++++++++++++ shell.nix | 9 +++++++++ 8 files changed, 85 insertions(+) create mode 100644 .envrc create mode 100644 .github/workflows/build_nix.yml create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml new file mode 100644 index 0000000..87d2eba --- /dev/null +++ b/.github/workflows/build_nix.yml @@ -0,0 +1,13 @@ +name: "Build legacy Nix package on Ubuntu" + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v26 + - name: Building package + run: nix build diff --git a/.gitignore b/.gitignore index d686362..c2350f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ /target **/*.rs.bk +# Nix build output +/result + # File used as the piped output of Sapling (I use it for debugging) log diff --git a/README.md b/README.md index 1f3d603..84fbcc4 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,9 @@ git clone https://github.com/kneasle/sapling.git cargo run 2> log ``` +If you have Nix you can also run `nix build` and `./result/bin/sapling 2> log`, or if you don't mind +seeing stderr output even quicker with `nix run`. + ### Demo ![Demo GIF](https://user-images.githubusercontent.com/60934058/112751246-d8e23f00-8fc4-11eb-9a15-8a3ef32d54a4.gif) diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..fb1afae --- /dev/null +++ b/default.nix @@ -0,0 +1,10 @@ +{ pkgs ? import { } }: +let + manifest = (pkgs.lib.importTOML ./Cargo.toml).package; +in +pkgs.rustPlatform.buildRustPackage rec { + pname = manifest.name; + version = manifest.version; + cargoLock.lockFile = ./Cargo.lock; + src = pkgs.lib.cleanSource ./.; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3bc2a40 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1737885589, + "narHash": "sha256-Zf0hSrtzaM1DEz8//+Xs51k/wdSajticVrATqDrfQjg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "852ff1d9e153d8875a83602e03fdef8a63f0ecf8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5d17af6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "Sapling text editor"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgsFor = nixpkgs.legacyPackages; + in { + packages = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./default.nix { }; + }); + devShells = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./shell.nix { }; + }); + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..55f195b --- /dev/null +++ b/shell.nix @@ -0,0 +1,9 @@ +{ pkgs ? import { } }: +pkgs.mkShell { + inputsFrom = [ (pkgs.callPackage ./default.nix { }) ]; + buildInputs = with pkgs; [ + rust-analyzer # LSP Server + rustfmt # Formatter + clippy # Linter + ]; +}