Improving a flake.nix config that configures home-manager

So to answer the questions 1 and 3, sure. You just need to repeat execpermfix in the input ando output function, the other ones can be removed. extraSpecialArgs is only useful in you load a module from another file. Here since the variable is defined above in the file (or closure to be more precise) you can just refer to it without using any variable. And for 3, yes, just do it :stuck_out_tongue: This way you can simplify the above file like this (not tested):

{
  description = "Home Manager config";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    execpermfix.url = "github:lpenz/execpermfix";
  };

  outputs = { nixpkgs, home-manager, execpermfix, ... }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};      
    in {
      homeConfigurations.myuser = home-manager.lib.homeManagerConfiguration {
        modules = [
          {
            home.username = "myuser";
            home.homeDirectory = "/home/myuser";
            home.stateVersion = "22.11";
            programs.home-manager.enable = true;
            home.packages = [
              execpermfix.packages.${system}.default
            ];
          }
        ];
      };
    };
}

Regarding the second question, you cannot directly make the homeConfiguration system-agnostic as pointed out in this issue. However, you can ‘fake it’ by creating a loop to create an entry myuser-${system} for instance. This flake makes it particularly easy to do by providing a list of systems. So your code would become like this (not tested, I hope I don’t have too much typos):

{
  description = "Home Manager config";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    execpermfix.url = "github:lpenz/execpermfix";
  };

  outputs = { nixpkgs, home-manager, execpermfix, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in
        {
          homeConfigurations."myuser-${system}" = home-manager.lib.homeManagerConfiguration {
            modules = [
              {
                home.username = "myuser";
                home.homeDirectory = "/home/myuser";
                home.stateVersion = "22.11";
                programs.home-manager.enable = true;
                home.packages = [
                  execpermfix.packages.${system}.default
                ];
              }
            ];
          };
        });
}

and you should be able to switch using something like

$ home-manager switch --flake .#myuser-x86_64-linux

Until the above issue is resolved I don’t think we can get a much better solution (at most you can also certainly write .#x86_64-linux.myuser if you prefer a doc by modifying accordingly homeConfigurations.${system}.myuser). Note that I can’t test this right now but I see no reasons for a failure except minor typos.

2 Likes