Skip to content
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

nixos/modules/flake/source-info: new module #179772

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions nixos/modules/flake/source-info.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ config, lib, ... }:

with lib;

let sourceInfo = config.system.nixos.configuration.sourceInfo;

in
{
options = {

system.nixos.configuration.sourceInfo = mkOption {
type = types.attrsOf types.anything;
default = {};
example = "self.sourceInfo";
description = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do this and then write markdown if you like

Suggested change
description = ''
description = lib.mdDoc ''

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. The example also gets improved.

The source information of a flake-based NixOS configuration.
If set, the attribute <literal>configurationRevision</literal>
will appear properly in the output of
<literal>nixos-version --json</literal>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it also occur in the grub and systemd-boot boot menus?

Copy link
Member Author

@herberteuler herberteuler Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not. Currently, the menus contain only the shortRev of nixpkgs. Should we add the configuration revision to versionSuffix too? If both revisions are to be included, they should be made distinctive.

Note that the nixpkgs revision can be dirty too; we may develop a uniform way to obtain revisions, and apply it to both occasions. What do you think about my earlier proposals on setting the dirty tag? I can start to work on a prototype after we discuss and reach an agreement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not.

Ok. That can be done in another PR if desirable.

we may develop a uniform way to obtain revisions

Sounds good, but these are all quite independent problems. It's best to resolve them in separate PRs, so that maintainers don't need to keep (in the limit) all of NixOS in their head in order to approve them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, there will be at least three PRs: this one, one for obtaining revisions, and another one for applying the feature. I will try to write a detailed design later.


Caution: Setting this option may result in unnecessary
re-deployments if the flake repository changes but the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
re-deployments if the flake repository changes but the
boot loader entries or re-deployments if the flake repository changes but the

specific system configuration does not change.
'';
};
};

config = {
system.configurationRevision = mkIf (sourceInfo ? rev) sourceInfo.rev;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set it to "dirty" when we see that sourceInfo is from git but does not have rev?
We don't have a type-like attribute in there (yet?), but the presence of submodules should give it away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention of setting it to dirty, to my understanding, is to help identify the state of the configuration better. To answer this question well, I checked the relevant code, and have two proposals:

  1. We can do it for all supported VCSes, not just git. For instance, mercurial is also supported (albeit immature). This is partly due to only git getting special handling while examining local paths, and we may improve that too to enable support for other VCSes. This also implies a standardized, fine-grained specification of source information, as will be discussed in sourceInfo does not tell us whether it's git or not nix#6747.

  2. To further tell differences among dirty configurations, we can fetch the latest update time of a repository and set something like dirty-<timestamp>. The latest update time can be defined as the most recent modification time of all files in the repository.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roberth Do we solve this later as a part of NixOS/rfcs#125?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can scope this discussion out regardless.

};
}
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
./config/users-groups.nix
./config/vte.nix
./config/zram.nix
./flake/source-info.nix
./hardware/acpilight.nix
./hardware/all-firmware.nix
./hardware/bladeRF.nix
Expand Down