-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flake.lock & workflow to update it #1934
Conversation
at some point it was discussed to open a PR instead of an automatic merge. I preferred that scenario, is that doable through github actions ? nevermind the checks, they can be added later |
I can have the workflow edit: I should clarify: no more than 1 flake update PR will be open at a time, but it will require manual merging each time it gets opened (at most twice a week). |
That seems the best option, would it close and open a new PR or force-push to the current one ? |
If the update action runs and there's already an existing PR, it will just force-push that branch. The Also remember that a new secret containing a github token with push access to the repo needs to be made so we can trigger other workflows on the PR. I'd like to add the I'll update the workflow to push to a new branch later today. |
1c5b7e8
to
29daba6
Compare
README.md
Outdated
home-manager.url = "github:nix-community/home-manager"; | ||
home-manager = { | ||
url = "github:nix-community/home-manager"; | ||
inputs.nixpkgs.follows = "nixpkgs"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is potentially harmful, advanced users can use it but we should default to the mainstream method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you elaborate on how this is potentially harmful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
home-manager is guaranteed to work with the nixpkgs in its lock file, it has not been tested with the overriden version so there is a risk of failure no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO users typically expect their entire configuration to be evaluated against a single instance of nixpkgs
unless they specify otherwise, so I figured overriding the input would be a sensible thing to include here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, that's not how flakes are conceived (it doesn't default to a single nixpkgs) and I think users prefer something that work rather than shaving off a few MB on the disk. It's still possbile but shouldn't be the default I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kclejeune, maybe I'm confused. I don't see any way to create a token for an organization. What I can see is a way to create a secret, but then I have to provide a value. Perhaps I don't have sufficient access to the nix-community organization? In the documentation I found https://docs.github.com/en/organizations/managing-organization-settings/disabling-or-limiting-github-actions-for-your-organization but it seems to be limited to GITHUB_TOKEN
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kclejeune, maybe I'm confused. I don't see any way to create a token for an organization. What I can see is a way to create a secret, but then I have to provide a value. Perhaps I don't have sufficient access to the nix-community organization? In the documentation I found https://docs.github.com/en/organizations/managing-organization-settings/disabling-or-limiting-github-actions-for-your-organization but it seems to be limited to
GITHUB_TOKEN
.
edit: it's not possible the dummy account is probably the way to go until I can finish the flakebot app in a week or two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is possible, personal access tokens are per-user only, not per-organization. I am an owner of another GitHub org and I see no such option to create a token at the org level.
The org can have secrets that are maintained at the org level, but their values (in our case: access tokens) would be generated per-user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rycee Yes. Please open a ticket at https://github.com/nix-community/infra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we fix this ? that's the last issue before merging I think ? @Mic92 you seem to have the necessary rights, haven't you ?
.github/workflows/update.yml
Outdated
PULL_REQUEST_FROM_BRANCH: flake-update | ||
PULL_REQUEST_BRANCH: master | ||
PULL_REQUEST_UPDATE: true | ||
PASS_ON_ERROR: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will open a new pull request against the master
branch, or, if one exists already, update the existing one. PASS_ON_ERROR
is set to true since this action will always be run, regardless of whether the flake was updated during the workflow. So if there were no changes, this step would fail, but we don't want the workflow to fail because of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead check if there was any update, and optionally skip this step? Because I'm not sure if we should have a blanked ignore of all errors. Could be hard to notice when there are actual issues.
One way to do this is checking the commit_info
declared above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this will be a lot harder than just checking commit_info
, since that is literally the commit info of HEAD, regardless of whether a flake update was committed or not. I suppose I can check if a commit was made by comparing against github.sha
, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about it some more, I think a better way to do this would be to ask the author of the action to let us specify to pass just if there are no new commits, that way I don't have to "reinvent the wheel". I can open an issue for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Action author has suggested that I just implement this logic in this workflow's step, so I have pushed 0be2c37. @asymmetric can you check if this looks right?
flake.nix
Outdated
@@ -29,10 +31,9 @@ | |||
hm = import ./modules/lib { lib = nixpkgs.lib; }; | |||
homeManagerConfiguration = { configuration, system, homeDirectory | |||
, username, extraModules ? [ ], extraSpecialArgs ? { } | |||
, pkgs ? builtins.getAttr system nixpkgs.outputs.legacyPackages | |||
, check ? true, stateVersion ? "20.09" }@args: | |||
, pkgs ? nixpkgsFor.${system}, check ? true, stateVersion ? "20.09" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nit, but why do we need to use a custom function when nixpkgs.legacyPackages.${system}
would suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured it was a more succinct expression that was being used elsewhere anyways. I can revert this particular change, though.
If this is the only reason, wouldn't it make more sense to fix it on nix's side? Why does |
See the discussion in NixOS/nix#4699. |
.github/workflows/update.yml
Outdated
git checkout -B flake-update | ||
- name: Update & commit lockfile | ||
run: | | ||
nix flake update --commit-lock-file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nix flake update
will update all inputs. At the moment it's only nixpkgs
, but if we added more, that could be surprising.
nix flake update --commit-lock-file | |
nix flake lock --update-input nixpkgs --commit-lock-file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR body will list the updated inputs (actually, it just inserts the auto-generated commit message), so it won't be as surprising. I think it's better that we update all inputs if more get added so we don't have a situation where inputs haven't been updated in weeks or months.
what is blocking ? looking forward to this to make lockstep updates in home-manager. Right now, when the nixos-unstable channel updates it can very well break home-manager. It would be better if we could choose what version of nixos-unstable works well via the flake. |
From my understanding it requires a github token still? I can add one on every level. |
If you need any organisational changes please drop a message in #nix-community:bethselamin.de or |
Has a token been added as a secret to this repo? What else needs to be done to move this PR forward? |
No. I have received no token so far. I think the best solution would be if one of the home-manager maintainer create a bot account that we add to the nix-community organisation. |
Thank you for your contribution! I marked this pull request as stale due to inactivity. If this remains inactive for another 7 days, I will close this PR. Please read the relevant sections below before commenting. If you are the original author of the PR
If you are not the original author of the PR
|
When I tried to execute:
I got:
However, if I execute:
It works well. I think we might also want to add a |
This is already provided ( |
@DeterminateSystems have since released a GitHub Action that does what we would want, and it's probably better for home-manager to use that rather than maintain its own workflow. I can update this workflow to using that action instead. It will use a default automated token for opening update PRs, but we'll still need to provide a personal auth token if we want to run tests against these PRs. |
#2971 adds a
Yes, I think that's better.
This is currently not needed as the CI tests don't use the flake at all (maybe they should...).
Fixed in #2971, see #2442 (comment). About the interval, I think twice a week is excessive considering that the updates require human intervention. Once every one or two weeks seems about right, maybe less often for release branches if we choose to update them (maybe release branches should follow the appropriate |
My hope is that we'd later port rycee's home-manager testing framework to support flakes in a later PR. I was working on that very briefly, but stopped a while ago because of schoolwork.
I agree that release branches should follow the corresponding branch in nixpkgs. In particular, I think
I suppose that means, going forward from However, that would mean maintainers would have to review 2 PRs per run of this workflow (for master and current release branch). |
I added a secret for a github bot in this repo. If you use the |
The access of this bot is managed with terraform here: https://github.com/Mic92/dotfiles/blob/master/terraform/modules/github-push-bot/main.tf and here https://github.com/Mic92/dotfiles/blob/master/terraform/github-bots/main.tf |
#2971 was merged, we have a flake.lock now. |
Thank you @ncfavier and @Mic92 for your help. A lot has happened since I opened this PR, so later today I will rebase my branch onto the tip of the master branch and redo most of the work so that it only adds the update workflow, since we now have a flake.lock. As I mentioned somewhere earlier in this PR, future work will involve porting home-manager's tests to the |
Alright, branch rebased. Since most of the work in the rest of the old commits was done elsewhere, this PR now just implements that update workflow. PRs will be tagged with the "dependencies" label (like dependabot does) to distinguish it from other PRs. |
tempted to merge this (and if it breaks stuff we'll deal with it). Any objection ? |
I'm fine with that. I will just draw attention to #1934 (comment), in particular whether release branches should receive a similar update workflow, perhaps in a later PR:
We don't have to address this now, but perhaps if we merge this PR we should consider doing the above on the next NixOS release. |
Description
This PR implements suggestions from #1913, adding a flake.lock file so we can
nix run github:nix-community/home-manager
without any hiccups. The nixpkgs input is currently set to tracknixos-unstable
. If you want to test this out, you can runnix run github:nix-community/home-manager/pull/1934/head
, which should give you the help text.To keep this file up to date, the PR also adds a GitHub workflow that
nix flake update --commit-lock-file
, committing as a nonexistent user calledflakebot
directly to masterto a new branch calledflake-update
with a custom tokenFLAKEBOT_TOKEN
(this needs to be added to the repo)Also updates the README to change the section on a flake-based config a bit.
I also wanted to modify the testing workflow to actually run home-manager's tests, but was having a bit of trouble exposing the tests under the
checks
output of the flake, so I will leave that out for now.This means that the update workflow will just regularly push updates to master, whether they pass tests or not.cc @berbiche since we were talking about this in the other PR.
Checklist
Change is backwards compatible.
Code formatted with
./format
.Code tested through
nix-shell --pure tests -A run.all
.Test cases updated/added. See example.
Commit messages are formatted like
See CONTRIBUTING for more information and recent commit messages for examples.
If this PR adds a new module
Added myself as module maintainer. See example.
Added myself and the module files to
.github/CODEOWNERS
.