From 3688d114ce22973de1294ed3ab88821931210b96 Mon Sep 17 00:00:00 2001 From: eveeifyeve <88671402+Eveeifyeve@users.noreply.github.com> Date: Wed, 22 Jan 2025 01:55:04 +1100 Subject: [PATCH 1/2] add nix/nixos development enviroment and automation for easy maintenance make flake check action check all systems added assignment to assign myself to flake update prs. fix actions to use determinsys switch nix formatting check to flake check fix formatting for nix --- .envrc | 1 + .github/workflows/nix-check.yml | 28 ++++++++++ .github/workflows/update-nix.yml | 21 +++++++ .gitignore | 4 ++ flake.lock | 96 ++++++++++++++++++++++++++++++++ flake.nix | 78 ++++++++++++++++++++++++++ shell.nix | 12 ++++ 7 files changed, 240 insertions(+) create mode 100644 .envrc create mode 100644 .github/workflows/nix-check.yml create mode 100644 .github/workflows/update-nix.yml 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 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/nix-check.yml b/.github/workflows/nix-check.yml new file mode 100644 index 00000000..6bb90d9c --- /dev/null +++ b/.github/workflows/nix-check.yml @@ -0,0 +1,28 @@ +name: Run nix checks on prs + +on: + pull_request: + branches: [ "master", "rewrite/v3" ] + +defaults: + run: + shell: bash + +jobs: + check: + name: Check Nix + runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v4 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Check flake.lock + uses: DeterminateSystems/flake-checker-action@main + with: + fail-mode: true + - name: Check Nix formatting + run: nix flake check diff --git a/.github/workflows/update-nix.yml b/.github/workflows/update-nix.yml new file mode 100644 index 00000000..958b29d3 --- /dev/null +++ b/.github/workflows/update-nix.yml @@ -0,0 +1,21 @@ +name: update-flake-lock +on: + workflow_dispatch: # allows manual triggering + schedule: + - cron: '0 0 * * 0' # runs weekly on Sunday at 00:00 + +permissions: + contents: write + pull-requests: write + +jobs: + lockfile: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/update-flake-lock@main + with: + pr-title: "Update flake.lock" + pr-assignees: eveeifyeve diff --git a/.gitignore b/.gitignore index 4bdf603e..aaecbd95 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ config.toml .etc/blocks.json flame.svg + +.direnv +result +result-* diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..846a9435 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1736143030, + "narHash": "sha256-+hu54pAoLDEZT9pjHlqL9DNzWz0NbUn8NEAHP7PQPzU=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "b905f6fc23a9051a6e1b741e1438dbfc0634c6de", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1737062831, + "narHash": "sha256-Tbk1MZbtV2s5aG+iM99U8FqwxU/YNArMcWAv6clcsBc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5df43628fdf08d642be8ba5b3625a6c70731c19c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1735774519, + "narHash": "sha256-CewEm1o2eVAnoqb6Ml+Qi9Gg/EfNAxbRx1lANGVyoLI=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1737426362, + "narHash": "sha256-4SavpRWfRw2pLG1qqErWpk/hI1eCzqjKcE1motxHZgo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "2103fcb16359438d42141bac873ed2367a05cbe7", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..cd51e481 --- /dev/null +++ b/flake.nix @@ -0,0 +1,78 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + inputs@{ + flake-parts, + nixpkgs, + rust-overlay, + ... + }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + + perSystem = + { + pkgs, + system, + ... + }: + { + formatter = nixpkgs.legacyPackages.${system}.nixfmt-rfc-style; + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ + rust-overlay.overlays.default + (self: super: { + rustToolchain = + let + rust = super.rust-bin; + in + if builtins.pathExists ./rust-toolchain.toml then + rust.fromRustupToolchainFile ./rust-toolchain.toml + else if builtins.pathExists ./rust-toolchain then + rust.fromRustupToolchainFile ./rust-toolchain + else + rust.nightly.latest.default; + }) + ]; + config = { }; + }; + + # Used to check formatting for nix specificly + checks.fmt-check = + pkgs.runCommand "format-check" + { + src = ./.; + doCheck = true; + nativeBuildInputs = [ + pkgs.nixfmt-rfc-style + ]; + } + '' + nixfmt --check . + touch $out + ''; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + rustToolchain + pkg-config + openssl + ]; + }; + + }; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..459e1526 --- /dev/null +++ b/shell.nix @@ -0,0 +1,12 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + nodeName = lock.nodes.root.inputs.flake-compat; + in + fetchTarball { + url = + lock.nodes.${nodeName}.locked.url + or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; + sha256 = lock.nodes.${nodeName}.locked.narHash; + } +) { src = ./.; }).shellNix From e3da4bfc37f9ad3f1aaec95f4cb4de3dee8511a8 Mon Sep 17 00:00:00 2001 From: eveeifyeve <88671402+Eveeifyeve@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:30:53 +1100 Subject: [PATCH 2/2] fix: nix caching deprecation --- .github/workflows/nix-check.yml | 2 +- .github/workflows/update-nix.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nix-check.yml b/.github/workflows/nix-check.yml index 6bb90d9c..e8254d77 100644 --- a/.github/workflows/nix-check.yml +++ b/.github/workflows/nix-check.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/flakehub-cache-action@main - name: Check flake.lock uses: DeterminateSystems/flake-checker-action@main with: diff --git a/.github/workflows/update-nix.yml b/.github/workflows/update-nix.yml index 958b29d3..30730570 100644 --- a/.github/workflows/update-nix.yml +++ b/.github/workflows/update-nix.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/flakehub-cache-action@main - uses: DeterminateSystems/update-flake-lock@main with: pr-title: "Update flake.lock"