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

add flake attribute apps to make it easier to run #2442

Merged
merged 1 commit into from Nov 23, 2021

Conversation

contrun
Copy link
Contributor

@contrun contrun commented Nov 4, 2021

Description

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.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

    • Added myself and the module files to .github/CODEOWNERS.

@contrun contrun requested a review from rycee as a code owner November 4, 2021 08:02
flake.nix Outdated Show resolved Hide resolved
Copy link
Member

@berbiche berbiche left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Can you remove the committed flake.lock file?

@contrun
Copy link
Contributor Author

contrun commented Nov 23, 2021

@berbiche It seems nix run requires a flake.lock. What's the downside of including a flake.lock?

@berbiche
Copy link
Member

@berbiche It seems nix run requires a flake.lock.

--no-write-lock-file

What's the downside of including a flake.lock?

The downside is that we would need to keep HM's flake inputs updated and we currently do not have an automated way of doing it.
There's a PR to add a workflow to update HM's flake.lock that is still waiting for something (I lost track).

This change also adds the required flake.lock. As a result,
home-manager can be ran with
`nix run --no-write-lock-file github:nix-community/home-manager`.
This is useful for people who want to try out home-manager or,
want to bootstrap their home-environment.
@contrun
Copy link
Contributor Author

contrun commented Nov 23, 2021

@berbiche Maybe you are referring to #1913 ? I removed flake.lock for now.

@berbiche
Copy link
Member

@berbiche Maybe you are referring to #1913 ? I removed flake.lock for now.

#1934

@berbiche berbiche merged commit c4c761b into nix-community:master Nov 23, 2021
peterhoeg pushed a commit to peterhoeg/home-manager that referenced this pull request Nov 29, 2021
Home Manager can be ran with
`nix run --no-write-lock-file github:nix-community/home-manager`.

This is useful for people who want to try out Home Manager or,
want to bootstrap their home-environment.
@terlar
Copy link
Contributor

terlar commented Dec 1, 2021

@contrun thanks for this, what do you think about having the defaultApp be flake native, e.g. add --flake to the command first. We could provide another app that returns home-manager without the flake flag.

I mentioned this earlier here:
#2523 (comment)

With such a wrapper we could have:

nix run github:nix-community/home-manager switch .

And for the non-flake one it could be something like:

nix run github:nix-community/home-manager#legacy switch

@contrun
Copy link
Contributor Author

contrun commented Dec 2, 2021

@terlar I agree. Currently we can use flake for home-manager by passing --flake flake-uri to home-manager. Users may expect to run home-manager like home-manager switch [flake-uri], where flake-uri is optional. I don't know if wrapping home-manager with home-manager --flake is acceptable for now, or we need to change the way home-manager taking arguments. Maybe home-manager can have a feature gate, i.e. if environment variable USE_FLAKE is present, then home-manager should be flake-native.

@akavel
Copy link

akavel commented Dec 2, 2021

(...) Maybe home-manager can have a feature gate (...)

Noob question (I reported the #2523, so I'm an interested party noob): could it make sense to do the detection based on whether a flake.nix file exists at the target location (i.e. ~/.config/nixpkgs/flake.nix by default, or [flake-uri]/flake.nix, or whatever)?

To my noobish eyes this sounds reasonable: if someone has a flake.nix file, the default assumption that they want to opt-in to flakes seems to make sense (and could still be e.g. opted out with some --no-flake flag possibly); OTOH, if someone doesn't have flake.nix, they probably want the old behavior by default.

@contrun
Copy link
Contributor Author

contrun commented Dec 4, 2021

@akavel All the configuration should be contained in the flake itself. That's the whole point of nix flakes, to make the building hermetic. Flake version of home-manager shouldn't depend on host-specific behavior.

@ncfavier
Copy link
Member

ncfavier commented May 21, 2022

Why was this added? The default behaviour of nix run (since at least 2.4) if there are no apps is to run /bin/${pname} under the default package, which does what we want here.

Adding an app would only be useful if we wanted to add a default --flake flag as suggested, but I don't think it's a good idea to artificially introduce CLI differences based on how the command is invoked. Instead, we could make home-manager take an optional flake as a positional argument: home-manager [OPTIONS...] COMMAND [FLAKE].

Also note that this stopped working in Nix 2.8: NixOS/nix#6448 (comment)

Dropping apps in #2971

ncfavier added a commit to ncfavier/home-manager that referenced this pull request May 21, 2022
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)
ncfavier added a commit to ncfavier/home-manager that referenced this pull request Jun 5, 2022
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)
ncfavier added a commit to ncfavier/home-manager that referenced this pull request Jun 7, 2022
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)
teto pushed a commit that referenced this pull request Jun 7, 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 #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
* 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
* 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.
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.

None yet

6 participants