fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
4.2 KiB134 linesraw
1# Adapted from Nixpkgs.
2
3{ config, lib, pkgs, pkgsPath, ... }:
4
5with lib;
6
7let
8
9  isConfig = x: builtins.isAttrs x || builtins.isFunction x;
10
11  optCall = f: x: if builtins.isFunction f then f x else f;
12
13  mergeConfig = lhs_: rhs_:
14    let
15      lhs = optCall lhs_ { inherit pkgs; };
16      rhs = optCall rhs_ { inherit pkgs; };
17    in lhs // rhs // optionalAttrs (lhs ? packageOverrides) {
18      packageOverrides = pkgs:
19        optCall lhs.packageOverrides pkgs
20        // optCall (attrByPath [ "packageOverrides" ] ({ }) rhs) pkgs;
21    } // optionalAttrs (lhs ? perlPackageOverrides) {
22      perlPackageOverrides = pkgs:
23        optCall lhs.perlPackageOverrides pkgs
24        // optCall (attrByPath [ "perlPackageOverrides" ] ({ }) rhs) pkgs;
25    };
26
27  configType = mkOptionType {
28    name = "nixpkgs-config";
29    description = "nixpkgs config";
30    check = x:
31      let traceXIfNot = c: if c x then true else lib.traceSeqN 1 x false;
32      in traceXIfNot isConfig;
33    merge = args: fold (def: mergeConfig def.value) { };
34  };
35
36  overlayType = mkOptionType {
37    name = "nixpkgs-overlay";
38    description = "nixpkgs overlay";
39    check = builtins.isFunction;
40    merge = lib.mergeOneOption;
41  };
42
43  _pkgs = import pkgsPath (filterAttrs (n: v: v != null) config.nixpkgs);
44
45in {
46  options.nixpkgs = {
47    config = mkOption {
48      default = null;
49      example = { allowBroken = true; };
50      type = types.nullOr configType;
51      description = ''
52        The configuration of the Nix Packages collection. (For
53        details, see the Nixpkgs documentation.) It allows you to set
54        package configuration options.
55
56        If `null`, then configuration is taken from
57        the fallback location, for example,
58        {file}`~/.config/nixpkgs/config.nix`.
59
60        Note, this option will not apply outside your Home Manager
61        configuration like when installing manually through
62        {command}`nix-env`. If you want to apply it both
63        inside and outside Home Manager you can put it in a separate
64        file and include something like
65
66        ```nix
67          nixpkgs.config = import ./nixpkgs-config.nix;
68          xdg.configFile."nixpkgs/config.nix".source = ./nixpkgs-config.nix;
69        ```
70
71        in your Home Manager configuration.
72      '';
73    };
74
75    overlays = mkOption {
76      default = null;
77      example = literalExpression ''
78        [
79          (final: prev: {
80            openssh = prev.openssh.override {
81              hpnSupport = true;
82              withKerberos = true;
83              kerberos = final.libkrb5;
84            };
85          })
86        ]
87      '';
88      type = types.nullOr (types.listOf overlayType);
89      description = ''
90        List of overlays to use with the Nix Packages collection. (For
91        details, see the Nixpkgs documentation.) It allows you to
92        override packages globally. This is a function that takes as
93        an argument the *original* Nixpkgs. The
94        first argument should be used for finding dependencies, and
95        the second should be used for overriding recipes.
96
97        If `null`, then the overlays are taken from
98        the fallback location, for example,
99        {file}`~/.config/nixpkgs/overlays`.
100
101        Like {var}`nixpkgs.config` this option only
102        applies within the Home Manager configuration. See
103        {var}`nixpkgs.config` for a suggested setup that
104        works both internally and externally.
105      '';
106    };
107
108    system = mkOption {
109      type = types.str;
110      example = "i686-linux";
111      internal = true;
112      description = ''
113        Specifies the Nix platform type for which the user environment
114        should be built. If unset, it defaults to the platform type of
115        your host system. Specifying this option is useful when doing
116        distributed multi-platform deployment, or when building
117        virtual machines.
118      '';
119    };
120  };
121
122  config = {
123    _module.args = {
124      # We use a no-op override to make sure that the option can be merged without evaluating
125      # `_pkgs`, see https://github.com/nix-community/home-manager/pull/993
126      pkgs = mkOverride modules.defaultOverridePriority _pkgs;
127      pkgs_i686 =
128        if _pkgs.stdenv.isLinux && _pkgs.stdenv.hostPlatform.isx86 then
129          _pkgs.pkgsi686Linux
130        else
131          { };
132    };
133  };
134}