Skip to content

Commit

Permalink
Merge pull request #21 from NixOS/fix-updates
Browse files Browse the repository at this point in the history
Fix updates (another try)
  • Loading branch information
philiptaron committed Mar 21, 2024
2 parents 4208244 + 4561070 commit febcf57
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 60 additions & 52 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,63 +30,71 @@ 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 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.concatStrings (pkgs.lib.mapAttrsToList (title: command: ''
echo -e '<details><summary>${title}</summary>\n\n```'
${command} 2>&1
echo -e '```\n</details>'
'') 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 '<details><summary>${command}</summary>\n\n```'
${command} 2>&1
echo -e '```\n</details>'
'') 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
'';
}

0 comments on commit febcf57

Please sign in to comment.