CDN
August 27, 2024, 3:44am
1
Hello everyone, I’m having trouble using NUR in my NixOS configuration after introducing it in my flake.nix
. Here’s my setup:
flake.nix
{
inputs {
nur.url = "github:nix-community/NUR";
...
};
outputs = { self, nixpkgs, home-manager, nur, ... }@inputs: {
nixosConfigurations.default = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs nur;
};
modules = [
./hosts/default/configuration.nix
];
};
};
}
configuration.nix
{ pkgs, lib, inputs, nur, ... }:
{
environment.systemPackages = with pkgs; [
nur.repos.mic92.hello-nur
...
];
}
When I try to rebuild, I get the error: attribute 'repos' missing
. Any insights on what might be going wrong?
Using NUR with flakes is silly, NUR was intended for people who don’t use flakes.
Just use the direct upstream flake itself! In this case - GitHub - Mic92/nur-packages: My personal NUR repository
And the full list of repos is at NUR/repos.json at d39c7ced498d546513270b314d682ac5d7de734d · nix-community/NUR · GitHub
3 Likes
CDN
August 27, 2024, 1:36pm
3
Oh! I just started with NixOS a few days ago and didn’t realize that. Do you mean to use the upstream flake as an input, like this:
flake.nix
{
inputs {
# nur.url = "github:nix-community/NUR";
mic92.url = "github:Mic92/nur-packages";
...
};
}
Is this the correct approach? Also, how should I export these packages so that I can use them in both my NixOS configuration and Home Manager? (I tried to find some templates on GitHub for direct usage, but their output sections were quite complex, and I’m having trouble figuring out which parts to use.)
Yes, since the upstream repo has a flake.nix, that makes it a flake, so you can use it as an input directly.
Then you can use whichever packages, modules, etc. from that flake input.
1 Like
CDN
August 27, 2024, 4:46pm
5
Thanks very much, @waffle8946 ! Now I understand how to do it.
However, I still don’t quite understand why using upstream flakes directly is better than using NUR in flakes. If you don’t mind, could you briefly explain why?
CDN
August 27, 2024, 4:56pm
6
If anyone stumbles upon this post and wants to know how to do it, here is my configuration:
flake.nix
{
...
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
mic92.url = "github:Mic92/nur-packages";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, home-manager, mic92, ... }@inputs: {
nixosConfigurations.default = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs;
};
modules = [
./hosts/default/configuration.nix
...
configuration.nix
{ pkgs, lib, inputs, config, ... }:
{
home-manager = {
useGlobalPkgs = true;
extraSpecialArgs = { inherit pkgs inputs; };
users = {
"username" = import ./home.nix;
};
};
environment.systemPackages = with pkgs; [
inputs.mic92.packages.x86_64-linux.hello-nur
...
home.nix
{ pkgs, inputs, config, ... }:
{
home.packages = with pkgs; [
inputs.mic92.packages.x86_64-linux.hello-nur
...
This way, you can use packages from another flake in both your NixOS configuration and Home Manager. Although, this configuration almost certainly has some unwise parts (like I should probably move x86_64-linux
to flake.nix
).
CDN
August 27, 2024, 5:12pm
7
Additionally, if anyone insists on integrating NUR with flakes, you can try the following configurations:
Method 1: Adding an overlay upon nixpkgs
flake.nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nur.url = "github:nix-community/NUR";
};
outputs = { self, nixpkgs, home-manager, nur, ... }@inputs: {
nixosConfigurations.default = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs;
};
modules = [
./hosts/default/configuration.nix
nixpkgs.overlays = [ nur.overlay ];
];
};
};
}
configuration.nix
{
home-manager = {
useGlobalPkgs = true;
extraSpecialArgs = { inherit pkgs; };
users = {
"username" = import ./home.nix;
};
};
environment.systemPackages = with pkgs; [
nur.repos.mic92.hello-nur
];
}
In home.nix
under home.packages
, you can also use nur.repos.mic92.hello-nur
.
Method 2: Directly passing the inputs (similar to using upstream flakes directly)
flake.nix
{
outputs = { self, nixpkgs, home-manager, nur, ... }@inputs: {
nixosConfigurations.default = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs;
};
modules = [
./hosts/default/configuration.nix
];
};
};
}
configuration.nix
{
home-manager = {
useGlobalPkgs = true;
extraSpecialArgs = { inherit pkgs inputs; };
users = {
"username" = import ./home.nix;
};
};
environment.systemPackages = with pkgs; [
config.nur.repos.mic92.hello-nur
];
}
home.nix
{
home.packages = with pkgs; [
osConfig.nur.repos.mic92.hello-nur
];
}
I haven’t figured out the differences between them yet, but they both seem to work…