Adding a flake package to home-manager

I wanted to add GitHub - oxalica/nil: Language Server for Nix Expression Language to my home-manager config, and so I first tried to add it as a flake and add the flake to home.packages. However, that didn’t work, instead I had to manually add the packages.system.default bit.

Is there a nicer way? This is my home-manager flake, other comments welcome:

  description = "A Home Manager flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    nil.url = "github:oxalica/nil";
    nil.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, home-manager, nil, ... }:
      system = "x86_64-linux";
      username = "wmertens";
      homeDirectory = "/home/${username}";
      pkgs = import nixpkgs {
        overlays = [ self.overlays.default ];
      overlays.default = (final: prev: {
        wout-scripts = final.callPackage ./wout-scripts.nix { };
        google-chrome = { commandLineArgs = "--enable-features=TouchpadOverscrollHistoryNavigation"; };
      homeConfigurations = {
        wmertens = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [
              # home-manager config
              home = {
                inherit username homeDirectory;
                stateVersion = "22.05";
              home.packages = [ nil.packages.${system}.default ];


PS: Since nil will be in nixpkgs soon, this question is somewhat academic, for future reference.

No, there isn’t really a nicer way, though if you pass the flake inputs in with extraSpecialArgs you can avoid needing to do it in flake.nix and put it in home.nix instead.

1 Like

You could also use github:nobbz/nixos-config#nil, which is a “drop in” replacement for rnix-lsp.

It works for all nix lsp editor plugins which just try to lookup rnix-lsp in PATH.

1 Like

Question about your config, why do you use self.lib to call your own functions instead of using rec {} and calling lib directly? Is there a difference?

Mostly because I try to avoid rec in general.

The other reason is, that I can keep it roughly roughly the same through the config.

1 Like