diff --git a/docs/default.nix b/docs/default.nix index 3df0cf6..d64a8d5 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2023, see AUTHORS. Licensed under MIT License, see LICENSE. -{ pkgs, home-manager, nmdSrc }: +{ pkgs, nixpkgs, home-manager, nmdSrc }: let nmd = import nmdSrc { inherit pkgs; }; @@ -14,7 +14,7 @@ let }; modules = import ../modules/module-list.nix { - inherit pkgs; + inherit pkgs nixpkgs; home-manager-path = home-manager.outPath; isFlake = true; }; diff --git a/flake.nix b/flake.nix index d2e0e66..aae0f05 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,7 @@ }; }; - outputs = { self, nixpkgs, nixpkgs-for-bootstrap, home-manager, nix-formatter-pack, nmd }: + outputs = { self, nixpkgs, nixpkgs-for-bootstrap, home-manager, nix-formatter-pack, nmd }@inputs: let forEachSystem = nixpkgs.lib.genAttrs [ "aarch64-linux" "x86_64-linux" ]; @@ -80,6 +80,7 @@ { modules ? [ ] , extraSpecialArgs ? { } , pkgs ? pkgs' + , nixpkgs ? inputs.nixpkgs , home-manager-path ? home-manager.outPath # deprecated: , config ? null @@ -103,7 +104,7 @@ See the 22.11 release notes for more. '' (import ./modules { - inherit extraSpecialArgs home-manager-path pkgs; + inherit extraSpecialArgs home-manager-path nixpkgs pkgs; config.imports = modules; isFlake = true; }); @@ -118,7 +119,7 @@ }; docs = import ./docs { - inherit home-manager; + inherit nixpkgs home-manager; pkgs = nixpkgs.legacyPackages.${system}; nmdSrc = nmd; }; diff --git a/modules/default.nix b/modules/default.nix index 0ad1872..6412b0a 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,6 +3,7 @@ { config ? null , extraSpecialArgs ? { } , pkgs ? import { } +, nixpkgs ? , home-manager-path ? , isFlake ? false }: @@ -21,7 +22,7 @@ let rawModule = evalModules { modules = [ configModule ] ++ nodModules; - specialArgs = extraSpecialArgs; + specialArgs = { inherit nixpkgs; } // extraSpecialArgs; }; failedAssertions = map (x: x.message) (filter (x: !x.assertion) rawModule.config.assertions); diff --git a/modules/environment/nix-channel.nix b/modules/environment/nix-channel.nix new file mode 100644 index 0000000..deff596 --- /dev/null +++ b/modules/environment/nix-channel.nix @@ -0,0 +1,44 @@ +# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. + +# Based on +# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/config/nix-channel.nix +# (Copyright (c) 2003-2022 Eelco Dolstra and the Nixpkgs/NixOS contributors, +# licensed under MIT License as well) + +{ config, lib, pkgs, nixpkgs, ... }: + +with lib; + +let + cfg = config.nix; + renameNixOpt = old: new: + (mkRenamedOptionModule [ "nix" old ] [ "nix" new ]); +in + +{ + ###### interface + + options = { + + nix = { + nixPath = mkOption { + type = types.listOf types.str; + default = [ ]; + description = '' + The default Nix expression search path, used by the Nix + evaluator to look up paths enclosed in angle brackets + (e.g. <nixpkgs>). + ''; + }; + }; + + }; + + + ###### implementation + + config = { + environment.sessionVariables.NIX_PATH = concatStringsSep ":" cfg.nixPath; + }; + +} diff --git a/modules/environment/nix-flakes.nix b/modules/environment/nix-flakes.nix new file mode 100644 index 0000000..e3063b6 --- /dev/null +++ b/modules/environment/nix-flakes.nix @@ -0,0 +1,21 @@ +# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. + +# Based on +# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/config/nix-flakes.nix +# (Copyright (c) 2003-2022 Eelco Dolstra and the Nixpkgs/NixOS contributors, +# licensed under MIT License as well) + +{ config, lib, pkgs, nixpkgs, ... }: + +with lib; + +let + cfg = config.nix; +in + +{ + imports = [ + # Use options and config from upstream nix-flakes.nix + "${nixpkgs}/nixos/modules/config/nix-flakes.nix" + ]; +} diff --git a/modules/environment/nix.nix b/modules/environment/nix.nix index c5295a9..c199550 100644 --- a/modules/environment/nix.nix +++ b/modules/environment/nix.nix @@ -1,26 +1,33 @@ # Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. # Based on -# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/nix-daemon.nix +# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/system/nix-daemon.nix +# and +# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/config/nix.nix # (Copyright (c) 2003-2022 Eelco Dolstra and the Nixpkgs/NixOS contributors, # licensed under MIT License as well) -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, nixpkgs, ... }: with lib; let cfg = config.nix; renameNixOpt = old: new: - (mkRenamedOptionModule [ "nix" old ] [ "nix" new ]); + mkRenamedOptionModuleWith { + sinceRelease = 2205; + from = [ "nix" old ]; + to = [ "nix" "settings" new ]; + }; in { - # Backward-compatibility with the NixOS options. imports = [ - (renameNixOpt "binaryCaches" "substituters") - (renameNixOpt "binaryCachePublicKeys" "trustedPublicKeys") - (renameNixOpt "extraConfig" "extraOptions") + # Use options and config from upstream nix.nix + "${nixpkgs}/nixos/modules/config/nix.nix" + # Backward-compatibility with pre-`settings` options. + (renameNixOpt "substituters" "substituters") + (renameNixOpt "trustedPublicKeys" "trusted-public-keys") ]; ###### interface @@ -28,6 +35,19 @@ in options = { nix = { + + ## From nix-daemon.nix + + enable = mkOption { + type = types.bool; + default = true; + description = '' + Whether to enable Nix. + Disabling Nix is not supported in NixOnDroid. This option is here to + make it compatible to the upstream NixOS modules. + ''; + }; + package = mkOption { type = types.package; default = pkgs.nix; @@ -37,97 +57,6 @@ in ''; }; - nixPath = mkOption { - type = types.listOf types.str; - default = [ ]; - description = '' - The default Nix expression search path, used by the Nix - evaluator to look up paths enclosed in angle brackets - (e.g. <nixpkgs>). - ''; - }; - - registry = mkOption { - type = types.attrsOf (types.submodule ( - let - referenceAttrs = with types; attrsOf (oneOf [ - str - int - bool - package - ]); - in - { config, name, ... }: - { - options = { - from = mkOption { - type = referenceAttrs; - example = { type = "indirect"; id = "nixpkgs"; }; - description = "The flake reference to be rewritten."; - }; - to = mkOption { - type = referenceAttrs; - example = { type = "github"; owner = "my-org"; repo = "my-nixpkgs"; }; - description = "The flake reference is rewritten to."; - }; - flake = mkOption { - type = types.nullOr types.attrs; - default = null; - example = literalExpression "nixpkgs"; - description = '' - The flake input is rewritten to. - ''; - }; - exact = mkOption { - type = types.bool; - default = true; - description = '' - Whether the reference needs to match exactly. If set, - a reference like nixpkgs does not - match with a reference like nixpkgs/nixos-20.03. - ''; - }; - }; - config = { - from = mkDefault { type = "indirect"; id = name; }; - to = mkIf (config.flake != null) (mkDefault - { - type = "path"; - path = config.flake.outPath; - } // filterAttrs - (n: _: n == "lastModified" || n == "rev" || n == "revCount" || n == "narHash") - config.flake); - }; - } - )); - default = { }; - description = "A system-wide flake registry."; - }; - - substituters = mkOption { - type = types.listOf types.str; - default = [ ]; - description = '' - A list of URLs of substituters. The official NixOS and Nix-on-Droid - substituters are added by default. - ''; - }; - - trustedPublicKeys = mkOption { - type = types.listOf types.str; - default = [ ]; - description = '' - A list of public keys. When paths are copied from another Nix store (such as a - binary cache), they must be signed with one of these keys. The official NixOS - and Nix-on-Droid public keys are added by default. - ''; - }; - - extraOptions = mkOption { - type = types.lines; - default = ""; - description = "Extra config to be appended to /etc/nix/nix.conf."; - }; }; }; @@ -135,37 +64,18 @@ in ###### implementation - config = mkMerge [ - { - environment.etc = { - "nix/nix.conf".text = '' - sandbox = false - substituters = ${concatStringsSep " " cfg.substituters} - trusted-public-keys = ${concatStringsSep " " cfg.trustedPublicKeys} - ${cfg.extraOptions} - ''; - - "nix/registry.json".text = builtins.toJSON { - version = 2; - flakes = mapAttrsToList (_n: v: { inherit (v) from to exact; }) cfg.registry; - }; - }; - - nix = { - substituters = [ - "https://cache.nixos.org" - "https://nix-on-droid.cachix.org" - ]; - trustedPublicKeys = [ - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" - "nix-on-droid.cachix.org-1:56snoMJTXmDRC1Ei24CmKoUqvHJ9XCp+nidK7qkMQrU=" - ]; - }; - } - - (mkIf (cfg.nixPath != [ ]) { - environment.sessionVariables.NIX_PATH = concatStringsSep ":" cfg.nixPath; - }) - ]; + config = { + nix = { + enable = true; + settings.substituters = [ + "https://cache.nixos.org" + "https://nix-on-droid.cachix.org" + ]; + settings.trusted-public-keys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + "nix-on-droid.cachix.org-1:56snoMJTXmDRC1Ei24CmKoUqvHJ9XCp+nidK7qkMQrU=" + ]; + }; + }; }