-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Accessing flakes from inside home-manager modules #1698
Comments
One way to do it is to inject {
description = "NixOS configuration";
inputs = {
# Some flake I want to access in a home-manager module
desiredflake = {
url = "github:zsh-users/antigen/v2.2.3";
flake = false;
};
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
darwin.url = "github:lnl7/nix-darwin/master";
darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { desiredflake, home-manager, nixpkgs, darwin, ... }: {
defaultPackage.x86_64-darwin = (darwin.lib.darwinSystem {
inputs = { inherit home-manager nixpkgs darwin desiredflake; };
modules = [
home-manager.darwinModules.home-manager
{
home-manager.useUserPackages = true;
home-manager.users.someuser = import ./home.nix;
}
({ config, lib, ... }: {
options.home-manager.users = lib.mkOption {
type = with lib.types; attrsOf (submoduleWith {
specialArgs = { super = config; inherit desiredflake; };
});
};
})
];
}).system;
};
} |
Thanks @terlar that's really useful! I'm not sure which is the better option - I managed to get something to work by currying imports like this home.nix flakes: { pkgs, ... }:
{
programs.zsh = {
enable = true;
plugins = [
{
name = "zsh-nix-shell";
file = "antigen.zsh";
src = flakes.desiredflake;
}
];
};
} home-manager.users.someuser = import ./home.nix { desiredflake = desiredflake; }; |
The changes done in this PR would need to be applied to the NixOS module and the Darwin module. |
@andyrichardson is this still an issue with #1699 merged? |
@berbiche So I would say this is still an issue, and if someone have some idea on how to fix it would be great (I am still learning how the whole Flake works). |
I've resorted to currying so cannot comment on whether the newest changes have worked. I've pulled the latest flake but I'm a bit of a nix noob so I wasn't able to work out where to add |
For the next person who comes across this issue, {
outputs = { self, neovim-nightly-overlay, unstable, home-manager, hwConfig, nixpkgs, scripts }:
{
nixosConfigurations.nixos =
let
system = "x86_64-linux";
specialArgs = {
inherit hwConfig neovim-nightly-overlay scripts;
};
modules = [
./hosts/nixos/configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.foo = import ./hosts/nixos/home.nix;
home-manager.extraSpecialArgs = specialArgs;
}
];
in
unstable.lib.nixosSystem { inherit system modules specialArgs; };
};
}
// home.nix can now use "scripts"
{ scripts, ...}: {} |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-to-export-flake-nix-as-a-package/16227/4 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nixos-flakes-with-home-manager/18476/1 |
References: https://github.com/Baitinq/nixos-config/blob/39d8e9c9bcbac6d74a4ad0fded30d763194c1d6e/flake.nix https://github.com/jonringer/nixpkgs-config/blob/618496e858af54f1b6deab4747bded0e11c60204/flake.nix#L74 https://github.com/Misterio77/nix-starter-configs/blob/972935c1b35d8b92476e26b0e63a044d191d49c3/standard/flake.nix nix-community/home-manager#1698 (comment)
Issue description
Hi there! First off, thanks for the awesome library!
I'm currently trying to use flakes with home manager - however, I'm struggling to access a flake (output argument) in a home-manager module.
Example
Here's an example nix config
flake.nix
home.nix
Notes
builtins.getFlakeOutput desiredflake
)Meta
Maintainer CC
Technical details
The text was updated successfully, but these errors were encountered: