From 2f677ff699432a506de131096d7ae4ab8bdd9b10 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 22 Mar 2024 00:36:44 +0100 Subject: [PATCH 1/2] Define what CI should build in Nix And make it also build the autoPrUpdate derivation --- .github/workflows/main.yml | 2 +- default.nix | 109 +++++++++++++++++++------------------ 2 files changed, 58 insertions(+), 53 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 14962a0..416c246 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,4 +13,4 @@ jobs: - uses: cachix/install-nix-action@v26 - name: build - run: nix-build -A build -A shell -A checks + run: nix-build -A ci diff --git a/default.nix b/default.nix index 5e9bef6..462826e 100644 --- a/default.nix +++ b/default.nix @@ -30,63 +30,68 @@ let nix-store --init ''; - build = pkgs.callPackage ./package.nix { - inherit nixpkgsLibPath initNix runtimeExprPath testNixpkgsPath; - }; -in -build // { + results = { + build = pkgs.callPackage ./package.nix { + inherit nixpkgsLibPath initNix runtimeExprPath testNixpkgsPath; + }; - inherit build; + shell = pkgs.mkShell { + env.NIX_CHECK_BY_NAME_EXPR_PATH = toString runtimeExprPath; + env.NIX_PATH = "test-nixpkgs=${toString testNixpkgsPath}:test-nixpkgs/lib=${toString nixpkgsLibPath}"; + env.RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + inputsFrom = [ results.build ]; + nativeBuildInputs = with pkgs; [ + npins + rust-analyzer + ]; + }; - # Used by CI and good for debugging - inherit pkgs; + # Run regularly by CI and turned into a PR + autoPrUpdate = pkgs.writeShellApplication { + name = "auto-pr-update"; + runtimeInputs = with pkgs; [ + npins + cargo + ]; + text = + let + commands = [ + "npins update" + "cargo update" + ]; + in + '' + echo "Run automated updates" + '' + + pkgs.lib.concatMapStrings (command: '' + echo -e '
${command}\n\n```' + ${command} 2>&1 + echo -e '```\n
' + '') commands; + }; - shell = pkgs.mkShell { - env.NIX_CHECK_BY_NAME_EXPR_PATH = toString runtimeExprPath; - env.NIX_PATH = "test-nixpkgs=${toString testNixpkgsPath}:test-nixpkgs/lib=${toString nixpkgsLibPath}"; - env.RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; - inputsFrom = [ build ]; - nativeBuildInputs = with pkgs; [ - npins - rust-analyzer - ]; + # Tests the tool on the pinned Nixpkgs tree, this is a good sanity check + nixpkgsCheck = pkgs.runCommand "test-nixpkgs-check-by-name" { + nativeBuildInputs = [ + results.build + pkgs.nix + ]; + nixpkgsPath = nixpkgs; + } '' + ${initNix} + nixpkgs-check-by-name --base "$nixpkgsPath" "$nixpkgsPath" + touch $out + ''; }; - # Run regularly by CI and turned into a PR - autoPrUpdate = pkgs.writeShellApplication { - name = "auto-pr-update"; - runtimeInputs = with pkgs; [ - npins - cargo - ]; - text = - let - commands = [ - "npins update" - "cargo update" - ]; - in - '' - echo "Run automated updates" - '' - + pkgs.lib.concatMapStrings (command: '' - echo -e '
${command}\n\n```' - ${command} 2>&1 - echo -e '```\n
' - '') commands; - }; +in +results.build // results // { + + # Good for debugging + inherit pkgs; + + # Built by CI + ci = pkgs.linkFarm "ci" results; - # Tests the tool on the pinned Nixpkgs tree, this is a good sanity check - checks.nixpkgs = pkgs.runCommand "test-nixpkgs-check-by-name" { - nativeBuildInputs = [ - build - pkgs.nix - ]; - nixpkgsPath = nixpkgs; - } '' - ${initNix} - nixpkgs-check-by-name --base "$nixpkgsPath" "$nixpkgsPath" - touch $out - ''; } From 45610704d1d0f5ce0be892f6a6bf2701c56ab148 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 22 Mar 2024 00:39:51 +0100 Subject: [PATCH 2/2] Fix automated updates (another try) See https://github.com/NixOS/nixpkgs-check-by-name/pull/20#issuecomment-2013998832 We fix this by telling the update scripts explicitly which files they should update and passing that information in from CI --- .github/workflows/update.yml | 2 +- default.nix | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 0bb99cb..9bdb24e 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -17,7 +17,7 @@ jobs: - name: update run: | nix-build repo -A autoPrUpdate - result/bin/auto-pr-update > body + result/bin/auto-pr-update repo > body - name: Create Pull Request uses: peter-evans/create-pull-request@v6 diff --git a/default.nix b/default.nix index 462826e..0004bf5 100644 --- a/default.nix +++ b/default.nix @@ -56,19 +56,22 @@ let ]; text = let - commands = [ - "npins update" - "cargo update" - ]; + commands = { + "npins changes" = '' + npins update --directory "$REPO_ROOT/npins"''; + "cargo changes" = '' + cargo update --manifest-path "$REPO_ROOT/Cargo.toml"''; + }; in '' + REPO_ROOT=$1 echo "Run automated updates" '' - + pkgs.lib.concatMapStrings (command: '' - echo -e '
${command}\n\n```' + + pkgs.lib.concatStrings (pkgs.lib.mapAttrsToList (title: command: '' + echo -e '
${title}\n\n```' ${command} 2>&1 echo -e '```\n
' - '') commands; + '') commands); }; # Tests the tool on the pinned Nixpkgs tree, this is a good sanity check