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 home-manager instantiate subcommand #1099

Closed
wants to merge 1 commit into from

Conversation

timokau
Copy link
Contributor

@timokau timokau commented Mar 17, 2020

It can be useful to simply instantiate a home-manager configuration
without actually building it, for example for the purpose of
pre-building it with some custom command.

One recent usage example: I was trying to build a home-manager configuration with a custom tool (nix-bisect) before switching to the configuration. That would be much simpler and less hacky if home-manager provided a way to instantiate a configuration.

@teto
Copy link
Collaborator

teto commented Mar 21, 2020

nix-bisect is really impressive, if this can support your tool, +1 from me

@@ -182,6 +190,21 @@ function doBuild() {
return $exitCode
}

function doInstantiate() {
local exitCode
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest not reusing doBuildAttr and instead have something like

function doInstantiate() {
    setConfigFile
    setHomeManagerNixPath

    local extraArgs=("$@")

    for p in "${EXTRA_NIX_PATH[@]}"; do
        extraArgs=("${extraArgs[@]}" "-I" "$p")
    done

    if [[ -v VERBOSE ]]; then
        extraArgs=("${extraArgs[@]}" "--show-trace")
    fi

    nix-instantiate \
        "<home-manager/home-manager/home-manager.nix>" \
        "${extraArgs[@]}" \
        "${PASSTHROUGH_OPTS[@]}" \
        --argstr confPath "$HOME_MANAGER_CONFIG" \
        --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
}

@@ -74,6 +74,7 @@ function setHomeManagerNixPath() {
done
}


Copy link
Member

Choose a reason for hiding this comment

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

Can remove this line.

@rycee
Copy link
Member

rycee commented Mar 23, 2020

Yes, I think this is a good idea 👍

If you adjust the code per the comment I added then I'd be happy to merge.

@timokau timokau force-pushed the instantiate-command branch from 7b73f71 to 64c9f87 Compare March 23, 2020 23:28
@timokau
Copy link
Contributor Author

timokau commented Mar 23, 2020

I applied the suggested changes, butfor some reason home-manager instantiate now returns two derivations: One for the home-manager generation, one for the news:

/nix/store/csdjljxmqlj76dryj1rc90j2ljnzj40p-home-manager-generation.drv
/nix/store/aadq2r0mpg151lfx1scal68583i5gjnq-news-info.sh.drv

Was that intentional? I don't quite understand why this happens (it didn't before).

@rycee
Copy link
Member

rycee commented Mar 24, 2020

Nice, I think this looks cleaner.

Yes, the two derivations are intentional. If you want just the generation derivation then add --attr activationPackage to the nix-instantiate command.

Also don't forget to update the doHelp function in the script, the doc/man-home-manager.xml file, and the home-manager/completion.bash file so that they include the new instantiate sub-command.

It can be useful to simply instantiate a home-manager configuration
without actually building it, for example for the purpose of
pre-building it with some custom command.
@timokau timokau force-pushed the instantiate-command branch from 64c9f87 to e343713 Compare March 25, 2020 14:03
@timokau
Copy link
Contributor Author

timokau commented Mar 25, 2020

Yes, the two derivations are intentional. If you want just the generation derivation then add --attr activationPackage to the nix-instantiate command.

Ah, I missed that bit. Intuitively I would expect the command to only instantiate the activation package, since that is the "interesting" part that one might want to pre-build or that might fail to build. But at worst the news derivation makes scripting slightly more cumbersome. I don't really mind. What do you prefer?

Also don't forget to update the doHelp function in the script, the doc/man-home-manager.xml file, and the home-manager/completion.bash file so that they include the new instantiate sub-command.

Thanks for the hints! Done. In the process I also noticed that bash completions were missing in the nixpkgs package, so I fixed that: NixOS/nixpkgs#83360.

Note that I've never written a man page or bash completions, but I just adapted what was already there and it seems to work fine.

rycee pushed a commit that referenced this pull request Mar 25, 2020
It can be useful to simply instantiate a Home Manager configuration
without actually building it, for example for the purpose of
pre-building it with some custom command.

PR #1099
@rycee
Copy link
Member

rycee commented Mar 25, 2020

Looks good! Rebased to master in 5969551.

@rycee rycee closed this Mar 25, 2020
@timokau timokau deleted the instantiate-command branch March 25, 2020 22:54
timokau added a commit to timokau/nixpkgs that referenced this pull request Mar 30, 2020
timokau added a commit to timokau/dotfiles that referenced this pull request Apr 7, 2020
This makes better use of parallelization and hopefully will fail earlier
if there is an issue. Possible since

nix-community/home-manager#1099
jorsn pushed a commit to jorsn/home-manager that referenced this pull request Apr 25, 2020
It can be useful to simply instantiate a Home Manager configuration
without actually building it, for example for the purpose of
pre-building it with some custom command.

PR nix-community#1099
NickHu pushed a commit to NickHu/home-manager that referenced this pull request May 19, 2020
It can be useful to simply instantiate a Home Manager configuration
without actually building it, for example for the purpose of
pre-building it with some custom command.

PR nix-community#1099
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.

3 participants