Skip to content

Commit

Permalink
Merge pull request #263744 from K900/stateversion-docs
Browse files Browse the repository at this point in the history
treewide: rewrite stateVersion docs (again), clean up some stateVersion usages (again)
  • Loading branch information
K900 authored Oct 29, 2023
2 parents 24043a2 + 424b0ce commit 2202414
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ in

virtualisation.azureImage.diskSize = 2500;

system.stateVersion = "20.03";
boot.kernelPackages = pkgs.linuxPackages_latest;

# test user doesn't have a password
Expand Down
6 changes: 3 additions & 3 deletions nixos/maintainers/scripts/lxd/lxd-container-image-inner.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, lib, ... }:
{ config, pkgs, lib, modulesPath, ... }:

{
imports =
[
# Include the default lxd configuration.
../../../modules/virtualisation/lxc-container.nix
"${modulesPath}/modules/virtualisation/lxc-container.nix"
# Include the container-specific autogenerated configuration.
./lxd.nix
];

networking.useDHCP = false;
networking.interfaces.eth0.useDHCP = true;

system.stateVersion = "21.05"; # Did you read the comment?
system.stateVersion = "@stateVersion@"; # Did you read the comment?
}
10 changes: 7 additions & 3 deletions nixos/maintainers/scripts/lxd/lxd-container-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
};

# copy the config for nixos-rebuild
system.activationScripts.config = ''
system.activationScripts.config = let
config = pkgs.substituteAll {
src = ./lxd-container-image-inner.nix;
stateVersion = lib.trivial.release;
};
in ''
if [ ! -e /etc/nixos/configuration.nix ]; then
mkdir -p /etc/nixos
cat ${./lxd-container-image-inner.nix} > /etc/nixos/configuration.nix
${lib.getExe pkgs.gnused} 's|../../../modules/virtualisation/lxc-container.nix|<nixpkgs/nixos/modules/virtualisation/lxc-container.nix>|g' -i /etc/nixos/configuration.nix
cp ${config} /etc/nixos/configuration.nix
fi
'';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, lib, ... }:
{ config, pkgs, lib, modulesPath, ... }:

{
imports =
[
# Include the default lxd configuration.
../../../modules/virtualisation/lxd-virtual-machine.nix
"${modulesPath}/virtualisation/lxd-virtual-machine.nix"
# Include the container-specific autogenerated configuration.
./lxd.nix
];

networking.useDHCP = false;
networking.interfaces.eth0.useDHCP = true;

system.stateVersion = "23.05"; # Did you read the comment?
system.stateVersion = "@stateVersion@"; # Did you read the comment?
}
10 changes: 7 additions & 3 deletions nixos/maintainers/scripts/lxd/lxd-virtual-machine-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
};

# copy the config for nixos-rebuild
system.activationScripts.config = ''
system.activationScripts.config = let
config = pkgs.substituteAll {
src = ./lxd-virtual-machine-image-inner.nix;
stateVersion = lib.trivial.release;
};
in ''
if [ ! -e /etc/nixos/configuration.nix ]; then
mkdir -p /etc/nixos
cat ${./lxd-virtual-machine-image-inner.nix} > /etc/nixos/configuration.nix
${lib.getExe pkgs.gnused} 's|../../../modules/virtualisation/lxd-virtual-machine.nix|<nixpkgs/nixos/modules/virtualisation/lxd-virtual-machine.nix>|g' -i /etc/nixos/configuration.nix
cp ${config} /etc/nixos/configuration.nix
fi
'';

Expand Down
22 changes: 16 additions & 6 deletions nixos/modules/installer/tools/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,22 @@ in
# accidentally delete configuration.nix.
# system.copySystemConfiguration = true;
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. It's perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
# This option defines the first version of NixOS you have installed on this particular machine,
# and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
#
# Most users should NEVER change this value after the initial install, for any reason,
# even if you've upgraded your system to a new NixOS release.
#
# This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
# so changing it will NOT upgrade your system.
#
# This value being lower than the current NixOS release does NOT mean your system is
# out of date, out of support, or vulnerable.
#
# Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
# and migrated your data accordingly.
#
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
system.stateVersion = "${config.system.nixos.release}"; # Did you read the comment?
}
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/installer/virtualbox-demo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with lib;
services.xserver.videoDrivers = mkOverride 40 [ "virtualbox" "vmware" "cirrus" "vesa" "modesetting" ];

powerManagement.enable = false;
system.stateVersion = mkDefault "18.03";
system.stateVersion = lib.mkDefault lib.trivial.release;

installer.cloneConfigExtra = ''
# Let demo build as a trusted user.
Expand Down
42 changes: 26 additions & 16 deletions nixos/modules/misc/version.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,32 @@ in
default = cfg.release;
defaultText = literalExpression "config.${opt.release}";
description = lib.mdDoc ''
Every once in a while, a new NixOS release may change
configuration defaults in a way incompatible with stateful
data. For instance, if the default version of PostgreSQL
changes, the new version will probably be unable to read your
existing databases. To prevent such breakage, you should set the
value of this option to the NixOS release with which you want
to be compatible. The effect is that NixOS will use
defaults corresponding to the specified release (such as using
an older version of PostgreSQL).
It’s perfectly fine and recommended to leave this value at the
release version of the first install of this system.
Changing this option will not upgrade your system. In fact it
is meant to stay constant exactly when you upgrade your system.
You should only bump this option, if you are sure that you can
or have migrated all state on your system which is affected
by this option.
This option defines the first version of NixOS you have installed on this particular machine,
and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
For example, if NixOS version XX.YY ships with AwesomeDB version N by default, and is then
upgraded to version XX.YY+1, which ships AwesomeDB version N+1, the existing databases
may no longer be compatible, causing applications to fail, or even leading to data loss.
The `stateVersion` mechanism avoids this situation by making the default version of such packages
conditional on the first version of NixOS you've installed (encoded in `stateVersion`), instead of
simply always using the latest one.
Note that this generally only affects applications that can't upgrade their data automatically -
applications and services supporting automatic migrations will remain on latest versions when
you upgrade.
Most users should **never** change this value after the initial install, for any reason,
even if you've upgraded your system to a new NixOS release.
This value does **not** affect the Nixpkgs version your packages and OS are pulled from,
so changing it will **not** upgrade your system.
This value being lower than the current NixOS release does **not** mean your system is
out of date, out of support, or vulnerable.
Do **not** change this value unless you have manually inspected all the changes it would
make to your configuration, and migrated your data accordingly.
'';
};

Expand Down
4 changes: 3 additions & 1 deletion nixos/modules/virtualisation/nixos-containers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ in
{ services.postgresql.enable = true;
services.postgresql.package = pkgs.postgresql_14;
system.stateVersion = "21.05";
system.stateVersion = "${lib.trivial.release}";
};
};
}
Expand Down Expand Up @@ -906,4 +906,6 @@ in
"tun"
];
});

meta.buildDocsInSandbox = false;
}
2 changes: 1 addition & 1 deletion nixos/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ in rec {
modules = singleton ({ ... }:
{ fileSystems."/".device = mkDefault "/dev/sda1";
boot.loader.grub.device = mkDefault "/dev/sda";
system.stateVersion = mkDefault "18.03";
system.stateVersion = mkDefault lib.trivial.release;
});
}).config.system.build.toplevel;
preferLocalBuild = true;
Expand Down
4 changes: 1 addition & 3 deletions nixos/tests/containers-imperative.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
modules = lib.singleton {
nixpkgs = { inherit (config.nixpkgs) localSystem; };

containers.foo.config = {
system.stateVersion = "18.03";
};
containers.foo.config = {};
};

# The system is inherited from the host above.
Expand Down
2 changes: 0 additions & 2 deletions nixos/tests/nextcloud/basic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ in {
"d /var/lib/nextcloud-data 0750 nextcloud nginx - -"
];

system.stateVersion = "22.11"; # stateVersion >=21.11 to make sure that we use OpenSSL3

services.nextcloud = {
enable = true;
datadir = "/var/lib/nextcloud-data";
Expand Down

0 comments on commit 2202414

Please sign in to comment.