From f03c7fb8d4e5fa75962f41b821b17e5ef8154c96 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 22 Dec 2022 19:51:11 +0100 Subject: [PATCH 1/4] nixos/version: Only warn about unset stateVersion if used If a configuration does not use services that depend on the stateVersion, it does not need to be set. This provides an incentive for services not to rely on stateVersion, and not to burden users with this. --- nixos/modules/misc/version.nix | 14 ++++++-------- nixos/modules/services/matrix/synapse.nix | 6 ++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index b3cdaf5568d4..1067b21a22b0 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -89,6 +89,12 @@ in stateVersion = mkOption { type = types.str; + # TODO Remove this and drop the default of the option so people are forced to set it. + # Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix + apply = v: + lib.warnIf (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority) + "system.stateVersion is not set, defaulting to ${v}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion." + v; default = cfg.release; defaultText = literalExpression "config.${opt.release}"; description = lib.mdDoc '' @@ -149,14 +155,6 @@ in "os-release".text = attrsToText osReleaseContents; }; - # We have to use `warnings` because when warning in the default of the option - # the warning would also be shown when building the manual since the manual - # has to evaluate the default. - # - # TODO Remove this and drop the default of the option so people are forced to set it. - # Doing this also means fixing the comment in nixos/modules/testing/test-instrumentation.nix - warnings = lib.optional (options.system.stateVersion.highestPrio == (lib.mkOptionDefault { }).priority) - "system.stateVersion is not set, defaulting to ${config.system.stateVersion}. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion."; }; # uses version info nixpkgs, which requires a full nixpkgs path diff --git a/nixos/modules/services/matrix/synapse.nix b/nixos/modules/services/matrix/synapse.nix index b9b581acb34a..3087d879b9d2 100644 --- a/nixos/modules/services/matrix/synapse.nix +++ b/nixos/modules/services/matrix/synapse.nix @@ -507,6 +507,12 @@ in { sqlite3 = null; psycopg2 = "matrix-synapse"; }.${cfg.settings.database.name}; + defaultText = lib.literalExpression '' + { + sqlite3 = null; + psycopg2 = "matrix-synapse"; + }.''${cfg.settings.database.name}; + ''; description = lib.mdDoc '' Username to connect with psycopg2, set to null when using sqlite3. From 30548793ab82c2a57239f71a413fd869cd67b300 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 27 Dec 2022 12:46:26 +0100 Subject: [PATCH 2/4] darwin.builder: Avoid unnecessary dependency on stateVersion --- nixos/modules/profiles/macos-builder.nix | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/nixos/modules/profiles/macos-builder.nix b/nixos/modules/profiles/macos-builder.nix index 15fad007bd3e..edb53cc0da10 100644 --- a/nixos/modules/profiles/macos-builder.nix +++ b/nixos/modules/profiles/macos-builder.nix @@ -11,6 +11,17 @@ in { imports = [ ../virtualisation/qemu-vm.nix + + # Avoid a dependency on stateVersion + { + disabledModules = [ + ../virtualisation/nixos-containers.nix + ../services/x11/desktop-managers/xterm.nix + ]; + config = { + }; + options.boot.isContainer = lib.mkOption { default = false; internal = true; }; + } ]; # The builder is not intended to be used interactively @@ -97,7 +108,23 @@ in # To prevent gratuitous rebuilds on each change to Nixpkgs nixos.revision = null; - stateVersion = "22.05"; + stateVersion = lib.mkDefault (throw '' + The macOS linux builder should not need a stateVersion to be set, but a module + has accessed stateVersion nonetheless. + Please inspect the trace of the following command to figure out which module + has a dependency on stateVersion. + + nix-instantiate --argstr system x86_64-darwin -A darwin.builder --show-trace + + or + + nix-instantiate --argstr system aarch64-darwin -A darwin.builder --show-trace + + If this error occurred while evaluating the static part of the option + documentation, the problem may be fixed by adding defaultText to an option. + Otherwise, the dependency should be removed. As a last resort, stateVersion + may be hardcoded in the darwin.builder package by replacing this exception. + ''); }; users.users."${user}"= { From 62c8b5bf85b064478e9696c365ead13a8981898a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 28 Dec 2022 14:30:59 +0100 Subject: [PATCH 3/4] nixos/macos-builder: Simplify error message The `system` argument is usually implied, and not hard to figure out. Co-authored-by: Gabriella Gonzalez --- nixos/modules/profiles/macos-builder.nix | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/nixos/modules/profiles/macos-builder.nix b/nixos/modules/profiles/macos-builder.nix index edb53cc0da10..ee76112a094c 100644 --- a/nixos/modules/profiles/macos-builder.nix +++ b/nixos/modules/profiles/macos-builder.nix @@ -114,11 +114,7 @@ in Please inspect the trace of the following command to figure out which module has a dependency on stateVersion. - nix-instantiate --argstr system x86_64-darwin -A darwin.builder --show-trace - - or - - nix-instantiate --argstr system aarch64-darwin -A darwin.builder --show-trace + nix-instantiate --attr darwin.builder --show-trace If this error occurred while evaluating the static part of the option documentation, the problem may be fixed by adding defaultText to an option. From 91050a9d9d21c18660da4b5cc88a3c9b2b23adda Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 28 Dec 2022 14:32:56 +0100 Subject: [PATCH 4/4] nixos/macos-builder: Remove unnecessary paragraph I was considering the broader context of stateVersion, but the macos builder does not enable documentation, making this paragraph a distraction. --- nixos/modules/profiles/macos-builder.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/nixos/modules/profiles/macos-builder.nix b/nixos/modules/profiles/macos-builder.nix index ee76112a094c..a981814730a1 100644 --- a/nixos/modules/profiles/macos-builder.nix +++ b/nixos/modules/profiles/macos-builder.nix @@ -115,11 +115,6 @@ in has a dependency on stateVersion. nix-instantiate --attr darwin.builder --show-trace - - If this error occurred while evaluating the static part of the option - documentation, the problem may be fixed by adding defaultText to an option. - Otherwise, the dependency should be removed. As a last resort, stateVersion - may be hardcoded in the darwin.builder package by replacing this exception. ''); };