Revert "Add a way to pin a NixOS version within the module system."

This reverts commit a5992ad61b314104aff7e28a41ce101a1b0e7c35. Motivation:

https://github.com/NixOS/nixpkgs/commit/a5992ad61b314104aff7e28a41ce101a1b0e7c35#commitcomment-14986820

+4 -252
+4 -12
nixos/default.nix
··· 1 { configuration ? import ./lib/from-env.nix "NIXOS_CONFIG" <nixos-config> 2 , system ? builtins.currentSystem 3 - , extraModules ? [] 4 - # This attribute is used to specify a different nixos version, a different 5 - # system or additional modules which might be set conditionally. 6 - , reEnter ? false 7 }: 8 9 let 10 - reEnterModule = { 11 - config.nixos.path = with (import ../lib); mkIf reEnter (mkForce null); 12 - config.nixos.configuration = configuration; 13 - }; 14 15 eval = import ./lib/eval-config.nix { 16 inherit system; 17 - modules = [ configuration reEnterModule ] ++ extraModules; 18 }; 19 20 inherit (eval) pkgs; ··· 22 # This is for `nixos-rebuild build-vm'. 23 vmConfig = (import ./lib/eval-config.nix { 24 inherit system; 25 - modules = [ configuration reEnterModule ./modules/virtualisation/qemu-vm.nix ] ++ extraModules; 26 }).config; 27 28 # This is for `nixos-rebuild build-vm-with-bootloader'. 29 vmWithBootLoaderConfig = (import ./lib/eval-config.nix { 30 inherit system; 31 modules = 32 - [ configuration reEnterModule 33 ./modules/virtualisation/qemu-vm.nix 34 { virtualisation.useBootLoader = true; } 35 ]; ··· 38 in 39 40 { 41 - inherit (eval.config.nixos.reflect) config options; 42 43 system = eval.config.system.build.toplevel; 44
··· 1 { configuration ? import ./lib/from-env.nix "NIXOS_CONFIG" <nixos-config> 2 , system ? builtins.currentSystem 3 }: 4 5 let 6 7 eval = import ./lib/eval-config.nix { 8 inherit system; 9 + modules = [ configuration ]; 10 }; 11 12 inherit (eval) pkgs; ··· 14 # This is for `nixos-rebuild build-vm'. 15 vmConfig = (import ./lib/eval-config.nix { 16 inherit system; 17 + modules = [ configuration ./modules/virtualisation/qemu-vm.nix ]; 18 }).config; 19 20 # This is for `nixos-rebuild build-vm-with-bootloader'. 21 vmWithBootLoaderConfig = (import ./lib/eval-config.nix { 22 inherit system; 23 modules = 24 + [ configuration 25 ./modules/virtualisation/qemu-vm.nix 26 { virtualisation.useBootLoader = true; } 27 ]; ··· 30 in 31 32 { 33 + inherit (eval) config options; 34 35 system = eval.config.system.build.toplevel; 36
-1
nixos/doc/manual/configuration/configuration.xml
··· 28 <xi:include href="postgresql.xml" /> 29 <xi:include href="gitlab.xml" /> 30 <xi:include href="acme.xml" /> 31 - <xi:include href="nixos.xml" /> 32 33 <!-- Apache; libvirtd virtualisation --> 34
··· 28 <xi:include href="postgresql.xml" /> 29 <xi:include href="gitlab.xml" /> 30 <xi:include href="acme.xml" /> 31 32 <!-- Apache; libvirtd virtualisation --> 33
-1
nixos/doc/manual/default.nix
··· 58 cp ${../../modules/services/databases/postgresql.xml} configuration/postgresql.xml 59 cp ${../../modules/services/misc/gitlab.xml} configuration/gitlab.xml 60 cp ${../../modules/security/acme.xml} configuration/acme.xml 61 - cp ${../../modules/misc/nixos.xml} configuration/nixos.xml 62 ln -s ${optionsDocBook} options-db.xml 63 echo "${version}" > version 64 '';
··· 58 cp ${../../modules/services/databases/postgresql.xml} configuration/postgresql.xml 59 cp ${../../modules/services/misc/gitlab.xml} configuration/gitlab.xml 60 cp ${../../modules/security/acme.xml} configuration/acme.xml 61 ln -s ${optionsDocBook} options-db.xml 62 echo "${version}" > version 63 '';
-13
nixos/doc/manual/release-notes/rl-unstable.xml
··· 12 <itemizedlist> 13 14 <listitem> 15 - <para>You can now pin a specific version of NixOS in your <filename>configuration.nix</filename> 16 - by setting: 17 - 18 - <programlisting> 19 - nixos.path = ./nixpkgs-unstable-2015-12-06/nixos; 20 - </programlisting> 21 - 22 - This will make NixOS re-evaluate your configuration with the modules of 23 - the specified NixOS version at the given path. For more details, see 24 - <xref linkend="module-misc-nixos" /></para> 25 - </listitem> 26 - 27 - <listitem> 28 <para>Firefox and similar browsers are now <emphasis>wrapped by default</emphasis>. 29 The package and attribute names are plain <literal>firefox</literal> 30 or <literal>midori</literal>, etc. Backward-compatibility attributes were set up,
··· 12 <itemizedlist> 13 14 <listitem> 15 <para>Firefox and similar browsers are now <emphasis>wrapped by default</emphasis>. 16 The package and attribute names are plain <literal>firefox</literal> 17 or <literal>midori</literal>, etc. Backward-compatibility attributes were set up,
-82
nixos/modules/misc/nixos.nix
··· 1 - { config, options, lib, ... }: 2 - 3 - # This modules is used to inject a different NixOS version as well as its 4 - # argument such that one can pin a specific version with the versionning 5 - # system of the configuration. 6 - let 7 - nixosReentry = import config.nixos.path { 8 - inherit (config.nixos) configuration extraModules; 9 - inherit (config.nixpkgs) system; 10 - reEnter = true; 11 - }; 12 - in 13 - 14 - with lib; 15 - 16 - { 17 - options = { 18 - nixos.path = mkOption { 19 - default = null; 20 - example = literalExample "./nixpkgs-15.09/nixos"; 21 - type = types.nullOr types.path; 22 - description = '' 23 - This option give the ability to evaluate the current set of modules 24 - with a different version of NixOS. This option can be used version 25 - the version of NixOS with the configuration without relying on the 26 - <literal>NIX_PATH</literal> environment variable. 27 - ''; 28 - }; 29 - 30 - nixos.system = mkOption { 31 - example = "i686-linux"; 32 - type = types.uniq types.str; 33 - description = '' 34 - Name of the system used to compile NixOS. 35 - ''; 36 - }; 37 - 38 - nixos.extraModules = mkOption { 39 - default = []; 40 - example = literalExample "[ ./sshd-config.nix ]"; 41 - type = types.listOf (types.either (types.submodule ({...}:{options={};})) types.path); 42 - description = '' 43 - Define additional modules which would be loaded to evaluate the 44 - configuration. 45 - ''; 46 - }; 47 - 48 - nixos.configuration = mkOption { 49 - type = types.unspecified; 50 - internal = true; 51 - description = '' 52 - Option used by <filename>nixos/default.nix</filename> to re-inject 53 - the same configuration module as the one used for the current 54 - execution. 55 - ''; 56 - }; 57 - 58 - nixos.reflect = mkOption { 59 - default = { inherit config options; }; 60 - type = types.unspecified; 61 - internal = true; 62 - description = '' 63 - Provides <literal>config</literal> and <literal>options</literal> 64 - computed by the module system and given as argument to all 65 - modules. These are used for introspection of options and 66 - configuration by tools such as <literal>nixos-option</literal>. 67 - ''; 68 - }; 69 - }; 70 - 71 - config = mkMerge [ 72 - (mkIf (config.nixos.path != null) (mkForce { 73 - system.build.toplevel = nixosReentry.system; 74 - system.build.vm = nixosReentry.vm; 75 - nixos.reflect = { inherit (nixosReentry) config options; }; 76 - })) 77 - 78 - { meta.maintainers = singleton lib.maintainers.pierron; 79 - meta.doc = ./nixos.xml; 80 - } 81 - ]; 82 - }
···
-84
nixos/modules/misc/nixos.xml
··· 1 - <chapter xmlns="http://docbook.org/ns/docbook" 2 - xmlns:xlink="http://www.w3.org/1999/xlink" 3 - xmlns:xi="http://www.w3.org/2001/XInclude" 4 - version="5.0" 5 - xml:id="module-misc-nixos"> 6 - 7 - <title>NixOS Reentry</title> 8 - 9 - <!-- FIXME: render nicely --> 10 - 11 - <!-- FIXME: source can be added automatically --> 12 - <para><emphasis>Source:</emphasis> <filename>modules/misc/nixos.nix</filename></para> 13 - 14 - <!-- FIXME: more stuff, like maintainer? --> 15 - 16 - <para>NixOS reentry can be used for both pinning the evaluation to a 17 - specific version of NixOS, and to dynamically add additional modules into 18 - the Module evaluation.</para> 19 - 20 - <section><title>NixOS Version Pinning</title> 21 - 22 - <para>To pin a specific version of NixOS, you need a version that you can 23 - either clone localy, or that you can fetch remotely.</para> 24 - 25 - <para>If you already have a cloned version of NixOS in the directory 26 - <filename>/etc/nixos/nixpkgs-16-03</filename>, then you can specify the 27 - <option>nixos.path</option> with either the path or the relative path of 28 - your NixOS clone. For example, you can add the following to your 29 - <filename>/etc/nixos/configuration.nix</filename> file: 30 - 31 - <programlisting> 32 - nixos.path = ./nixpkgs-16-03/nixos; 33 - </programlisting> 34 - </para> 35 - 36 - <para>Another option is to fetch a specific version of NixOS, with either 37 - the <literal>fetchTarball</literal> builtin, or the 38 - <literal>pkgs.fetchFromGitHub</literal> function and use the result as an 39 - input. 40 - 41 - <programlisting> 42 - nixos.path = "${builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/1f27976e03c15183191d1b4aa1a40d1f14666cd2.tar.gz}/nixos"; 43 - </programlisting> 44 - </para> 45 - 46 - </section> 47 - 48 - 49 - <section><title>Adding Module Dynamically</title> 50 - 51 - <para>To add additional module, the recommended way is to use statically 52 - known modules in the list of imported arguments as described in <xref 53 - linkend="sec-modularity" />. Unfortunately, this recommended method has 54 - limitation, such that the list of imported files cannot be selected based on 55 - the content of the configuration. 56 - 57 - Fortunately, NixOS reentry system can be used as an alternative to register 58 - new imported modules based on the content of the configuration. To do so, 59 - one should define both <option>nixos.path</option> and 60 - <option>nixos.extraModules</option> options. 61 - 62 - <programlisting> 63 - nixos.path = &lt;nixos&gt;; 64 - nixos.extraModules = 65 - if config.networking.hostName == "server" then 66 - [ ./server.nix ] else [ ./client.nix ]; 67 - </programlisting> 68 - 69 - Also note, that the above can be reimplemented in a different way which is 70 - not as expensive, by using <literal>mkIf</literal> at the top each 71 - configuration if both modules are present on the file system (see <xref 72 - linkend="sec-option-definitions" />) and by always inmporting both 73 - modules.</para> 74 - 75 - </section> 76 - 77 - <section><title>Options</title> 78 - 79 - <para>FIXME: auto-generated list of module options.</para> 80 - 81 - </section> 82 - 83 - 84 - </chapter>
···
-1
nixos/modules/module-list.nix
··· 58 ./misc/lib.nix 59 ./misc/locate.nix 60 ./misc/meta.nix 61 - ./misc/nixos.nix 62 ./misc/nixpkgs.nix 63 ./misc/passthru.nix 64 ./misc/version.nix
··· 58 ./misc/lib.nix 59 ./misc/locate.nix 60 ./misc/meta.nix 61 ./misc/nixpkgs.nix 62 ./misc/passthru.nix 63 ./misc/version.nix
-1
nixos/release.nix
··· 284 tests.networkingProxy = callTest tests/networking-proxy.nix {}; 285 tests.nfs3 = callTest tests/nfs.nix { version = 3; }; 286 tests.nfs4 = callTest tests/nfs.nix { version = 4; }; 287 - tests.nixosPinVersion = callTest tests/nixos-pin-version.nix {}; 288 tests.nsd = callTest tests/nsd.nix {}; 289 tests.openssh = callTest tests/openssh.nix {}; 290 tests.panamax = hydraJob (import tests/panamax.nix { system = "x86_64-linux"; });
··· 284 tests.networkingProxy = callTest tests/networking-proxy.nix {}; 285 tests.nfs3 = callTest tests/nfs.nix { version = 3; }; 286 tests.nfs4 = callTest tests/nfs.nix { version = 4; }; 287 tests.nsd = callTest tests/nsd.nix {}; 288 tests.openssh = callTest tests/openssh.nix {}; 289 tests.panamax = hydraJob (import tests/panamax.nix { system = "x86_64-linux"; });
-57
nixos/tests/nixos-pin-version.nix
··· 1 - { system ? builtins.currentSystem }: 2 - 3 - with import ../lib/testing.nix { inherit system; }; 4 - let 5 - in 6 - 7 - pkgs.stdenv.mkDerivation rec { 8 - name = "nixos-pin-version"; 9 - src = ../..; 10 - buildInputs = with pkgs; [ nix gnugrep ]; 11 - 12 - withoutPath = pkgs.writeText "configuration.nix" '' 13 - { 14 - nixos.extraModules = [ ({lib, ...}: { system.nixosRevision = lib.mkForce "ABCDEF"; }) ]; 15 - } 16 - ''; 17 - 18 - withPath = pkgs.writeText "configuration.nix" '' 19 - { 20 - nixos.path = ${src}/nixos ; 21 - nixos.extraModules = [ ({lib, ...}: { system.nixosRevision = lib.mkForce "ABCDEF"; }) ]; 22 - } 23 - ''; 24 - 25 - phases = "buildPhase"; 26 - buildPhase = '' 27 - datadir="${pkgs.nix}/share" 28 - export TEST_ROOT=$(pwd)/test-tmp 29 - export NIX_STORE_DIR=$TEST_ROOT/store 30 - export NIX_LOCALSTATE_DIR=$TEST_ROOT/var 31 - export NIX_LOG_DIR=$TEST_ROOT/var/log/nix 32 - export NIX_STATE_DIR=$TEST_ROOT/var/nix 33 - export NIX_DB_DIR=$TEST_ROOT/db 34 - export NIX_CONF_DIR=$TEST_ROOT/etc 35 - export NIX_MANIFESTS_DIR=$TEST_ROOT/var/nix/manifests 36 - export NIX_BUILD_HOOK= 37 - export PAGER=cat 38 - cacheDir=$TEST_ROOT/binary-cache 39 - nix-store --init 40 - 41 - export NIX_PATH="nixpkgs=$src:nixos=$src/nixos:nixos-config=${withoutPath}" ; 42 - if test $(nix-instantiate $src/nixos -A config.system.nixosRevision --eval-only) != '"ABCDEF"' ; then :; 43 - else 44 - echo "Unexpected re-entry without the nixos.path option defined."; 45 - exit 1; 46 - fi; 47 - 48 - export NIX_PATH="nixpkgs=$src:nixos=$src/nixos:nixos-config=${withPath}" ; 49 - if test $(nix-instantiate $src/nixos -A config.system.nixosRevision --eval-only) = '"ABCDEF"' ; then :; 50 - else 51 - echo "Expected a re-entry when the nixos.path option is defined."; 52 - exit 1; 53 - fi; 54 - 55 - touch $out; 56 - ''; 57 - }
···