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

Prepare inclusion in nixos-search #2971

Merged
merged 4 commits into from
Jun 7, 2022

Conversation

ncfavier
Copy link
Member

@ncfavier ncfavier commented May 20, 2022

Description

Lays the groundwork for NixOS/nixos-search#323 by making

nix run nixos-search#flake-info -- flake github:nix-community/home-manager

succeed. Note that this PR does NOT solve the problem of how to expose Home Manager modules/options in the flake, it only ensures that we can index packages and NixOS options.

Best reviewed one commit at a time.

This PR partly supersedes #1934, although it does not add an auto-update workflow.

Tested the NixOS module and the manual. nix-darwin testers welcome.

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

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

@ncfavier ncfavier marked this pull request as draft May 21, 2022 12:40
@ncfavier ncfavier force-pushed the nixos-searchable branch from f420bf3 to 8d75e43 Compare May 21, 2022 18:14
@ncfavier ncfavier marked this pull request as ready for review May 21, 2022 18:18
@teto
Copy link
Collaborator

teto commented Jun 5, 2022

I am happy to see this initiative but why mixing it with format changes ? can these go in another MR ?

Is the following expected ?

$ nix run nixos-search#flake-info -- flake github:ncfavier/home-manager/nixos-searchable
warning: Using saved setting for 'extra-substituters = https://nixos-search.cachix.org' from ~/.local/share/nix/trusted-settings.json.
warning: Using saved setting for 'extra-trusted-public-keys = nixos-search.cachix.org-1:1HV3YF8az4fywnH+pAd+CXFEdpTXtv9WpoivPi+H70o=' from ~/.local/share/nix/trusted-settings.json.
[2022-06-05T10:03:11Z ERROR command_run] command 'nix eval --json --no-write-lock-file -f /tmp/.tmpRoip4S/extract.nix --override-flake input-flake github:ncfavier/home-manager/nixos-searchable --argstr flake github:ncfavier/home-manager/nixos-searchable all' failed: exit status: 1
    stdout:
    
    stderr:
    warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
    error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
    
           at /tmp/.tmpRoip4S/extract.nix:5:21:
    
                4|
                5|   nixpkgs = (import <nixpkgs> {});
                 |                     ^
                6|   lib = nixpkgs.lib;
    (use '--show-trace' to show detailed location information)
    
Error: Getting flake info caused an error: Failed to gather information about github:ncfavier/home-manager/nixos-searchable

Caused by:
    command 'nix eval --json --no-write-lock-file -f /tmp/.tmpRoip4S/extract.nix --override-flake input-flake github:ncfavier/home-manager/nixos-searchable --argstr flake github:ncfavier/home-manager/nixos-searchable all' failed: exit status: 1

@ncfavier
Copy link
Member Author

ncfavier commented Jun 5, 2022

I am happy to see this initiative but why mixing it with format changes ? can these go in another MR ?

I suppose they can, but does it matter? This is just a big clean-up PR. Removed the formatting changes.

Is the following expected ?

Nope, that's a bug in nixos-search. In the meantime you can do export NIX_PATH=nixpkgs=channel:nixpkgs-unstable. Fixed now.

@teto
Copy link
Collaborator

teto commented Jun 5, 2022

arf nmd issue:

    error: a 'aarch64-darwin' with features {} is required to build '/nix/store/rsiqrib1rv2shc6azv12xcbkvxs9hj32-nmd.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test}
    (use '--show-trace' to show detailed location information)

@ncfavier
Copy link
Member Author

ncfavier commented Jun 5, 2022

Ah, I guess I didn't run into that because that path was substituted by the nix-community cache.

So we should probably add nmd and nmt to the flake inputs instead of having an IFD (which I did initially but then I thought it wasn't needed).

@ncfavier ncfavier force-pushed the nixos-searchable branch from 176833a to bfb27a7 Compare June 5, 2022 12:31
@ncfavier
Copy link
Member Author

ncfavier commented Jun 5, 2022

Should be fixed now

flake.nix Outdated Show resolved Hide resolved
ncfavier added 4 commits June 7, 2022 20:07
Add a lockfile to work around NixOS/nix#6541
(and because it's a good idea anyway).

Also use flake-utils, and restrict ourselves to the five platforms
supported by nixpkgs. Otherwise, the IFD for nmd fails on weird
platforms. This fixes `nix flake check`.

Remove the redundant `apps` output, see nix-community#2442 (comment)
Make sure the option is included in the NixOS/nix-darwin manual (but the
HM submodule options aren't).

Also add a static description to the HM submodule type so that we don't need to
evaluate the submodules just to build the option manual. This makes
nixos-search able to index the home-manager flake.

Also clean up some TODOs.
This avoids having to use `pkgs.fetchFromGitLab` in an IFD, which causes
issues when indexing packages with nixos-search because `pkgs` is
instantiated with every platform.
@ncfavier ncfavier force-pushed the nixos-searchable branch from bfb27a7 to 5b98520 Compare June 7, 2022 18:09
@teto teto merged commit 64ab7d6 into nix-community:master Jun 7, 2022
@ncfavier ncfavier deleted the nixos-searchable branch June 7, 2022 18:49
@ncfavier
Copy link
Member Author

ncfavier commented Jun 7, 2022

Thanks for the quick merge! (EDIT: wait, it's been 18 days? where does time go...)

@rycee quick heads-up since I don't know how familiar you are with flakes: inputs like nmd and nmt can now be updated with nix flake lock --update-input nmd (you'll need to enable the flakes and nix-command experimental features). But maybe we want to automate this as part of #1934?

Copy link
Member

@rycee rycee left a comment

Choose a reason for hiding this comment

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

I don't know much about Flakes so I'll defer to @teto's judgement about merging. I just added a few minor comments that I didn't see discussed, probably because they are too blindingly obvious for people who aren't ignorant about Flakes 🙂

Comment on lines +5 to +11
flake = (import
(let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url =
"https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) { src = ./.; }).defaultNix;
Copy link
Member

Choose a reason for hiding this comment

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

This feels pretty ugly to me. Why not simply change the pkgs.fetchFromGitLab to fetchTarball when fetching nmd and nmt?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is only a compatibility layer that should progressively become useless as we transition to flakes and the new nix CLI.

Why not simply change the pkgs.fetchFromGitLab to fetchTarball when fetching nmd and nmt?

We could, but if we're going to use flakes, we might as well use them fully, i.e. for all inputs. I think they're a nicer way to manage dependencies, and they make updating and overriding easier.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that eventually it will be worth switching over to flakes but I'm skeptical about delving too deep while the feature is marked as experimental. At least unless there is a really compelling reason. But in this case there is a straight forward way to avoid the pkgs reference without touching flakes and needing compatibility shims.

I also would like to move the nmt and nmd projects over to sourcehut at some point and it doesn't seem like the flake-compat project supports the sourcehut URLs. I'll probably maintain a mirror at the gitlab location so this is not a blocker, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's also not a blocker because we can just use URLs like git+https://git.sr.ht/~rycee/nmt.

Copy link
Member

Choose a reason for hiding this comment

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

I'm skeptical about delving too deep while the feature is marked as experimental.

It is only marked as experimental to not have to create backwards compatibility while it still might change.

Comment on lines +19 to +34
"nixpkgs": {
"locked": {
"lastModified": 1654230545,
"narHash": "sha256-8Vlwf0x8ow6pPOK2a04bT+pxIeRnM1+O0Xv9/CuDzRs=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "236cc2971ac72acd90f0ae3a797f9f83098b17ec",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
Copy link
Member

Choose a reason for hiding this comment

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

I want it to be explicit to the user which Nixpkgs they are using in their configuration. I.e., HM should never be responsible for pinning Nixpkgs on behalf of users. So if we are pinning Nixpkgs here wouldn't we also need to change

pkgs ? builtins.getAttr system nixpkgs.outputs.legacyPackages

to simply

pkgs

in the homeManagerConfiguration function?

Ideally, perhaps disallowing

home-manager.url = "github:nix-community/home-manager";

without an accompanying

home-manager.inputs.nixpkgs.follows = "nixpkgs";

would be most reassuring but I don't know if that is possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

So if we are pinning Nixpkgs here wouldn't we also need to change

Agreed, I'll do that in a follow-up PR.

Ideally, perhaps disallowing

That's not possible, and I think it would be overkill: we only need to ensure that the nixpkgs input is not passed down to the HM modules, but we may (and should) use the locked nixpkgs for flake packages.

integration-common.nix Show resolved Hide resolved
ncfavier added a commit to ncfavier/home-manager that referenced this pull request Jun 16, 2022
Prevents Home Manager from pinning nixpkgs on behalf of users, see
nix-community#2971 (comment)
ncfavier added a commit to ncfavier/home-manager that referenced this pull request Jun 16, 2022
Prevents Home Manager from pinning nixpkgs on behalf of users, see
nix-community#2971 (comment)
@ncfavier ncfavier mentioned this pull request Jun 16, 2022
@ncfavier
Copy link
Member Author

#3028

rycee pushed a commit to ncfavier/home-manager that referenced this pull request Jun 18, 2022
Prevents Home Manager from pinning nixpkgs on behalf of users, see
nix-community#2971 (comment)
rycee pushed a commit to ncfavier/home-manager that referenced this pull request Jun 18, 2022
Prevents Home Manager from pinning Nixpkgs on behalf of users, see

  nix-community#2971 (comment)
@wmertens
Copy link
Contributor

so what is now the way to pass nixpkgs? It is not clear to me at all. I tried passing pkgs = inputs.nixpkgs.outputs.legacyPackages but then lib is missing.

The docs for flakes haven't been updated yet.

@ncfavier
Copy link
Member Author

ncfavier commented Jun 20, 2022

nixpkgs.legacyPackages.${system}

See #3037 for the docs update

jevy pushed a commit to jevy/home-manager that referenced this pull request Jul 1, 2022
* Add flake.lock and clean up flake.nix

Add a lockfile to work around NixOS/nix#6541
(and because it's a good idea anyway).

Also use flake-utils, and restrict ourselves to the five platforms
supported by nixpkgs. Otherwise, the IFD for nmd fails on weird
platforms. This fixes `nix flake check`.

Remove the redundant `apps` output, see nix-community#2442 (comment)

* nixos,nix-darwin: factor out into a common module

* nixos,nix-darwin: make `home-managers.users` shallowly visible

Make sure the option is included in the NixOS/nix-darwin manual (but the
HM submodule options aren't).

Also add a static description to the HM submodule type so that we don't need to
evaluate the submodules just to build the option manual. This makes
nixos-search able to index the home-manager flake.

Also clean up some TODOs.

* flake: add nmd and nmt

This avoids having to use `pkgs.fetchFromGitLab` in an IFD, which causes
issues when indexing packages with nixos-search because `pkgs` is
instantiated with every platform.
jevy pushed a commit to jevy/home-manager that referenced this pull request Jul 1, 2022
Prevents Home Manager from pinning Nixpkgs on behalf of users, see

  nix-community#2971 (comment)
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/the-nix-module-in-home-manager-and-nixos/20999/11

spacekookie pushed a commit to spacekookie/home-manager that referenced this pull request Feb 10, 2023
* Add flake.lock and clean up flake.nix

Add a lockfile to work around NixOS/nix#6541
(and because it's a good idea anyway).

Also use flake-utils, and restrict ourselves to the five platforms
supported by nixpkgs. Otherwise, the IFD for nmd fails on weird
platforms. This fixes `nix flake check`.

Remove the redundant `apps` output, see nix-community#2442 (comment)

* nixos,nix-darwin: factor out into a common module

* nixos,nix-darwin: make `home-managers.users` shallowly visible

Make sure the option is included in the NixOS/nix-darwin manual (but the
HM submodule options aren't).

Also add a static description to the HM submodule type so that we don't need to
evaluate the submodules just to build the option manual. This makes
nixos-search able to index the home-manager flake.

Also clean up some TODOs.

* flake: add nmd and nmt

This avoids having to use `pkgs.fetchFromGitLab` in an IFD, which causes
issues when indexing packages with nixos-search because `pkgs` is
instantiated with every platform.
spacekookie pushed a commit to spacekookie/home-manager that referenced this pull request Feb 10, 2023
Prevents Home Manager from pinning Nixpkgs on behalf of users, see

  nix-community#2971 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants