From 8eaf02b9cd35def36217d39812b7c656de307c58 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 11 Feb 2019 12:27:17 +0100 Subject: [PATCH 01/39] Add flake.nix --- flake.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..9f5434330aa --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + name = "nixpkgs"; + + epoch = 2019; + + description = "A collection of packages for the Nix package manager"; + + provides = flakes: + let pkgs = import ./. {}; in + { + lib = import ./lib; + + builders = { + inherit (pkgs) stdenv fetchurl; + }; + + packages = { + inherit (pkgs) hello nix fuse nlohmann_json boost; + }; + + legacyPkgs = pkgs; + }; +} From 123dea9b0d96544f042428b556a76ce6ed6f18b2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 12 Feb 2019 20:32:26 +0100 Subject: [PATCH 02/39] flake.nix: Set system explicitly for now Flakes now are evaluated in pure mode, so we can't rely on currentSystem anymore. --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9f5434330aa..f007a060fd1 100644 --- a/flake.nix +++ b/flake.nix @@ -6,7 +6,7 @@ description = "A collection of packages for the Nix package manager"; provides = flakes: - let pkgs = import ./. {}; in + let pkgs = import ./. { system = "x86_64-linux"; }; in { lib = import ./lib; From 57ccd736bb7afb52f44ea9b6fb8357e4bf591d7e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 26 Mar 2019 14:37:43 +0100 Subject: [PATCH 03/39] Export a function for building NixOS system configurations --- flake.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index f007a060fd1..316181c2cc3 100644 --- a/flake.nix +++ b/flake.nix @@ -8,7 +8,9 @@ provides = flakes: let pkgs = import ./. { system = "x86_64-linux"; }; in { - lib = import ./lib; + lib = (import ./lib) // { + nixosSystem = import ./nixos/lib/eval-config.nix; + }; builders = { inherit (pkgs) stdenv fetchurl; From b7cbbfff519caf46cbed563ef24439fd36c9bf84 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 19 Apr 2019 14:48:40 +0200 Subject: [PATCH 04/39] Add flake.lock --- flake.lock | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 flake.lock diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..b0dd7a2b6ba --- /dev/null +++ b/flake.lock @@ -0,0 +1,5 @@ +{ + "nonFlakeRequires": {}, + "requires": {}, + "version": 1 +} \ No newline at end of file From af376fdc2343dfdc748356f491c0b5315defe522 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 29 May 2019 21:11:22 +0200 Subject: [PATCH 05/39] legacyPkgs -> legacyPackages --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 316181c2cc3..9f4535d4c51 100644 --- a/flake.nix +++ b/flake.nix @@ -17,9 +17,9 @@ }; packages = { - inherit (pkgs) hello nix fuse nlohmann_json boost; + inherit (pkgs) hello nix fuse nlohmann_json boost firefox; }; - legacyPkgs = pkgs; + legacyPackages = pkgs; }; } From 0f913dee486286c9846135dd857c83d28cc9c315 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 29 May 2019 21:21:56 +0200 Subject: [PATCH 06/39] flake.nix: Add check --- flake.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake.nix b/flake.nix index 9f4535d4c51..b4b126c9be0 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,10 @@ nixosSystem = import ./nixos/lib/eval-config.nix; }; + checks.tarball = (import ./pkgs/top-level/release.nix { + nixpkgs = flakes.self; + }).tarball; + builders = { inherit (pkgs) stdenv fetchurl; }; From 55483974885b1e98fc392c73da93bb90e9204c56 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 29 May 2019 21:28:33 +0200 Subject: [PATCH 07/39] make-tarball.nix: Derive version from lastModified instead of revCount GitHub flakes don't provide revCount. --- pkgs/top-level/make-tarball.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/make-tarball.nix b/pkgs/top-level/make-tarball.nix index 288971403f1..7bb18e765f1 100644 --- a/pkgs/top-level/make-tarball.nix +++ b/pkgs/top-level/make-tarball.nix @@ -17,7 +17,10 @@ releaseTools.sourceTarball { inherit officialRelease; version = pkgs.lib.fileContents ../../.version; - versionSuffix = "pre${toString nixpkgs.revCount}.${nixpkgs.shortRev}"; + versionSuffix = "pre${ + if nixpkgs ? lastModified + then builtins.substring 0 8 nixpkgs.lastModified + else toString nixpkgs.revCount}.${nixpkgs.shortRev}"; buildInputs = [ nix.out jq lib-tests ]; From b70a4436c617de1576c56b85c8338b5b51c18994 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 29 May 2019 23:03:16 +0200 Subject: [PATCH 08/39] flake.nix: provides -> outputs --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index b4b126c9be0..002999fdf4c 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,7 @@ description = "A collection of packages for the Nix package manager"; - provides = flakes: + outputs = inputs: let pkgs = import ./. { system = "x86_64-linux"; }; in { lib = (import ./lib) // { @@ -13,7 +13,7 @@ }; checks.tarball = (import ./pkgs/top-level/release.nix { - nixpkgs = flakes.self; + nixpkgs = inputs.self; }).tarball; builders = { From 395f044bbe282c2d9a8d5131ef1a409e702f6021 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 3 Jun 2019 21:26:40 +0200 Subject: [PATCH 09/39] flake.nix: Update epoch --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 002999fdf4c..20145e4dadb 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,7 @@ { name = "nixpkgs"; - epoch = 2019; + epoch = 201906; description = "A collection of packages for the Nix package manager"; From f16ca590c7dbce162f713a003fdd31bfc49df1b0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 5 Jun 2019 10:27:30 +0200 Subject: [PATCH 10/39] Remove flake.lock --- flake.lock | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 flake.lock diff --git a/flake.lock b/flake.lock deleted file mode 100644 index b0dd7a2b6ba..00000000000 --- a/flake.lock +++ /dev/null @@ -1,5 +0,0 @@ -{ - "nonFlakeRequires": {}, - "requires": {}, - "version": 1 -} \ No newline at end of file From 2ba1f3c1955d0687ed3ba5608b4af6f6f579f80b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 19 Jun 2019 12:43:26 +0200 Subject: [PATCH 11/39] Add flake outputs for the manuals --- flake.nix | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 20145e4dadb..9209a9f5e71 100644 --- a/flake.nix +++ b/flake.nix @@ -6,20 +6,30 @@ description = "A collection of packages for the Nix package manager"; outputs = inputs: - let pkgs = import ./. { system = "x86_64-linux"; }; in + let + pkgs = import ./. { system = "x86_64-linux"; }; + jobs = import ./pkgs/top-level/release.nix { + nixpkgs = inputs.self; + }; + in { lib = (import ./lib) // { nixosSystem = import ./nixos/lib/eval-config.nix; }; - checks.tarball = (import ./pkgs/top-level/release.nix { - nixpkgs = inputs.self; - }).tarball; + checks.tarball = jobs.tarball; builders = { inherit (pkgs) stdenv fetchurl; }; + htmlDocs = { + nixpkgsManual = jobs.manual; + nixosManual = (import ./nixos/release-small.nix { + nixpkgs = inputs.self; + }).nixos.manual.x86_64-linux; + }; + packages = { inherit (pkgs) hello nix fuse nlohmann_json boost firefox; }; From 63bcbc19cd4a36f439e4b7235bc2a6358cd5d278 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 30 Aug 2019 11:48:43 +0200 Subject: [PATCH 12/39] Update flake interface --- flake.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 9209a9f5e71..15dd412fdec 100644 --- a/flake.nix +++ b/flake.nix @@ -1,15 +1,15 @@ { name = "nixpkgs"; - epoch = 201906; + epoch = 201909; description = "A collection of packages for the Nix package manager"; - outputs = inputs: + outputs = { self }: let pkgs = import ./. { system = "x86_64-linux"; }; jobs = import ./pkgs/top-level/release.nix { - nixpkgs = inputs.self; + nixpkgs = self; }; in { @@ -26,7 +26,7 @@ htmlDocs = { nixpkgsManual = jobs.manual; nixosManual = (import ./nixos/release-small.nix { - nixpkgs = inputs.self; + nixpkgs = self; }).nixos.manual.x86_64-linux; }; From 6a210fa34558f883a8200354ad0eaa9e83b04975 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 30 Aug 2019 16:35:17 +0200 Subject: [PATCH 13/39] flake.nix: Remove obsolete name attribute --- flake.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/flake.nix b/flake.nix index 15dd412fdec..f3bd9c8611b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,4 @@ { - name = "nixpkgs"; - epoch = 201909; description = "A collection of packages for the Nix package manager"; From 22cc7ab78c3e45ebbb1ec66be6c5b9c7f47f780d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 13 Sep 2019 18:02:44 +0200 Subject: [PATCH 14/39] nixos-rebuild: Add --flake option --- nixos/doc/manual/man-nixos-rebuild.xml | 40 +++++++++++ .../modules/installer/tools/nixos-rebuild.sh | 70 ++++++++++++++++--- nixos/modules/installer/tools/tools.nix | 1 + 3 files changed, 103 insertions(+), 8 deletions(-) diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml index 495dbc8859b..81e2f8bb279 100644 --- a/nixos/doc/manual/man-nixos-rebuild.xml +++ b/nixos/doc/manual/man-nixos-rebuild.xml @@ -77,7 +77,18 @@ builder-spec + + + + flake-uri + + + + name + + + @@ -508,6 +519,35 @@ + + + + flake-uri + + + + Build the NixOS system from the specified flake. The flake must + contain an output named + nixosConfigurations.name, + where name denotes the name of the + configuration and can be specified using the + option. + + + + + + + name + + + + Specifies which NixOS configuration to use from the + flake. Defaults to the current hostname. + + + + diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 7db323d38e6..949cd869146 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -3,6 +3,9 @@ if [ -x "@shell@" ]; then export SHELL="@shell@"; fi; set -e +set -o pipefail + +export PATH=@path@:$PATH showSyntax() { exec man nixos-rebuild @@ -93,6 +96,14 @@ while [ "$#" -gt 0 ]; do --use-remote-sudo) maybeSudo=(sudo --) ;; + --flake) + flake="$1" + shift 1 + ;; + --config) + flakeAttr="nixosConfigurations.$1" + shift 1 + ;; *) echo "$0: unknown option \`$i'" exit 1 @@ -226,7 +237,8 @@ if [ -z "$_NIXOS_REBUILD_REEXEC" ]; then fi # Re-execute nixos-rebuild from the Nixpkgs tree. -if [ -z "$_NIXOS_REBUILD_REEXEC" -a -n "$canRun" -a -z "$fast" ]; then +# FIXME: get nixos-rebuild from $flake. +if [[ -z $_NIXOS_REBUILD_REEXEC && -n $canRun && -z $fast && -z $flake ]]; then if p=$(nix-build --no-out-link --expr 'with import {}; config.system.build.nixos-rebuild' "${extraBuildFlags[@]}"); then export _NIXOS_REBUILD_REEXEC=1 exec $p/bin/nixos-rebuild "${origArgs[@]}" @@ -234,7 +246,23 @@ if [ -z "$_NIXOS_REBUILD_REEXEC" -a -n "$canRun" -a -z "$fast" ]; then fi fi +# For convenience, use the hostname as the default configuration to +# build from the flake. +if [[ -n $flake && -z $flakeAttr ]]; then + hostname=$(cat /proc/sys/kernel/hostname) + if [[ -z $hostname ]]; then + hostname=default + fi + flakeAttr="nixosConfigurations.\"$hostname\"" +fi + +# Resolve the flake. +if [[ -n $flake ]]; then + flake=$(nix flake info --json -- "$flake" | jq -r .uri) +fi + # Find configuration.nix and open editor instead of building. +# FIXME: handle flakes if [ "$action" = edit ]; then NIXOS_CONFIG=${NIXOS_CONFIG:-$(nix-instantiate --find-file nixos-config)} exec "${EDITOR:-nano}" "$NIXOS_CONFIG" @@ -296,7 +324,8 @@ prebuiltNix() { remotePATH= -if [ -n "$buildNix" ]; then +# FIXME: get nix from the flake. +if [[ -n $buildNix && -z $flake ]]; then echo "building Nix..." >&2 nixDrv= if ! nixDrv="$(nix-instantiate '' --add-root $tmpDir/nix.drv --indirect -A config.nix.package.out "${extraBuildFlags[@]}")"; then @@ -337,7 +366,7 @@ fi # Update the version suffix if we're building from Git (so that # nixos-version shows something useful). -if [ -n "$canRun" ]; then +if [[ -n $canRun && -z $flake ]]; then if nixpkgs=$(nix-instantiate --find-file nixpkgs "${extraBuildFlags[@]}"); then suffix=$($SHELL $nixpkgs/nixos/modules/installer/tools/get-version-suffix "${extraBuildFlags[@]}" || true) if [ -n "$suffix" ]; then @@ -356,17 +385,42 @@ fi # or "boot"), or just build it and create a symlink "result" in the # current directory (for "build" and "test"). if [ -z "$rollback" ]; then - echo "building the system configuration..." >&2 + if [[ -z $flake ]]; then + echo "building the system configuration..." >&2 + else + echo "building the system configuration '$flake:$flakeAttr'..." >&2 + fi if [ "$action" = switch -o "$action" = boot ]; then - pathToConfig="$(nixBuild '' --no-out-link -A system "${extraBuildFlags[@]}")" + if [[ -z $flake ]]; then + pathToConfig="$(nixBuild '' --no-out-link -A system "${extraBuildFlags[@]}")" + else + outLink=$tmpDir/result + nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink + pathToConfig="$(readlink -f $outLink)" + fi copyToTarget "$pathToConfig" targetHostCmd nix-env -p "$profile" --set "$pathToConfig" elif [ "$action" = test -o "$action" = build -o "$action" = dry-build -o "$action" = dry-activate ]; then - pathToConfig="$(nixBuild '' -A system -k "${extraBuildFlags[@]}")" + if [[ -z $flake ]]; then + pathToConfig="$(nixBuild '' -A system -k "${extraBuildFlags[@]}")" + else + nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" + pathToConfig="$(readlink -f ./result)" + fi elif [ "$action" = build-vm ]; then - pathToConfig="$(nixBuild '' -A vm -k "${extraBuildFlags[@]}")" + if [[ -z $flake ]]; then + pathToConfig="$(nixBuild '' -A vm -k "${extraBuildFlags[@]}")" + else + echo "TODO: not implemented" >&2 + exit 1 + fi elif [ "$action" = build-vm-with-bootloader ]; then - pathToConfig="$(nixBuild '' -A vmWithBootLoader -k "${extraBuildFlags[@]}")" + if [[ -z $flake ]]; then + pathToConfig="$(nixBuild '' -A vmWithBootLoader -k "${extraBuildFlags[@]}")" + else + echo "TODO: not implemented" >&2 + exit 1 + fi else showSyntax fi diff --git a/nixos/modules/installer/tools/tools.nix b/nixos/modules/installer/tools/tools.nix index 5df9c23e6b6..9c8e26ba242 100644 --- a/nixos/modules/installer/tools/tools.nix +++ b/nixos/modules/installer/tools/tools.nix @@ -31,6 +31,7 @@ let nix = config.nix.package.out; nix_x86_64_linux = fallback.x86_64-linux; nix_i686_linux = fallback.i686-linux; + path = makeBinPath [ pkgs.jq ]; }; nixos-generate-config = makeProg { From b91803bf135ce583a3115e5b7e4feb0333d96af1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 13 Sep 2019 18:26:38 +0200 Subject: [PATCH 15/39] nixosSystem: Automatically set version suffix from flake E.g. $ nixos-version 19.03.20190913.af5eb77 (Koi) --- flake.nix | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index f3bd9c8611b..b3903f3ae3d 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,19 @@ jobs = import ./pkgs/top-level/release.nix { nixpkgs = self; }; + lib = import ./lib; in { - lib = (import ./lib) // { - nixosSystem = import ./nixos/lib/eval-config.nix; + lib = lib // { + nixosSystem = { modules, ... } @ args: + import ./nixos/lib/eval-config.nix (args // { + modules = modules ++ + [ { system.nixos.versionSuffix = + ".${lib.substring 0 8 self.lastModified}.${self.shortRev}"; + system.nixos.revision = self.rev; + } + ]; + }); }; checks.tarball = jobs.tarball; From 855fcc324a5e83d3abced135d4b6ecad02cc022a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 13 Sep 2019 18:58:40 +0200 Subject: [PATCH 16/39] Add option system.configurationRevision to record revision of top-level flake --- nixos/modules/misc/version.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index 8a85035ceb7..8dbbbe6761c 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -84,6 +84,12 @@ in description = "Default NixOS channel to which the root user is subscribed."; }; + configurationRevision = mkOption { + type = types.nullOr types.str; + default = null; + description = "The Git revision of the top-level flake from which this configuration was built."; + }; + }; config = { From 7e9b745174092b5eee25890d5d377db58236d3dd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 13 Sep 2019 18:58:55 +0200 Subject: [PATCH 17/39] nixos-version: Add --json flag and show system.configurationRevision --- nixos/doc/manual/man-nixos-version.xml | 29 +++++++++++++++++-- .../modules/installer/tools/nixos-version.sh | 5 ++++ nixos/modules/installer/tools/tools.nix | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/nixos/doc/manual/man-nixos-version.xml b/nixos/doc/manual/man-nixos-version.xml index e9ad8bddcac..aada08c5b4a 100644 --- a/nixos/doc/manual/man-nixos-version.xml +++ b/nixos/doc/manual/man-nixos-version.xml @@ -12,16 +12,22 @@ - nixos-version + nixos-version - + + + + + + + Description @@ -84,12 +90,16 @@ + Options + This command accepts the following options: + + @@ -107,6 +117,21 @@ + + + + + + + + Print a JSON representation of the versions of NixOS and the + top-level configuration flake. + + + + + + diff --git a/nixos/modules/installer/tools/nixos-version.sh b/nixos/modules/installer/tools/nixos-version.sh index 190c49a33ec..0117aa1549c 100644 --- a/nixos/modules/installer/tools/nixos-version.sh +++ b/nixos/modules/installer/tools/nixos-version.sh @@ -8,6 +8,11 @@ case "$1" in --hash|--revision) echo "@revision@" ;; + --json) + cat < Date: Fri, 13 Sep 2019 19:01:23 +0200 Subject: [PATCH 18/39] Export nixosModules.notDetected --- flake.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake.nix b/flake.nix index b3903f3ae3d..3c0f6c31cd5 100644 --- a/flake.nix +++ b/flake.nix @@ -42,5 +42,9 @@ }; legacyPackages = pkgs; + + nixosModules = { + notDetected = ./nixos/modules/installer/scan/not-detected.nix; + }; }; } From cfd468adbb9b8b5430a6cecf02d8f6ff76e7360c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 19 Sep 2019 14:40:24 +0200 Subject: [PATCH 19/39] nixos-rebuild: Use /etc/nixos/flake.nix if it exists --- nixos/doc/manual/man-nixos-rebuild.xml | 40 ++++++++++++++----- .../modules/installer/tools/nixos-rebuild.sh | 6 +++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml index 81e2f8bb279..4341b8918df 100644 --- a/nixos/doc/manual/man-nixos-rebuild.xml +++ b/nixos/doc/manual/man-nixos-rebuild.xml @@ -140,14 +140,17 @@ Description - This command updates the system so that it corresponds to the configuration - specified in /etc/nixos/configuration.nix. Thus, every - time you modify /etc/nixos/configuration.nix or any - NixOS module, you must run nixos-rebuild to make the - changes take effect. It builds the new system in - /nix/store, runs its activation script, and stop and - (re)starts any system services if needed. Please note that user services need - to be started manually as they aren't detected by the activation script at the moment. + This command updates the system so that it corresponds to the + configuration specified in + /etc/nixos/configuration.nix or + /etc/nixos/flake.nix. Thus, every time you + modify the configuration or any other NixOS module, you must run + nixos-rebuild to make the changes take + effect. It builds the new system in + /nix/store, runs its activation script, and + stop and (re)starts any system services if needed. Please note that + user services need to be started manually as they aren't detected + by the activation script at the moment. @@ -526,8 +529,10 @@ - Build the NixOS system from the specified flake. The flake must - contain an output named + Build the NixOS system from the specified flake. It defaults to + the directory containing the target of the symlink + /etc/nixos/flake.nix, if it exists. The + flake must contain an output named nixosConfigurations.name, where name denotes the name of the configuration and can be specified using the @@ -594,6 +599,21 @@ + + + /etc/nixos/flake.nix + + + + If this file exists, then nixos-rebuild will + use it as if the option was given. This + file may be a symlink to a flake.nix in an + actual flake; thus /etc/nixos need not be a + flake. + + + + /run/current-system diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 949cd869146..18088e4f9ea 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -236,6 +236,12 @@ if [ -z "$_NIXOS_REBUILD_REEXEC" ]; then export PATH=@nix@/bin:$PATH fi +# Use /etc/nixos/flake.nix if it exists. It can be a symlink to the +# actual flake. +if [[ -z $flake && -e /etc/nixos/flake.nix ]]; then + flake="$(dirname "$(readlink -f /etc/nixos/flake.nix)")" +fi + # Re-execute nixos-rebuild from the Nixpkgs tree. # FIXME: get nixos-rebuild from $flake. if [[ -z $_NIXOS_REBUILD_REEXEC && -n $canRun && -z $fast && -z $flake ]]; then From 20087bd5534e115a1c7ddd5279610bc437c39046 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 19 Sep 2019 18:55:21 +0200 Subject: [PATCH 20/39] nixos-container: Add flake support E.g. to create a container that runs the NixOS homepage: $ nixos-container create homepage --flake nixos-homepage And to upgrade it: $ nixos-container update homepage --- .../nixos-container/nixos-container.pl | 71 +++++++++++++++---- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/pkgs/tools/virtualization/nixos-container/nixos-container.pl b/pkgs/tools/virtualization/nixos-container/nixos-container.pl index 2a9625501b6..392d59486c1 100755 --- a/pkgs/tools/virtualization/nixos-container/nixos-container.pl +++ b/pkgs/tools/virtualization/nixos-container/nixos-container.pl @@ -22,13 +22,27 @@ $ENV{"NIXOS_CONFIG"} = ""; sub showHelp { print < [--nixos-path ] [--system-path ] [--config-file ] [--config ] [--ensure-unique-name] [--auto-start] [--bridge ] [--port ] [--host-address ] [--local-address ] + nixos-container create + [--nixos-path ] + [--system-path ] + [--config ] + [--config-file ] + [--flake ] + [--ensure-unique-name] + [--auto-start] + [--bridge ] + [--port ] + [--host-address ] + [--local-address ] nixos-container destroy nixos-container start nixos-container stop nixos-container terminate nixos-container status - nixos-container update [--config ] [--config-file ] + nixos-container update + [--config ] + [--config-file ] + [--flake ] nixos-container login nixos-container root-login nixos-container run -- args... @@ -49,6 +63,7 @@ my $signal; my $configFile; my $hostAddress; my $localAddress; +my $flake; GetOptions( "help" => sub { showHelp() }, @@ -63,6 +78,7 @@ GetOptions( "config-file=s" => \$configFile, "host-address=s" => \$hostAddress, "local-address=s" => \$localAddress, + "flake=s" => \$flake, ) or exit 1; if (defined $hostAddress and !defined $localAddress or defined $localAddress and !defined $hostAddress) { @@ -97,8 +113,6 @@ sub writeNixOSConfig { my $localExtraConfig = ""; - - if ($extraConfig) { $localExtraConfig = $extraConfig } elsif ($configFile) { @@ -121,6 +135,14 @@ EOF write_file($nixosConfigFile, $nixosConfig); } +sub buildFlake { + system("nix", "build", "-o", "$systemPath.tmp", "--", + "$flake:nixosConfigurations.container.config.system.build.toplevel") == 0 + or die "$0: failed to build container from flake '$flake'\n"; + $systemPath = readlink("$systemPath.tmp") or die; + unlink("$systemPath.tmp"); +} + if ($action eq "create") { # Acquire an exclusive lock to prevent races with other # invocations of ‘nixos-container create’. @@ -176,6 +198,7 @@ if ($action eq "create") { push @conf, "HOST_BRIDGE=$bridge\n"; push @conf, "HOST_PORT=$port\n"; push @conf, "AUTO_START=$autoStart\n"; + push @conf, "FLAKE=$flake\n" if defined $flake; write_file($confFile, \@conf); close($lock); @@ -191,6 +214,10 @@ if ($action eq "create") { mkpath($profileDir, 0, 0755); # Build/set the initial configuration. + if (defined $flake) { + buildFlake(); + } + if (defined $systemPath) { system("nix-env", "-p", "$profileDir/system", "--set", $systemPath) == 0 or die "$0: failed to set initial container configuration\n"; @@ -326,19 +353,35 @@ elsif ($action eq "status") { } elsif ($action eq "update") { - my $nixosConfigFile = "$root/etc/nixos/configuration.nix"; - # FIXME: may want to be more careful about clobbering the existing - # configuration.nix. - if ((defined $extraConfig && $extraConfig ne "") || - (defined $configFile && $configFile ne "")) { - writeNixOSConfig $nixosConfigFile; + # Unless overriden on the command line, rebuild the flake recorded + # in the container config file. FIXME: read the container config + # in a more sensible way. + if (!defined $flake && !defined $configFile && !defined $extraConfig) { + my $s = read_file($confFile); + $s =~ /^FLAKE=(.*)$/m; + $flake = $1; } - system("nix-env", "-p", "$profileDir/system", - "-I", "nixos-config=$nixosConfigFile", "-f", "", - "--set", "-A", "system") == 0 - or die "$0: failed to build container configuration\n"; + if (defined $flake) { + buildFlake(); + system("nix-env", "-p", "$profileDir/system", "--set", $systemPath) == 0 + or die "$0: failed to set container configuration\n"; + } else { + my $nixosConfigFile = "$root/etc/nixos/configuration.nix"; + + # FIXME: may want to be more careful about clobbering the existing + # configuration.nix. + if ((defined $extraConfig && $extraConfig ne "") || + (defined $configFile && $configFile ne "")) { + writeNixOSConfig $nixosConfigFile; + } + + system("nix-env", "-p", "$profileDir/system", + "-I", "nixos-config=$nixosConfigFile", "-f", "", + "--set", "-A", "system") == 0 + or die "$0: failed to build container configuration\n"; + } if (isContainerRunning) { print STDERR "reloading container...\n"; From fb051f0dece79d2ac28ad368d6e26289d780bc0a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 20 Sep 2019 18:37:17 +0200 Subject: [PATCH 21/39] nixos-{rebuild,container}: Use flakeref#attrpath syntax This makes them consistent with the 'nix' command line. --- nixos/doc/manual/man-nixos-rebuild.xml | 25 +++------------ .../modules/installer/tools/nixos-rebuild.sh | 32 +++++++++---------- .../nixos-container/nixos-container.pl | 8 ++++- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml index 4341b8918df..f4f663b84f0 100644 --- a/nixos/doc/manual/man-nixos-rebuild.xml +++ b/nixos/doc/manual/man-nixos-rebuild.xml @@ -83,10 +83,6 @@ flake-uri - - name - - @@ -525,7 +521,7 @@ - flake-uri + flake-uri[name] @@ -533,22 +529,9 @@ the directory containing the target of the symlink /etc/nixos/flake.nix, if it exists. The flake must contain an output named - nixosConfigurations.name, - where name denotes the name of the - configuration and can be specified using the - option. - - - - - - - name - - - - Specifies which NixOS configuration to use from the - flake. Defaults to the current hostname. + nixosConfigurations.name. If + name is omitted, it default to the + current host name. diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 18088e4f9ea..b681a170b6b 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -100,10 +100,6 @@ while [ "$#" -gt 0 ]; do flake="$1" shift 1 ;; - --config) - flakeAttr="nixosConfigurations.$1" - shift 1 - ;; *) echo "$0: unknown option \`$i'" exit 1 @@ -254,12 +250,20 @@ fi # For convenience, use the hostname as the default configuration to # build from the flake. -if [[ -n $flake && -z $flakeAttr ]]; then - hostname=$(cat /proc/sys/kernel/hostname) - if [[ -z $hostname ]]; then - hostname=default +if [[ -n $flake ]]; then + if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then + flake="${BASH_REMATCH[1]}" + flakeAttr="${BASH_REMATCH[2]}" + fi + if [[ -z $flakeAttr ]]; then + hostname=$(cat /proc/sys/kernel/hostname) + if [[ -z $hostname ]]; then + hostname=default + fi + flakeAttr="nixosConfigurations.\"$hostname\"" + else + flakeAttr="nixosConfigurations.\"$flakeAttr\"" fi - flakeAttr="nixosConfigurations.\"$hostname\"" fi # Resolve the flake. @@ -391,17 +395,13 @@ fi # or "boot"), or just build it and create a symlink "result" in the # current directory (for "build" and "test"). if [ -z "$rollback" ]; then - if [[ -z $flake ]]; then - echo "building the system configuration..." >&2 - else - echo "building the system configuration '$flake:$flakeAttr'..." >&2 - fi + echo "building the system configuration..." >&2 if [ "$action" = switch -o "$action" = boot ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '' --no-out-link -A system "${extraBuildFlags[@]}")" else outLink=$tmpDir/result - nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink + nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink pathToConfig="$(readlink -f $outLink)" fi copyToTarget "$pathToConfig" @@ -410,7 +410,7 @@ if [ -z "$rollback" ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '' -A system -k "${extraBuildFlags[@]}")" else - nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" + nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" pathToConfig="$(readlink -f ./result)" fi elif [ "$action" = build-vm ]; then diff --git a/pkgs/tools/virtualization/nixos-container/nixos-container.pl b/pkgs/tools/virtualization/nixos-container/nixos-container.pl index 392d59486c1..727c0333b27 100755 --- a/pkgs/tools/virtualization/nixos-container/nixos-container.pl +++ b/pkgs/tools/virtualization/nixos-container/nixos-container.pl @@ -64,6 +64,7 @@ my $configFile; my $hostAddress; my $localAddress; my $flake; +my $flakeAttr = "container"; GetOptions( "help" => sub { showHelp() }, @@ -92,6 +93,11 @@ if (defined $configFile and defined $extraConfig) { "Please define on or the other, but not both"; } +if (defined $flake && $flake =~ /^(.*)#([^#"]+)$/) { + $flake = $1; + $flakeAttr = $2; +} + # Execute the selected action. mkpath("/etc/containers", 0, 0755); @@ -137,7 +143,7 @@ EOF sub buildFlake { system("nix", "build", "-o", "$systemPath.tmp", "--", - "$flake:nixosConfigurations.container.config.system.build.toplevel") == 0 + "$flake#nixosConfigurations.\"$flakeAttr\".config.system.build.toplevel") == 0 or die "$0: failed to build container from flake '$flake'\n"; $systemPath = readlink("$systemPath.tmp") or die; unlink("$systemPath.tmp"); From bda94ae808b8864a0e58b60830c505084c752462 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Oct 2019 14:56:51 +0200 Subject: [PATCH 22/39] epoch -> edition --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 3c0f6c31cd5..c3defdeceab 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - epoch = 201909; + edition = 201909; description = "A collection of packages for the Nix package manager"; From 98e322b929bdc141c630d5c615d18ed487d4abd6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Oct 2019 20:46:10 +0200 Subject: [PATCH 23/39] nixos-rebuild: uri -> url --- nixos/modules/installer/tools/nixos-rebuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index b681a170b6b..ec9dd9b71d4 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -268,7 +268,7 @@ fi # Resolve the flake. if [[ -n $flake ]]; then - flake=$(nix flake info --json -- "$flake" | jq -r .uri) + flake=$(nix flake info --json -- "$flake" | jq -r .url) fi # Find configuration.nix and open editor instead of building. From 2452042c47859666c2ad89fdfd47e5c0a55c0af2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Oct 2019 20:48:43 +0200 Subject: [PATCH 24/39] nixos-rebuild: Support -L flag --- nixos/modules/installer/tools/nixos-rebuild.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index ec9dd9b71d4..8d69bbfd14c 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -61,7 +61,7 @@ while [ "$#" -gt 0 ]; do j="$1"; shift 1 extraBuildFlags+=("$i" "$j") ;; - --show-trace|--keep-failed|-K|--keep-going|-k|--verbose|-v|-vv|-vvv|-vvvv|-vvvvv|--fallback|--repair|--no-build-output|-Q|-j*) + --show-trace|--keep-failed|-K|--keep-going|-k|--verbose|-v|-vv|-vvv|-vvvv|-vvvvv|--fallback|--repair|--no-build-output|-Q|-j*|-L) extraBuildFlags+=("$i") ;; --option) @@ -268,7 +268,7 @@ fi # Resolve the flake. if [[ -n $flake ]]; then - flake=$(nix flake info --json -- "$flake" | jq -r .url) + flake=$(nix flake info --json "${extraBuildFlags[@]}" -- "$flake" | jq -r .url) fi # Find configuration.nix and open editor instead of building. @@ -401,7 +401,8 @@ if [ -z "$rollback" ]; then pathToConfig="$(nixBuild '' --no-out-link -A system "${extraBuildFlags[@]}")" else outLink=$tmpDir/result - nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink + nix build "$flake#$flakeAttr.config.system.build.toplevel" \ + --keep-going "${extraBuildFlags[@]}" --out-link $outLink pathToConfig="$(readlink -f $outLink)" fi copyToTarget "$pathToConfig" From 0bf1ab421bb166cba1e4aa4f28ea17f2184f9215 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 15 Oct 2019 13:50:44 +0200 Subject: [PATCH 25/39] flake.nix: Remove packages, builders outputs --- flake.nix | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index c3defdeceab..599aa0352b7 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,6 @@ outputs = { self }: let - pkgs = import ./. { system = "x86_64-linux"; }; jobs = import ./pkgs/top-level/release.nix { nixpkgs = self; }; @@ -26,10 +25,6 @@ checks.tarball = jobs.tarball; - builders = { - inherit (pkgs) stdenv fetchurl; - }; - htmlDocs = { nixpkgsManual = jobs.manual; nixosManual = (import ./nixos/release-small.nix { @@ -37,11 +32,7 @@ }).nixos.manual.x86_64-linux; }; - packages = { - inherit (pkgs) hello nix fuse nlohmann_json boost firefox; - }; - - legacyPackages = pkgs; + legacyPackages = import ./. { system = "x86_64-linux"; }; nixosModules = { notDetected = ./nixos/modules/installer/scan/not-detected.nix; From 7ff2e743e81214665e80dba3462292019999a45a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 15 Oct 2019 18:17:21 +0200 Subject: [PATCH 26/39] flake.nix: Support more systems --- flake.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 599aa0352b7..3f9e22bdae0 100644 --- a/flake.nix +++ b/flake.nix @@ -5,10 +5,17 @@ outputs = { self }: let + jobs = import ./pkgs/top-level/release.nix { nixpkgs = self; }; + lib = import ./lib; + + systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" ]; + + forAllSystems = f: lib.genAttrs systems (system: f system); + in { lib = lib // { @@ -32,7 +39,7 @@ }).nixos.manual.x86_64-linux; }; - legacyPackages = import ./. { system = "x86_64-linux"; }; + legacyPackages = forAllSystems (system: import ./. { inherit system; }); nixosModules = { notDetected = ./nixos/modules/installer/scan/not-detected.nix; From 2a0cf385d26544d80a29ebf7e34f63e86f397283 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 1 Feb 2020 12:11:22 +0100 Subject: [PATCH 27/39] nixos-rebuild: Avoid subshell reading hostname MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Jörg Thalheim --- nixos/modules/installer/tools/nixos-rebuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 8d69bbfd14c..4bbed9e6971 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -256,7 +256,7 @@ if [[ -n $flake ]]; then flakeAttr="${BASH_REMATCH[2]}" fi if [[ -z $flakeAttr ]]; then - hostname=$(cat /proc/sys/kernel/hostname) + read -r hostname < /proc/sys/kernel/hostname if [[ -z $hostname ]]; then hostname=default fi From 60330b60655b3fa3a18624bdd7069855bb37af99 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 5 Feb 2020 16:00:27 +0100 Subject: [PATCH 28/39] flake.nix: Handle missing rev attribute Dirty trees no longer set 'rev', so we need to handle this. --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 3f9e22bdae0..e2346f99c7a 100644 --- a/flake.nix +++ b/flake.nix @@ -23,8 +23,8 @@ import ./nixos/lib/eval-config.nix (args // { modules = modules ++ [ { system.nixos.versionSuffix = - ".${lib.substring 0 8 self.lastModified}.${self.shortRev}"; - system.nixos.revision = self.rev; + ".${lib.substring 0 8 self.lastModified}.${self.shortRev or "dirty"}"; + system.nixos.revision = lib.mkIf (self ? rev) self.rev; } ]; }); From c08930874a37d5dea5985498d4ff6dec7e9069cc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 5 Feb 2020 16:00:58 +0100 Subject: [PATCH 29/39] nixos-rebuild: Propagate various flake lock file flags And also --refresh and --no-net. --- .../modules/installer/tools/nixos-rebuild.sh | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 4bbed9e6971..88c5cb4a443 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -16,6 +16,7 @@ showSyntax() { # Parse the command line. origArgs=("$@") extraBuildFlags=() +lockFlags=() action= buildNix=1 fast= @@ -61,7 +62,7 @@ while [ "$#" -gt 0 ]; do j="$1"; shift 1 extraBuildFlags+=("$i" "$j") ;; - --show-trace|--keep-failed|-K|--keep-going|-k|--verbose|-v|-vv|-vvv|-vvvv|-vvvvv|--fallback|--repair|--no-build-output|-Q|-j*|-L) + --show-trace|--keep-failed|-K|--keep-going|-k|--verbose|-v|-vv|-vvv|-vvvv|-vvvvv|--fallback|--repair|--no-build-output|-Q|-j*|-L|--refresh|--no-net) extraBuildFlags+=("$i") ;; --option) @@ -100,6 +101,18 @@ while [ "$#" -gt 0 ]; do flake="$1" shift 1 ;; + --recreate-lock-file|--no-update-lock-file|--no-write-lock-file|--no-registries|--commit-lock-file) + lockFlags+=("$i") + ;; + --update-input) + j="$1"; shift 1 + lockFlags+=("$i" "$j") + ;; + --override-input) + j="$1"; shift 1 + k="$1"; shift 1 + lockFlags+=("$i" "$j" "$k") + ;; *) echo "$0: unknown option \`$i'" exit 1 @@ -268,7 +281,7 @@ fi # Resolve the flake. if [[ -n $flake ]]; then - flake=$(nix flake info --json "${extraBuildFlags[@]}" -- "$flake" | jq -r .url) + flake=$(nix flake info --json "${extraBuildFlags[@]}" "${lockFlags[@]}" -- "$flake" | jq -r .url) fi # Find configuration.nix and open editor instead of building. @@ -402,7 +415,7 @@ if [ -z "$rollback" ]; then else outLink=$tmpDir/result nix build "$flake#$flakeAttr.config.system.build.toplevel" \ - --keep-going "${extraBuildFlags[@]}" --out-link $outLink + --keep-going "${extraBuildFlags[@]}" "${lockFlags[@]}" --out-link $outLink pathToConfig="$(readlink -f $outLink)" fi copyToTarget "$pathToConfig" @@ -411,7 +424,7 @@ if [ -z "$rollback" ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '' -A system -k "${extraBuildFlags[@]}")" else - nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" + nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" "${lockFlags[@]}" pathToConfig="$(readlink -f ./result)" fi elif [ "$action" = build-vm ]; then From 4089dbf090eb3cd2a2286e496c3f7491ae27f6f7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 7 Feb 2020 15:26:12 +0100 Subject: [PATCH 30/39] nixos-rebuild: Make 'edit' work with with flakes --- nixos/modules/installer/tools/nixos-rebuild.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 88c5cb4a443..cc86fa25b60 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -285,10 +285,13 @@ if [[ -n $flake ]]; then fi # Find configuration.nix and open editor instead of building. -# FIXME: handle flakes if [ "$action" = edit ]; then - NIXOS_CONFIG=${NIXOS_CONFIG:-$(nix-instantiate --find-file nixos-config)} - exec "${EDITOR:-nano}" "$NIXOS_CONFIG" + if [[ -z $flake ]]; then + NIXOS_CONFIG=${NIXOS_CONFIG:-$(nix-instantiate --find-file nixos-config)} + exec "${EDITOR:-nano}" "$NIXOS_CONFIG" + else + exec nix edit "${lockFlags[@]}" -- "$flake#$flakeAttr" + fi exit 1 fi From f9392f04aef1d534e5baa6f136264270f050be5d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 7 Feb 2020 19:49:01 +0100 Subject: [PATCH 31/39] nixos-rebuild: Remove --keep-going flag --- nixos/modules/installer/tools/nixos-rebuild.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index cc86fa25b60..0ba3930ab99 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -418,7 +418,7 @@ if [ -z "$rollback" ]; then else outLink=$tmpDir/result nix build "$flake#$flakeAttr.config.system.build.toplevel" \ - --keep-going "${extraBuildFlags[@]}" "${lockFlags[@]}" --out-link $outLink + "${extraBuildFlags[@]}" "${lockFlags[@]}" --out-link $outLink pathToConfig="$(readlink -f $outLink)" fi copyToTarget "$pathToConfig" @@ -427,7 +427,7 @@ if [ -z "$rollback" ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '' -A system -k "${extraBuildFlags[@]}")" else - nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" "${lockFlags[@]}" + nix build "$flake#$flakeAttr.config.system.build.toplevel" "${extraBuildFlags[@]}" "${lockFlags[@]}" pathToConfig="$(readlink -f ./result)" fi elif [ "$action" = build-vm ]; then From b98ea4560899470536506426a74704a907fcfc8f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2020 15:25:24 +0100 Subject: [PATCH 32/39] nixos-version --json: Use builtins.toJSON --- nixos/modules/installer/tools/nixos-version.sh | 2 +- nixos/modules/installer/tools/tools.nix | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-version.sh b/nixos/modules/installer/tools/nixos-version.sh index 0117aa1549c..2711bc1e131 100644 --- a/nixos/modules/installer/tools/nixos-version.sh +++ b/nixos/modules/installer/tools/nixos-version.sh @@ -10,7 +10,7 @@ case "$1" in ;; --json) cat < Date: Mon, 10 Feb 2020 15:25:44 +0100 Subject: [PATCH 33/39] nixos.revision: Use null instead of "master" "master" is not a valid SHA-1 commit hash, and it's not even necessarily the branch used. 'nixos-version --revision' now returns an error if the commit hash is not known. --- nixos/modules/installer/tools/nixos-version.sh | 4 ++++ nixos/modules/misc/version.nix | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-version.sh b/nixos/modules/installer/tools/nixos-version.sh index 2711bc1e131..bde6c9c3003 100644 --- a/nixos/modules/installer/tools/nixos-version.sh +++ b/nixos/modules/installer/tools/nixos-version.sh @@ -6,6 +6,10 @@ case "$1" in exit 1 ;; --hash|--revision) + if ! [[ @revision@ =~ /[0-9a-f]+/ ]]; then + echo "$0: Nixpkgs commit hash is unknown" + exit 1 + fi echo "@revision@" ;; --json) diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index 8dbbbe6761c..c394ff592f4 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -42,8 +42,8 @@ in nixos.revision = mkOption { internal = true; - type = types.str; - default = trivial.revisionWithDefault "master"; + type = types.nullOr types.str; + default = trivial.revisionWithDefault null; description = "The Git revision from which this NixOS configuration was built."; }; From 8f86624ac95de33f3bdd08b9f0d3a9096f7755c4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2020 15:31:23 +0100 Subject: [PATCH 34/39] nixos-rebuild: Remove TODOs --- nixos/modules/installer/tools/nixos-rebuild.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 0ba3930ab99..354274478a3 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -222,7 +222,7 @@ fi # If ‘--upgrade’ is given, run ‘nix-channel --update nixos’. -if [ -n "$upgrade" -a -z "$_NIXOS_REBUILD_REEXEC" ]; then +if [[ -n $upgrade && -z $_NIXOS_REBUILD_REEXEC && -z $flake ]]; then nix-channel --update nixos # If there are other channels that contain a file called @@ -350,7 +350,6 @@ prebuiltNix() { remotePATH= -# FIXME: get nix from the flake. if [[ -n $buildNix && -z $flake ]]; then echo "building Nix..." >&2 nixDrv= @@ -434,14 +433,14 @@ if [ -z "$rollback" ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '' -A vm -k "${extraBuildFlags[@]}")" else - echo "TODO: not implemented" >&2 + echo "$0: 'build-vm' is not supported with '--flake'" >&2 exit 1 fi elif [ "$action" = build-vm-with-bootloader ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '' -A vmWithBootLoader -k "${extraBuildFlags[@]}")" else - echo "TODO: not implemented" >&2 + echo "$0: 'build-vm-with-bootloader' is not supported with '--flake'" >&2 exit 1 fi else From a274da605de4dcdf3eeb1bc63967d3098505dc12 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2020 16:20:41 +0100 Subject: [PATCH 35/39] lib/tests/misc.nix: Fix dependency on currentSystem This doesn't work in pure mode. --- lib/tests/misc.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 59ed1e507e2..01ff5ecf148 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -148,7 +148,7 @@ runTests { "${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11"; in { storePath = isStorePath goodPath; - storePathDerivation = isStorePath (import ../.. {}).hello; + storePathDerivation = isStorePath (import ../.. { system = "x86_64-linux"; }).hello; storePathAppendix = isStorePath "${goodPath}/bin/python"; nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath))); From 5c389f84d42538f41e3e9a73b5e6bee645d45ebf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2020 16:21:04 +0100 Subject: [PATCH 36/39] lib/tests/misc.nix: Don't make a copy on Nixpkgs --- lib/tests/release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/release.nix b/lib/tests/release.nix index 737d142d253..069c015d783 100644 --- a/lib/tests/release.nix +++ b/lib/tests/release.nix @@ -2,7 +2,7 @@ pkgs.runCommandNoCC "nixpkgs-lib-tests" { buildInputs = [ pkgs.nix (import ./check-eval.nix) ]; - NIX_PATH="nixpkgs=${pkgs.path}"; + NIX_PATH = "nixpkgs=${toString pkgs.path}"; } '' datadir="${pkgs.nix}/share" export TEST_ROOT=$(pwd)/test-tmp From 64e5f4d53b2740bffb16641f703b9cf0df58b84e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2020 16:25:33 +0100 Subject: [PATCH 37/39] Fix 'nix flake check' --- flake.nix | 4 ++-- pkgs/top-level/make-tarball.nix | 4 ++-- pkgs/top-level/release.nix | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index e2346f99c7a..197b6e2056e 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ }); }; - checks.tarball = jobs.tarball; + checks.x86_64-linux.tarball = jobs.tarball; htmlDocs = { nixpkgsManual = jobs.manual; @@ -42,7 +42,7 @@ legacyPackages = forAllSystems (system: import ./. { inherit system; }); nixosModules = { - notDetected = ./nixos/modules/installer/scan/not-detected.nix; + notDetected = import ./nixos/modules/installer/scan/not-detected.nix; }; }; } diff --git a/pkgs/top-level/make-tarball.nix b/pkgs/top-level/make-tarball.nix index 7bb18e765f1..ff0b0568819 100644 --- a/pkgs/top-level/make-tarball.nix +++ b/pkgs/top-level/make-tarball.nix @@ -20,7 +20,7 @@ releaseTools.sourceTarball { versionSuffix = "pre${ if nixpkgs ? lastModified then builtins.substring 0 8 nixpkgs.lastModified - else toString nixpkgs.revCount}.${nixpkgs.shortRev}"; + else toString nixpkgs.revCount}.${nixpkgs.shortRev or "dirty"}"; buildInputs = [ nix.out jq lib-tests ]; @@ -28,7 +28,7 @@ releaseTools.sourceTarball { eval "$preConfigure" releaseName=nixpkgs-$VERSION$VERSION_SUFFIX echo -n $VERSION_SUFFIX > .version-suffix - echo -n ${nixpkgs.rev or nixpkgs.shortRev} > .git-revision + echo -n ${nixpkgs.rev or nixpkgs.shortRev or "dirty"} > .git-revision echo "release name is $releaseName" echo "git-revision is $(cat .git-revision)" ''; diff --git a/pkgs/top-level/release.nix b/pkgs/top-level/release.nix index b8ce1fcbce5..78d70c0239a 100644 --- a/pkgs/top-level/release.nix +++ b/pkgs/top-level/release.nix @@ -14,9 +14,9 @@ , supportedSystems ? [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ] , limitedSupportedSystems ? [ "i686-linux" ] # Strip most of attributes when evaluating to spare memory usage -, scrubJobs ? true +, scrubJobs ? true # Attributes passed to nixpkgs. Don't build packages marked as unfree. -, nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; } +, nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; } }: with import ./release-lib.nix { inherit supportedSystems scrubJobs nixpkgsArgs; }; From fb05afd78dc63fa93626ee51330c69559754b44d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2020 16:32:59 +0100 Subject: [PATCH 38/39] Doh --- nixos/modules/installer/tools/nixos-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-version.sh b/nixos/modules/installer/tools/nixos-version.sh index bde6c9c3003..fb0fe26116a 100644 --- a/nixos/modules/installer/tools/nixos-version.sh +++ b/nixos/modules/installer/tools/nixos-version.sh @@ -6,7 +6,7 @@ case "$1" in exit 1 ;; --hash|--revision) - if ! [[ @revision@ =~ /[0-9a-f]+/ ]]; then + if ! [[ @revision@ =~ ^[0-9a-f]+$ ]]; then echo "$0: Nixpkgs commit hash is unknown" exit 1 fi From a1fa9e65cab889c4f45e5966d25e45639fc3381b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Feb 2020 16:36:53 +0100 Subject: [PATCH 39/39] flake.nix: Add note --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 197b6e2056e..a6828c98fb5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,3 +1,5 @@ +# Experimental flake interface to Nixpkgs. +# See https://github.com/NixOS/rfcs/pull/49 for details. { edition = 201909;