mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
Prepare inclusion in nixos-search (#2971)
* Add flake.lock and clean up flake.nix Add a lockfile to work around https://github.com/NixOS/nix/issues/6541 (and because it's a good idea anyway). Also use flake-utils, and restrict ourselves to the five platforms supported by nixpkgs. Otherwise, the IFD for nmd fails on weird platforms. This fixes `nix flake check`. Remove the redundant `apps` output, see https://github.com/nix-community/home-manager/pull/2442#issuecomment-1133670487 * nixos,nix-darwin: factor out into a common module * nixos,nix-darwin: make `home-managers.users` shallowly visible Make sure the option is included in the NixOS/nix-darwin manual (but the HM submodule options aren't). Also add a static description to the HM submodule type so that we don't need to evaluate the submodules just to build the option manual. This makes nixos-search able to index the home-manager flake. Also clean up some TODOs. * flake: add nmd and nmt This avoids having to use `pkgs.fetchFromGitLab` in an IFD, which causes issues when indexing packages with nixos-search because `pkgs` is instantiated with every platform.
This commit is contained in:
parent
2070389247
commit
64ab7d6e8d
12 changed files with 354 additions and 347 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
||||||
/flake.lock
|
|
||||||
/result*
|
/result*
|
||||||
|
|
14
default.nix
14
default.nix
|
@ -1,6 +1,16 @@
|
||||||
{ pkgs ? import <nixpkgs> { } }:
|
{ pkgs ? import <nixpkgs> { } }:
|
||||||
|
|
||||||
rec {
|
let
|
||||||
|
|
||||||
|
flake = (import
|
||||||
|
(let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
|
in fetchTarball {
|
||||||
|
url =
|
||||||
|
"https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||||
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
|
}) { src = ./.; }).defaultNix;
|
||||||
|
|
||||||
|
in rec {
|
||||||
docs = with import ./docs { inherit pkgs; }; {
|
docs = with import ./docs { inherit pkgs; }; {
|
||||||
html = manual.html;
|
html = manual.html;
|
||||||
manPages = manPages;
|
manPages = manPages;
|
||||||
|
@ -16,4 +26,6 @@ rec {
|
||||||
nixos = import ./nixos;
|
nixos = import ./nixos;
|
||||||
|
|
||||||
path = ./.;
|
path = ./.;
|
||||||
|
|
||||||
|
inherit (flake) inputs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
{ pkgs
|
{ pkgs, nmdSrc ? (import ./.. { }).inputs.nmd
|
||||||
|
|
||||||
# Note, this should be "the standard library" + HM extensions.
|
# Note, this should be "the standard library" + HM extensions.
|
||||||
, lib ? import ../modules/lib/stdlib-extended.nix pkgs.lib }:
|
, lib ? import ../modules/lib/stdlib-extended.nix pkgs.lib }:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
nmdSrc = pkgs.fetchFromGitLab {
|
|
||||||
name = "nmd";
|
|
||||||
owner = "rycee";
|
|
||||||
repo = "nmd";
|
|
||||||
rev = "9e7a20e6ee3f6751f699f79c0b299390f81f7bcd";
|
|
||||||
sha256 = "1s49gjn1wapcjn0q4gabi8jwp8k5f18354a9c1vji0hfqsaknxzj";
|
|
||||||
};
|
|
||||||
|
|
||||||
nmd = import nmdSrc { inherit lib pkgs; };
|
nmd = import nmdSrc { inherit lib pkgs; };
|
||||||
|
|
||||||
# Make sure the used package is scrubbed to avoid actually
|
# Make sure the used package is scrubbed to avoid actually
|
||||||
|
|
94
flake.lock
Normal file
94
flake.lock
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-compat": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1650374568,
|
||||||
|
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1654230545,
|
||||||
|
"narHash": "sha256-8Vlwf0x8ow6pPOK2a04bT+pxIeRnM1+O0Xv9/CuDzRs=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "236cc2971ac72acd90f0ae3a797f9f83098b17ec",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nmd": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1653339422,
|
||||||
|
"narHash": "sha256-8nc7lcYOgih3YEmRMlBwZaLLJYpLPYKBlewqHqx8ieg=",
|
||||||
|
"owner": "rycee",
|
||||||
|
"repo": "nmd",
|
||||||
|
"rev": "9e7a20e6ee3f6751f699f79c0b299390f81f7bcd",
|
||||||
|
"type": "gitlab"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "rycee",
|
||||||
|
"repo": "nmd",
|
||||||
|
"type": "gitlab"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nmt": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1648075362,
|
||||||
|
"narHash": "sha256-u36WgzoA84dMVsGXzml4wZ5ckGgfnvS0ryzo/3zn/Pc=",
|
||||||
|
"owner": "rycee",
|
||||||
|
"repo": "nmt",
|
||||||
|
"rev": "d83601002c99b78c89ea80e5e6ba21addcfe12ae",
|
||||||
|
"type": "gitlab"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "rycee",
|
||||||
|
"repo": "nmt",
|
||||||
|
"type": "gitlab"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"nmd": "nmd",
|
||||||
|
"nmt": "nmt",
|
||||||
|
"utils": "utils"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1653893745,
|
||||||
|
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
75
flake.nix
75
flake.nix
|
@ -1,43 +1,31 @@
|
||||||
{
|
{
|
||||||
description = "Home Manager for Nix";
|
description = "Home Manager for Nix";
|
||||||
|
|
||||||
outputs = { self, nixpkgs }:
|
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
let
|
inputs.nmd.url = "gitlab:rycee/nmd";
|
||||||
# List of systems supported by home-manager binary
|
inputs.nmd.flake = false;
|
||||||
supportedSystems = with nixpkgs.lib.platforms; linux ++ darwin;
|
inputs.nmt.url = "gitlab:rycee/nmt";
|
||||||
|
inputs.nmt.flake = false;
|
||||||
|
|
||||||
# Function to generate a set based on supported systems
|
inputs.utils.url = "github:numtide/flake-utils";
|
||||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
inputs.flake-compat.url = "github:edolstra/flake-compat";
|
||||||
|
inputs.flake-compat.flake = false;
|
||||||
|
|
||||||
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
|
outputs = { self, nixpkgs, nmd, utils, ... }:
|
||||||
in rec {
|
{
|
||||||
nixosModules.home-manager = import ./nixos;
|
nixosModules = rec {
|
||||||
nixosModule = self.nixosModules.home-manager;
|
home-manager = import ./nixos;
|
||||||
|
default = home-manager;
|
||||||
|
};
|
||||||
|
# deprecated in Nix 2.8
|
||||||
|
nixosModule = self.nixosModules.default;
|
||||||
|
|
||||||
darwinModules.home-manager = import ./nix-darwin;
|
darwinModules = rec {
|
||||||
darwinModule = self.darwinModules.home-manager;
|
home-manager = import ./nix-darwin;
|
||||||
|
default = home-manager;
|
||||||
packages = forAllSystems (system:
|
};
|
||||||
let docs = import ./docs { pkgs = nixpkgsFor.${system}; };
|
# unofficial; deprecated in Nix 2.8
|
||||||
in {
|
darwinModule = self.darwinModules.default;
|
||||||
home-manager = nixpkgsFor.${system}.callPackage ./home-manager { };
|
|
||||||
docs-html = docs.manual.html;
|
|
||||||
docs-manpages = docs.manPages;
|
|
||||||
docs-json = docs.options.json;
|
|
||||||
default = self.packages.${system}.home-manager;
|
|
||||||
});
|
|
||||||
|
|
||||||
# defaultPackage is deprecated as of Nix 2.7.0
|
|
||||||
defaultPackage = forAllSystems (system: self.packages.${system}.default);
|
|
||||||
|
|
||||||
apps = forAllSystems (system: {
|
|
||||||
home-manager = {
|
|
||||||
type = "app";
|
|
||||||
program = "${defaultPackage.${system}}/bin/home-manager";
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
defaultApp = forAllSystems (system: apps.${system}.home-manager);
|
|
||||||
|
|
||||||
lib = {
|
lib = {
|
||||||
hm = import ./modules/lib { lib = nixpkgs.lib; };
|
hm = import ./modules/lib { lib = nixpkgs.lib; };
|
||||||
|
@ -56,5 +44,22 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
} // utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
docs = import ./docs {
|
||||||
|
inherit pkgs;
|
||||||
|
nmdSrc = nmd;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
packages = rec {
|
||||||
|
home-manager = pkgs.callPackage ./home-manager { };
|
||||||
|
docs-html = docs.manual.html;
|
||||||
|
docs-manpages = docs.manPages;
|
||||||
|
docs-json = docs.options.json;
|
||||||
|
default = home-manager;
|
||||||
|
};
|
||||||
|
# deprecated in Nix 2.7
|
||||||
|
defaultPackage = self.packages.${system}.default;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
1
format
1
format
|
@ -27,6 +27,5 @@ find . -name '*.nix' \
|
||||||
! -path ./modules/programs/bash.nix \
|
! -path ./modules/programs/bash.nix \
|
||||||
! -path ./modules/programs/ssh.nix \
|
! -path ./modules/programs/ssh.nix \
|
||||||
! -path ./modules/programs/zsh.nix \
|
! -path ./modules/programs/zsh.nix \
|
||||||
! -path ./nix-darwin/default.nix \
|
|
||||||
! -path ./tests/default.nix \
|
! -path ./tests/default.nix \
|
||||||
-exec nixfmt $CHECK_ARG {} +
|
-exec nixfmt $CHECK_ARG {} +
|
||||||
|
|
|
@ -19,6 +19,7 @@ in runCommand "home-manager" {
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
nativeBuildInputs = [ gettext ];
|
nativeBuildInputs = [ gettext ];
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
|
mainProgram = "home-manager";
|
||||||
description = "A user environment configurator";
|
description = "A user environment configurator";
|
||||||
maintainers = [ maintainers.rycee ];
|
maintainers = [ maintainers.rycee ];
|
||||||
platforms = platforms.unix;
|
platforms = platforms.unix;
|
||||||
|
|
124
integration-common.nix
Normal file
124
integration-common.nix
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
# This module is the common base for the NixOS and nix-darwin modules.
|
||||||
|
# For OS-specific configuration, please edit nixos/default.nix or nix-darwin/default.nix instead.
|
||||||
|
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
cfg = config.home-manager;
|
||||||
|
|
||||||
|
extendedLib = import ./modules/lib/stdlib-extended.nix pkgs.lib;
|
||||||
|
|
||||||
|
hmModule' = types.submoduleWith {
|
||||||
|
specialArgs = {
|
||||||
|
lib = extendedLib;
|
||||||
|
osConfig = config;
|
||||||
|
modulesPath = builtins.toString ./modules;
|
||||||
|
} // cfg.extraSpecialArgs;
|
||||||
|
modules = [
|
||||||
|
({ name, ... }: {
|
||||||
|
imports = import ./modules/modules.nix {
|
||||||
|
inherit pkgs;
|
||||||
|
lib = extendedLib;
|
||||||
|
useNixpkgsModule = !cfg.useGlobalPkgs;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
submoduleSupport.enable = true;
|
||||||
|
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
||||||
|
|
||||||
|
home.username = config.users.users.${name}.name;
|
||||||
|
home.homeDirectory = config.users.users.${name}.home;
|
||||||
|
|
||||||
|
# Make activation script use same version of Nix as system as a whole.
|
||||||
|
# This avoids problems with Nix not being in PATH.
|
||||||
|
home.extraActivationPath = [ config.nix.package ];
|
||||||
|
};
|
||||||
|
})
|
||||||
|
] ++ cfg.sharedModules;
|
||||||
|
} // {
|
||||||
|
description = "Home Manager module";
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: hack until https://github.com/NixOS/nixpkgs/pull/173621 lands
|
||||||
|
hmModule = hmModule' // {
|
||||||
|
substSubModules = m:
|
||||||
|
hmModule'.substSubModules m // {
|
||||||
|
inherit (hmModule') description;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
in {
|
||||||
|
options.home-manager = {
|
||||||
|
useUserPackages = mkEnableOption ''
|
||||||
|
installation of user packages through the
|
||||||
|
<option>users.users.<name>.packages</option> option
|
||||||
|
'';
|
||||||
|
|
||||||
|
useGlobalPkgs = mkEnableOption ''
|
||||||
|
using the system configuration's <literal>pkgs</literal>
|
||||||
|
argument in Home Manager. This disables the Home Manager
|
||||||
|
options <option>nixpkgs.*</option>
|
||||||
|
'';
|
||||||
|
|
||||||
|
backupFileExtension = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
example = "backup";
|
||||||
|
description = ''
|
||||||
|
On activation move existing files by appending the given
|
||||||
|
file extension rather than exiting with an error.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
extraSpecialArgs = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
default = { };
|
||||||
|
example = literalExpression "{ inherit emacs-overlay; }";
|
||||||
|
description = ''
|
||||||
|
Extra <literal>specialArgs</literal> passed to Home Manager. This
|
||||||
|
option can be used to pass additional arguments to all modules.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
sharedModules = mkOption {
|
||||||
|
type = with types; listOf raw;
|
||||||
|
default = [ ];
|
||||||
|
example = literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
|
||||||
|
description = ''
|
||||||
|
Extra modules added to all users.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
verbose = mkEnableOption "verbose output on activation";
|
||||||
|
|
||||||
|
users = mkOption {
|
||||||
|
type = types.attrsOf hmModule;
|
||||||
|
default = { };
|
||||||
|
# Prevent the entire submodule being included in the documentation.
|
||||||
|
visible = "shallow";
|
||||||
|
description = ''
|
||||||
|
Per-user Home Manager configuration.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf (cfg.users != { }) {
|
||||||
|
warnings = flatten (flip mapAttrsToList cfg.users (user: config:
|
||||||
|
flip map config.warnings (warning: "${user} profile: ${warning}")));
|
||||||
|
|
||||||
|
assertions = flatten (flip mapAttrsToList cfg.users (user: config:
|
||||||
|
flip map config.assertions (assertion: {
|
||||||
|
inherit (assertion) assertion;
|
||||||
|
message = "${user} profile: ${assertion.message}";
|
||||||
|
})));
|
||||||
|
|
||||||
|
users.users = mkIf cfg.useUserPackages
|
||||||
|
(mapAttrs (username: usercfg: { packages = [ usercfg.home.path ]; })
|
||||||
|
cfg.users);
|
||||||
|
|
||||||
|
environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
|
||||||
|
};
|
||||||
|
}
|
|
@ -152,7 +152,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
# Required for the assertions
|
# Required for the assertions
|
||||||
# TODO: Remove me once `mkRemovedOptionModule` works correctly with submodules
|
# TODO: Remove me once https://github.com/NixOS/nixpkgs/issues/96006 is fixed
|
||||||
assertions = mkOption {
|
assertions = mkOption {
|
||||||
type = types.listOf types.unspecified;
|
type = types.listOf types.unspecified;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
|
|
|
@ -6,140 +6,26 @@ let
|
||||||
|
|
||||||
cfg = config.home-manager;
|
cfg = config.home-manager;
|
||||||
|
|
||||||
extendedLib = import ../modules/lib/stdlib-extended.nix pkgs.lib;
|
in {
|
||||||
|
imports = [ ../integration-common.nix ];
|
||||||
|
|
||||||
hmModule = types.submoduleWith {
|
config = mkMerge [
|
||||||
specialArgs = {
|
{ home-manager.extraSpecialArgs.darwinConfig = config; }
|
||||||
lib = extendedLib;
|
(mkIf (cfg.users != { }) {
|
||||||
darwinConfig = config;
|
system.activationScripts.postActivation.text = concatStringsSep "\n"
|
||||||
osConfig = config;
|
(mapAttrsToList (username: usercfg: ''
|
||||||
modulesPath = builtins.toString ../modules;
|
echo Activating home-manager configuration for ${username}
|
||||||
} // cfg.extraSpecialArgs;
|
sudo -u ${username} -s --set-home ${
|
||||||
modules = [
|
pkgs.writeShellScript "activation-${username}" ''
|
||||||
({ name, ... }: {
|
${lib.optionalString (cfg.backupFileExtension != null)
|
||||||
imports = import ../modules/modules.nix {
|
"export HOME_MANAGER_BACKUP_EXT=${
|
||||||
inherit pkgs;
|
lib.escapeShellArg cfg.backupFileExtension
|
||||||
lib = extendedLib;
|
}"}
|
||||||
useNixpkgsModule = !cfg.useGlobalPkgs;
|
${lib.optionalString cfg.verbose "export VERBOSE=1"}
|
||||||
};
|
exec ${usercfg.home.activationPackage}/activate
|
||||||
|
''
|
||||||
config = {
|
|
||||||
submoduleSupport.enable = true;
|
|
||||||
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
|
||||||
|
|
||||||
home.username = config.users.users.${name}.name;
|
|
||||||
home.homeDirectory = config.users.users.${name}.home;
|
|
||||||
|
|
||||||
# Make activation script use same version of Nix as system as a whole.
|
|
||||||
# This avoids problems with Nix not being in PATH.
|
|
||||||
home.extraActivationPath = [ config.nix.package ];
|
|
||||||
};
|
|
||||||
})
|
|
||||||
] ++ cfg.sharedModules;
|
|
||||||
};
|
|
||||||
|
|
||||||
in
|
|
||||||
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
home-manager = {
|
|
||||||
useUserPackages = mkEnableOption ''
|
|
||||||
installation of user packages through the
|
|
||||||
<option>users.users.<name?>.packages</option> option.
|
|
||||||
'';
|
|
||||||
|
|
||||||
useGlobalPkgs = mkEnableOption ''
|
|
||||||
using the system configuration's <literal>pkgs</literal>
|
|
||||||
argument in Home Manager. This disables the Home Manager
|
|
||||||
options <option>nixpkgs.*</option>
|
|
||||||
'';
|
|
||||||
|
|
||||||
backupFileExtension = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
example = "backup";
|
|
||||||
description = ''
|
|
||||||
On activation move existing files by appending the given
|
|
||||||
file extension rather than exiting with an error.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
extraSpecialArgs = mkOption {
|
|
||||||
type = types.attrs;
|
|
||||||
default = { };
|
|
||||||
example = literalExpression "{ inherit emacs-overlay; }";
|
|
||||||
description = ''
|
|
||||||
Extra <literal>specialArgs</literal> passed to Home Manager. This
|
|
||||||
option can be used to pass additional arguments to all modules.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
sharedModules = mkOption {
|
|
||||||
type = with types;
|
|
||||||
# TODO: use types.raw once this PR is merged: https://github.com/NixOS/nixpkgs/pull/132448
|
|
||||||
listOf (mkOptionType {
|
|
||||||
name = "submodule";
|
|
||||||
inherit (submodule { }) check;
|
|
||||||
merge = lib.options.mergeOneOption;
|
|
||||||
description = "Home Manager modules";
|
|
||||||
});
|
|
||||||
default = [ ];
|
|
||||||
example = literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
|
|
||||||
description = ''
|
|
||||||
Extra modules added to all users.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
verbose = mkEnableOption "verbose output on activation";
|
|
||||||
|
|
||||||
users = mkOption {
|
|
||||||
type = types.attrsOf hmModule;
|
|
||||||
default = {};
|
|
||||||
# Set as not visible to prevent the entire submodule being included in
|
|
||||||
# the documentation.
|
|
||||||
visible = false;
|
|
||||||
description = ''
|
|
||||||
Per-user Home Manager configuration.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf (cfg.users != {}) {
|
|
||||||
warnings =
|
|
||||||
flatten (flip mapAttrsToList cfg.users (user: config:
|
|
||||||
flip map config.warnings (warning:
|
|
||||||
"${user} profile: ${warning}"
|
|
||||||
)
|
|
||||||
));
|
|
||||||
|
|
||||||
assertions =
|
|
||||||
flatten (flip mapAttrsToList cfg.users (user: config:
|
|
||||||
flip map config.assertions (assertion:
|
|
||||||
{
|
|
||||||
inherit (assertion) assertion;
|
|
||||||
message = "${user} profile: ${assertion.message}";
|
|
||||||
}
|
}
|
||||||
)
|
'') cfg.users);
|
||||||
));
|
})
|
||||||
|
];
|
||||||
users.users = mkIf cfg.useUserPackages (
|
|
||||||
mapAttrs (username: usercfg: {
|
|
||||||
packages = [ usercfg.home.path ];
|
|
||||||
}) cfg.users
|
|
||||||
);
|
|
||||||
|
|
||||||
environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
|
|
||||||
|
|
||||||
system.activationScripts.postActivation.text =
|
|
||||||
concatStringsSep "\n" (mapAttrsToList (username: usercfg: ''
|
|
||||||
echo Activating home-manager configuration for ${username}
|
|
||||||
sudo -u ${username} -s --set-home ${pkgs.writeShellScript "activation-${username}" ''
|
|
||||||
${lib.optionalString (cfg.backupFileExtension != null)
|
|
||||||
"export HOME_MANAGER_BACKUP_EXT=${lib.escapeShellArg cfg.backupFileExtension}"}
|
|
||||||
${lib.optionalString cfg.verbose "export VERBOSE=1"}
|
|
||||||
exec ${usercfg.home.activationPackage}/activate
|
|
||||||
''}
|
|
||||||
'') cfg.users);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,180 +6,80 @@ let
|
||||||
|
|
||||||
cfg = config.home-manager;
|
cfg = config.home-manager;
|
||||||
|
|
||||||
extendedLib = import ../modules/lib/stdlib-extended.nix pkgs.lib;
|
|
||||||
|
|
||||||
hmModule = types.submoduleWith {
|
|
||||||
specialArgs = {
|
|
||||||
lib = extendedLib;
|
|
||||||
nixosConfig = config;
|
|
||||||
osConfig = config;
|
|
||||||
modulesPath = builtins.toString ../modules;
|
|
||||||
} // cfg.extraSpecialArgs;
|
|
||||||
modules = [
|
|
||||||
({ name, ... }: {
|
|
||||||
imports = import ../modules/modules.nix {
|
|
||||||
inherit pkgs;
|
|
||||||
lib = extendedLib;
|
|
||||||
useNixpkgsModule = !cfg.useGlobalPkgs;
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
|
||||||
submoduleSupport.enable = true;
|
|
||||||
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
|
||||||
|
|
||||||
# The per-user directory inside /etc/profiles is not known by
|
|
||||||
# fontconfig by default.
|
|
||||||
fonts.fontconfig.enable = cfg.useUserPackages
|
|
||||||
&& config.fonts.fontconfig.enable;
|
|
||||||
|
|
||||||
home.username = config.users.users.${name}.name;
|
|
||||||
home.homeDirectory = config.users.users.${name}.home;
|
|
||||||
|
|
||||||
# Make activation script use same version of Nix as system as a whole.
|
|
||||||
# This avoids problems with Nix not being in PATH.
|
|
||||||
home.extraActivationPath = [ config.nix.package ];
|
|
||||||
};
|
|
||||||
})
|
|
||||||
] ++ cfg.sharedModules;
|
|
||||||
};
|
|
||||||
|
|
||||||
serviceEnvironment = optionalAttrs (cfg.backupFileExtension != null) {
|
serviceEnvironment = optionalAttrs (cfg.backupFileExtension != null) {
|
||||||
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
|
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
|
||||||
} // optionalAttrs cfg.verbose { VERBOSE = "1"; };
|
} // optionalAttrs cfg.verbose { VERBOSE = "1"; };
|
||||||
|
|
||||||
in {
|
in {
|
||||||
options = {
|
imports = [ ../integration-common.nix ];
|
||||||
home-manager = {
|
|
||||||
useUserPackages = mkEnableOption ''
|
|
||||||
installation of user packages through the
|
|
||||||
<option>users.users.<name>.packages</option> option
|
|
||||||
'';
|
|
||||||
|
|
||||||
useGlobalPkgs = mkEnableOption ''
|
config = mkMerge [
|
||||||
using the system configuration's <literal>pkgs</literal>
|
{
|
||||||
argument in Home Manager. This disables the Home Manager
|
home-manager = {
|
||||||
options <option>nixpkgs.*</option>
|
extraSpecialArgs.nixosConfig = config;
|
||||||
'';
|
|
||||||
|
|
||||||
backupFileExtension = mkOption {
|
sharedModules = [{
|
||||||
type = types.nullOr types.str;
|
# The per-user directory inside /etc/profiles is not known by
|
||||||
default = null;
|
# fontconfig by default.
|
||||||
example = "backup";
|
fonts.fontconfig.enable = cfg.useUserPackages
|
||||||
description = ''
|
&& config.fonts.fontconfig.enable;
|
||||||
On activation move existing files by appending the given
|
}];
|
||||||
file extension rather than exiting with an error.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
(mkIf (cfg.users != { }) {
|
||||||
|
systemd.services = mapAttrs' (_: usercfg:
|
||||||
|
let username = usercfg.home.username;
|
||||||
|
in nameValuePair ("home-manager-${utils.escapeSystemdPath username}") {
|
||||||
|
description = "Home Manager environment for ${username}";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
wants = [ "nix-daemon.socket" ];
|
||||||
|
after = [ "nix-daemon.socket" ];
|
||||||
|
before = [ "systemd-user-sessions.service" ];
|
||||||
|
|
||||||
extraSpecialArgs = mkOption {
|
environment = serviceEnvironment;
|
||||||
type = types.attrs;
|
|
||||||
default = { };
|
|
||||||
example = literalExpression "{ inherit emacs-overlay; }";
|
|
||||||
description = ''
|
|
||||||
Extra <literal>specialArgs</literal> passed to Home Manager. This
|
|
||||||
option can be used to pass additional arguments to all modules.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
sharedModules = mkOption {
|
unitConfig = { RequiresMountsFor = usercfg.home.homeDirectory; };
|
||||||
type = with types;
|
|
||||||
# TODO: use types.raw once this PR is merged: https://github.com/NixOS/nixpkgs/pull/132448
|
|
||||||
listOf (mkOptionType {
|
|
||||||
name = "submodule";
|
|
||||||
inherit (submodule { }) check;
|
|
||||||
merge = lib.options.mergeOneOption;
|
|
||||||
description = "Home Manager modules";
|
|
||||||
});
|
|
||||||
default = [ ];
|
|
||||||
example = literalExpression "[ { home.packages = [ nixpkgs-fmt ]; } ]";
|
|
||||||
description = ''
|
|
||||||
Extra modules added to all users.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
verbose = mkEnableOption "verbose output on activation";
|
stopIfChanged = false;
|
||||||
|
|
||||||
users = mkOption {
|
serviceConfig = {
|
||||||
type = types.attrsOf hmModule;
|
User = usercfg.home.username;
|
||||||
default = { };
|
Type = "oneshot";
|
||||||
# Set as not visible to prevent the entire submodule being included in
|
RemainAfterExit = "yes";
|
||||||
# the documentation.
|
TimeoutStartSec = 90;
|
||||||
visible = false;
|
SyslogIdentifier = "hm-activate-${username}";
|
||||||
description = ''
|
|
||||||
Per-user Home Manager configuration.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf (cfg.users != { }) {
|
ExecStart = let
|
||||||
warnings = flatten (flip mapAttrsToList cfg.users (user: config:
|
systemctl =
|
||||||
flip map config.warnings (warning: "${user} profile: ${warning}")));
|
"XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$UID} systemctl";
|
||||||
|
|
||||||
assertions = flatten (flip mapAttrsToList cfg.users (user: config:
|
sed = "${pkgs.gnused}/bin/sed";
|
||||||
flip map config.assertions (assertion: {
|
|
||||||
inherit (assertion) assertion;
|
|
||||||
message = "${user} profile: ${assertion.message}";
|
|
||||||
})));
|
|
||||||
|
|
||||||
users.users = mkIf cfg.useUserPackages
|
exportedSystemdVariables = concatStringsSep "|" [
|
||||||
(mapAttrs (username: usercfg: { packages = [ usercfg.home.path ]; })
|
"DBUS_SESSION_BUS_ADDRESS"
|
||||||
cfg.users);
|
"DISPLAY"
|
||||||
|
"WAYLAND_DISPLAY"
|
||||||
|
"XAUTHORITY"
|
||||||
|
"XDG_RUNTIME_DIR"
|
||||||
|
];
|
||||||
|
|
||||||
environment.pathsToLink = mkIf cfg.useUserPackages [ "/etc/profile.d" ];
|
setupEnv = pkgs.writeScript "hm-setup-env" ''
|
||||||
|
#! ${pkgs.runtimeShell} -el
|
||||||
|
|
||||||
systemd.services = mapAttrs' (_: usercfg:
|
# The activation script is run by a login shell to make sure
|
||||||
let username = usercfg.home.username;
|
# that the user is given a sane environment.
|
||||||
in nameValuePair ("home-manager-${utils.escapeSystemdPath username}") {
|
# If the user is logged in, import variables from their current
|
||||||
description = "Home Manager environment for ${username}";
|
# session environment.
|
||||||
wantedBy = [ "multi-user.target" ];
|
eval "$(
|
||||||
wants = [ "nix-daemon.socket" ];
|
${systemctl} --user show-environment 2> /dev/null \
|
||||||
after = [ "nix-daemon.socket" ];
|
| ${sed} -En '/^(${exportedSystemdVariables})=/s/^/export /p'
|
||||||
before = [ "systemd-user-sessions.service" ];
|
)"
|
||||||
|
|
||||||
environment = serviceEnvironment;
|
exec "$1/activate"
|
||||||
|
'';
|
||||||
unitConfig = { RequiresMountsFor = usercfg.home.homeDirectory; };
|
in "${setupEnv} ${usercfg.home.activationPackage}";
|
||||||
|
};
|
||||||
stopIfChanged = false;
|
}) cfg.users;
|
||||||
|
})
|
||||||
serviceConfig = {
|
];
|
||||||
User = usercfg.home.username;
|
|
||||||
Type = "oneshot";
|
|
||||||
RemainAfterExit = "yes";
|
|
||||||
TimeoutStartSec = 90;
|
|
||||||
SyslogIdentifier = "hm-activate-${username}";
|
|
||||||
|
|
||||||
ExecStart = let
|
|
||||||
systemctl =
|
|
||||||
"XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$UID} systemctl";
|
|
||||||
|
|
||||||
sed = "${pkgs.gnused}/bin/sed";
|
|
||||||
|
|
||||||
exportedSystemdVariables = concatStringsSep "|" [
|
|
||||||
"DBUS_SESSION_BUS_ADDRESS"
|
|
||||||
"DISPLAY"
|
|
||||||
"WAYLAND_DISPLAY"
|
|
||||||
"XAUTHORITY"
|
|
||||||
"XDG_RUNTIME_DIR"
|
|
||||||
];
|
|
||||||
|
|
||||||
setupEnv = pkgs.writeScript "hm-setup-env" ''
|
|
||||||
#! ${pkgs.runtimeShell} -el
|
|
||||||
|
|
||||||
# The activation script is run by a login shell to make sure
|
|
||||||
# that the user is given a sane environment.
|
|
||||||
# If the user is logged in, import variables from their current
|
|
||||||
# session environment.
|
|
||||||
eval "$(
|
|
||||||
${systemctl} --user show-environment 2> /dev/null \
|
|
||||||
| ${sed} -En '/^(${exportedSystemdVariables})=/s/^/export /p'
|
|
||||||
)"
|
|
||||||
|
|
||||||
exec "$1/activate"
|
|
||||||
'';
|
|
||||||
in "${setupEnv} ${usercfg.home.activationPackage}";
|
|
||||||
};
|
|
||||||
}) cfg.users;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,7 @@ let
|
||||||
|
|
||||||
lib = import ../modules/lib/stdlib-extended.nix pkgs.lib;
|
lib = import ../modules/lib/stdlib-extended.nix pkgs.lib;
|
||||||
|
|
||||||
nmt = pkgs.fetchFromGitLab {
|
inherit ((import ./.. { }).inputs) nmt;
|
||||||
owner = "rycee";
|
|
||||||
repo = "nmt";
|
|
||||||
rev = "d83601002c99b78c89ea80e5e6ba21addcfe12ae";
|
|
||||||
sha256 = "1xzwwxygzs1cmysg97hzd285r7n1g1lwx5y1ar68gwq07a1rczmv";
|
|
||||||
};
|
|
||||||
|
|
||||||
modules = import ../modules/modules.nix {
|
modules = import ../modules/modules.nix {
|
||||||
inherit lib pkgs;
|
inherit lib pkgs;
|
||||||
|
|
Loading…
Reference in a new issue