diff --git a/.github/workflows/test-update-nix-direnv.yaml b/.github/workflows/test-update-nix-direnv.yaml deleted file mode 100644 index 1465960..0000000 --- a/.github/workflows/test-update-nix-direnv.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: Test update-nix-direnv.nu -"on": - pull_request: - branches: ["main"] - paths: - - .github/workflows/test-update-nix-direnv.yaml - - flake.lock - - update-nix-direnv.nu - - update-nix-direnv-tests.nu - push: - branches: ["main"] - paths: - - .github/workflows/test-update-nix-direnv.yaml - - flake.lock - - update-nix-direnv.nu - - update-nix-direnv-tests.nu - workflow_dispatch: - -jobs: - test-update-nix-direnv: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: DeterminateSystems/nix-installer-action@v14 - - uses: DeterminateSystems/magic-nix-cache-action@v8 - - name: Run the Nushell tests - run: nix develop --command nu update-nix-direnv-tests.nu diff --git a/.justfile b/.justfile index c318299..ae056f0 100644 --- a/.justfile +++ b/.justfile @@ -69,11 +69,6 @@ alias pack := package package board="attiny85": ^nix build ".#pwm-fan-controller-{{ board }}" -alias t := test - -test: - nu update-nix-direnv-tests.nu - alias u := update alias up := update @@ -85,4 +80,3 @@ update: ^cargo update cd "{{ justfile_directory() }}/boards/qt-py-ch32v203" ^cargo update - nu update-nix-direnv.nu diff --git a/flake.lock b/flake.lock index cecef70..96ce305 100644 --- a/flake.lock +++ b/flake.lock @@ -47,6 +47,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -65,9 +81,28 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ + "nix-update-scripts", "pre-commit-hooks", "nixpkgs" ] @@ -86,13 +121,55 @@ "type": "github" } }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nix-update-scripts": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1729186314, + "narHash": "sha256-aPbE+mfN7xPcl5yLKSCy26tmJcid8Zmf3M+jD0t1HX8=", + "owner": "jwillikers", + "repo": "nix-update-scripts", + "rev": "c2738c18eb9bcaeca7a5f341ce1da243dd2c15b4", + "type": "github" + }, + "original": { + "owner": "jwillikers", + "repo": "nix-update-scripts", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1728241625, - "narHash": "sha256-yumd4fBc/hi8a9QgA9IT8vlQuLZ2oqhkJXHPKxH/tRw=", + "lastModified": 1728888510, + "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c31898adf5a8ed202ce5bea9f347b1c6871f32d1", + "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c", "type": "github" }, "original": { @@ -118,6 +195,22 @@ "type": "github" } }, + "nixpkgs-stable_2": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1726871744, @@ -134,15 +227,71 @@ "type": "github" } }, + "nixpkgs_3": { + "locked": { + "lastModified": 1728241625, + "narHash": "sha256-yumd4fBc/hi8a9QgA9IT8vlQuLZ2oqhkJXHPKxH/tRw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c31898adf5a8ed202ce5bea9f347b1c6871f32d1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1726871744, + "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat", "gitignore": "gitignore", "nixpkgs": [ + "nix-update-scripts", "nixpkgs" ], "nixpkgs-stable": "nixpkgs-stable" }, + "locked": { + "lastModified": 1729087992, + "narHash": "sha256-u9bQsT6G/yzDVQ7xCcudnKXkS4ZR240Y4Cd9BmrKejc=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "43983c5976fef25e774e3f1c9bd04f658e9481c3", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "pre-commit-hooks_2": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore_2", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable_2" + }, "locked": { "lastModified": 1728092656, "narHash": "sha256-eMeCTJZ5xBeQ0f9Os7K8DThNVSo9gy4umZLDfF5q6OM=", @@ -162,10 +311,11 @@ "advisory-db": "advisory-db", "crane": "crane", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks", + "nix-update-scripts": "nix-update-scripts", + "nixpkgs": "nixpkgs_3", + "pre-commit-hooks": "pre-commit-hooks_2", "rust-overlay": "rust-overlay", - "treefmt-nix": "treefmt-nix" + "treefmt-nix": "treefmt-nix_2" } }, "rust-overlay": { @@ -203,10 +353,43 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { "nixpkgs": "nixpkgs_2" }, + "locked": { + "lastModified": 1729077719, + "narHash": "sha256-zayHqZO9gA1U85c4CPvVSnLV8/cBgc2yVrSKWaKeBUs=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "5307ba60125bb024d7e52d71d582eafd511f3fee", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "treefmt-nix_2": { + "inputs": { + "nixpkgs": "nixpkgs_4" + }, "locked": { "lastModified": 1727984844, "narHash": "sha256-xpRqITAoD8rHlXQafYZOLvUXCF6cnZkPfoq67ThN0Hc=", diff --git a/flake.nix b/flake.nix index 3c0faeb..e107745 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,7 @@ }; crane.url = "github:ipetkov/crane"; flake-utils.url = "github:numtide/flake-utils"; + nix-update-scripts.url = "github:jwillikers/nix-update-scripts"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; pre-commit-hooks = { url = "github:cachix/pre-commit-hooks.nix"; @@ -28,6 +29,7 @@ advisory-db, crane, flake-utils, + nix-update-scripts, nixpkgs, pre-commit-hooks, rust-overlay, @@ -433,6 +435,7 @@ in { apps = { + inherit (nix-update-scripts.apps.${system}) update-nix-direnv; attiny85.flash.avrdude = boards.attiny85.apps.flash.avrdude; default = self.apps.${system}.attiny85.flash.avrdude; pico.flash.elf2uf2-rs = boards.pico.apps.flash.elf2uf2-rs; diff --git a/update-nix-direnv-tests.nu b/update-nix-direnv-tests.nu deleted file mode 100755 index 66e83f4..0000000 --- a/update-nix-direnv-tests.nu +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env nu -use update-nix-direnv.nu update_nix_direnv_in_envrc - -use std assert -use std log - -def test_update_nix_direnv_in_envrc [] { - for t in [ - [text version hash expected]; - [ -'if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" -fi - -use flake' "3.0.7" "TEsTJaRMf8oF5LznDrlCXbkOQrywm0IHv1VjYGaTesT=" -'if ! has nix_direnv_version || ! nix_direnv_version 3.0.7; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.7/direnvrc" "sha256-TEsTJaRMf8oF5LznDrlCXbkOQrywm0IHv1VjYGaTesT=" -fi - -use flake'] - ] { - assert equal ($t.text | update_nix_direnv_in_envrc $t.version $t.hash) $t.expected - } -} - -def main [] [] { - test_update_nix_direnv_in_envrc - echo "All tests passed!" -} diff --git a/update-nix-direnv.nu b/update-nix-direnv.nu deleted file mode 100755 index f85b7b7..0000000 --- a/update-nix-direnv.nu +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env nu - -# https://github.com/nix-community/nix-direnv - -# Get the newest version of nix-direnv. -def get_latest_nix_direnv_version [] [ nothing -> string ] { - http get https://api.github.com/repos/nix-community/nix-direnv/releases/latest | get name -} - -# Get the SHA-256 hash of the direnvrc file for a particular version of nix-direnv. -def get_direnvrc_hash [ - version: string # The version of nix-direnv, i.e. 3.0.6 -] [ nothing -> string ] { - http get $"https://raw.githubusercontent.com/nix-community/nix-direnv/($version)/direnvrc" | hash sha256 --binary | encode new-base64 -} - -# Replace the current version of nix-direnv with the given version and update the SHA-256 checksum of the direnvrc file. -# -# This function takes as input the content of a .envrc file, like the following. -# -# if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then -# source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" -# fi -# -# use flake -# -export def update_nix_direnv_in_envrc [ - version: string # nix-direnv version, i.e. 3.0.6 - hash: string # The sha256 checksum of the release -] [ string -> string ] { - ( - $in - | str replace --regex "nix_direnv_version [0-9]+\\.[0-9]+\\.[0-9]+" - $"nix_direnv_version ($version)" - | str replace --regex "source_url \"https://raw.githubusercontent.com/nix-community/nix-direnv/[0-9]+\\.[0-9]+\\.[0-9]+/direnvrc\" \"sha256-[[:alnum:]]+=\"" - $'source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/($version)/direnvrc" "sha256-($hash)"' - ) -} - -def main [ - files: list = [] # A list of `.envrc` files to operate on. -] { - let files = ( - if ($files | is-empty) { - glob **/.envrc - } else { - $files - } - ) - - let version = get_latest_nix_direnv_version - let hash = get_direnvrc_hash $version - - for file in $files { - $file | open | update_nix_direnv_in_envrc $version $hash | save --force $file - } - - exit 0 -}