Unverified Commit 927b67cd authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

nixos/tools: continue cleanup (#343466)

parents aa1433bb 1f9fc918
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6,13 +6,13 @@ tedious, so here is a quick way to see if the installer works properly:
```ShellSession
# mount -t tmpfs none /mnt
# nixos-generate-config --root /mnt
$ nix-build '<nixpkgs/nixos>' -A config.system.build.nixos-install
$ nix-build '<nixpkgs>' -A nixos-install
# ./result/bin/nixos-install
```

To start a login shell in the new NixOS installation in `/mnt`:

```ShellSession
$ nix-build '<nixpkgs/nixos>' -A config.system.build.nixos-enter
$ nix-build '<nixpkgs>' -A nixos-enter
# ./result/bin/nixos-enter
```
+1 −1
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ let format' = format; in let
      e2fsprogs
      lkl
      config.system.build.nixos-install
      config.system.build.nixos-enter
      nixos-enter
      nix
      systemdMinimal
    ]
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ let

  tools = lib.makeBinPath (
    with pkgs; [
      config.system.build.nixos-enter
      nixos-enter
      config.system.build.nixos-install
      dosfstools
      e2fsprogs
+1 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ let

  tools = lib.makeBinPath (
    with pkgs; [
      config.system.build.nixos-enter
      nixos-enter
      config.system.build.nixos-install
      dosfstools
      e2fsprogs
+171 −159
Original line number Diff line number Diff line
@@ -3,8 +3,6 @@

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

with lib;

let
  makeProg = args: pkgs.substituteAll (args // {
    dir = "bin";
@@ -17,11 +15,6 @@ let
    '';
  });

  inherit (pkgs) nixos-build-vms;

  nixos-install = pkgs.nixos-install.override { nix = config.nix.package; };
  nixos-rebuild = pkgs.nixos-rebuild.override { nix = config.nix.package.out; };

  nixos-generate-config = makeProg {
    name = "nixos-generate-config";
    src = ./nixos-generate-config.pl;
@@ -34,8 +27,6 @@ let
    manPage = ./manpages/nixos-generate-config.8;
  };

  inherit (pkgs) nixos-option;

  nixos-version = makeProg {
    name = "nixos-version";
    src = ./nixos-version.sh;
@@ -44,69 +35,18 @@ let
    inherit (config.system) configurationRevision;
    json = builtins.toJSON ({
      nixosVersion = config.system.nixos.version;
    } // optionalAttrs (config.system.nixos.revision != null) {
    } // lib.optionalAttrs (config.system.nixos.revision != null) {
      nixpkgsRevision = config.system.nixos.revision;
    } // optionalAttrs (config.system.configurationRevision != null) {
    } // lib.optionalAttrs (config.system.configurationRevision != null) {
      configurationRevision = config.system.configurationRevision;
    });
    manPage = ./manpages/nixos-version.8;
  };

  inherit (pkgs) nixos-enter;
in

{

  options.system.nixos-generate-config = {
    configuration = mkOption {
      internal = true;
      type = types.str;
      description = ''
        The NixOS module that `nixos-generate-config`
        saves to `/etc/nixos/configuration.nix`.

        This is an internal option. No backward compatibility is guaranteed.
        Use at your own risk!

        Note that this string gets spliced into a Perl script. The perl
        variable `$bootLoaderConfig` can be used to
        splice in the boot loader configuration.
      '';
    };

    desktopConfiguration = mkOption {
      internal = true;
      type = types.listOf types.lines;
      default = [];
      description = ''
        Text to preseed the desktop configuration that `nixos-generate-config`
        saves to `/etc/nixos/configuration.nix`.

        This is an internal option. No backward compatibility is guaranteed.
        Use at your own risk!

        Note that this string gets spliced into a Perl script. The perl
        variable `$bootLoaderConfig` can be used to
        splice in the boot loader configuration.
      '';
    };
  };

  options.system.disableInstallerTools = mkOption {
    internal = true;
    type = types.bool;
    default = false;
    description = ''
      Disable nixos-rebuild, nixos-generate-config, nixos-installer
      and other NixOS tools. This is useful to shrink embedded,
      read-only systems which are not expected to be rebuild or
      reconfigure themselves. Use at your own risk!
    '';
  };

  config = lib.mkMerge [ (lib.mkIf (config.nix.enable && !config.system.disableInstallerTools) {
  nixos-install = pkgs.nixos-install.override { nix = config.nix.package; };
  nixos-rebuild = pkgs.nixos-rebuild.override { nix = config.nix.package; };

    system.nixos-generate-config.configuration = mkDefault ''
  defaultConfigTemplate = ''
    # Edit this configuration file to define what should be installed on
    # your system. Help is available in the configuration.nix(5) man page, on
    # https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
@@ -223,26 +163,98 @@ in

    }
  '';
in
{
  options.system.nixos-generate-config = {
    configuration = lib.mkOption {
      internal = true;
      type = lib.types.str;
      default = defaultConfigTemplate;
      description = ''
        The NixOS module that `nixos-generate-config`
        saves to `/etc/nixos/configuration.nix`.

        This is an internal option. No backward compatibility is guaranteed.
        Use at your own risk!

        Note that this string gets spliced into a Perl script. The perl
        variable `$bootLoaderConfig` can be used to
        splice in the boot loader configuration.
      '';
    };

    environment.systemPackages =
      [ nixos-build-vms
        nixos-install
        nixos-rebuild
        nixos-generate-config
        nixos-option
        nixos-version
        nixos-enter
      ];
    desktopConfiguration = lib.mkOption {
      internal = true;
      type = lib.types.listOf lib.types.lines;
      default = [];
      description = ''
        Text to preseed the desktop configuration that `nixos-generate-config`
        saves to `/etc/nixos/configuration.nix`.

    documentation.man.man-db.skipPackages = [ nixos-version ];
        This is an internal option. No backward compatibility is guaranteed.
        Use at your own risk!

        Note that this string gets spliced into a Perl script. The perl
        variable `$bootLoaderConfig` can be used to
        splice in the boot loader configuration.
      '';
    };
  };

  options.system.disableInstallerTools = lib.mkOption {
    internal = true;
    type = lib.types.bool;
    default = false;
    description = ''
      Disable nixos-rebuild, nixos-generate-config, nixos-installer
      and other NixOS tools. This is useful to shrink embedded,
      read-only systems which are not expected to be rebuild or
      reconfigure themselves. Use at your own risk!
    '';
  };

  imports = let
    mkToolModule = { name, package ? pkgs.${name} }: { config, ... }: {
      options.system.tools.${name}.enable = lib.mkEnableOption "${name} script" // {
        default = true;
        internal = true;
      };

      config = lib.mkIf config.system.tools.${name}.enable {
        environment.systemPackages = [ package ];
      };
    };
  in [
    (mkToolModule { name = "nixos-build-vms"; })
    (mkToolModule { name = "nixos-enter"; })
    (mkToolModule { name = "nixos-generate-config"; package = nixos-generate-config; })
    (mkToolModule { name = "nixos-install"; package = nixos-install; })
    (mkToolModule { name = "nixos-option"; })
    (mkToolModule { name = "nixos-rebuild"; package = nixos-rebuild; })
    (mkToolModule { name = "nixos-version"; package = nixos-version; })
  ];

  config = lib.mkMerge [
    (lib.mkIf config.system.disableInstallerTools {
      system.tools = {
        nixos-build-vms.enable = false;
        nixos-enter.enable = false;
        nixos-generate-config.enable = false;
        nixos-install.enable = false;
        nixos-option.enable = false;
        nixos-rebuild.enable = false;
        nixos-version.enable = false;
      };
    })
    {
      documentation.man.man-db.skipPackages = [ nixos-version ];

      # These may be used in auxiliary scripts (ie not part of toplevel), so they are defined unconditionally.
  ({
      system.build = {
      inherit nixos-install nixos-generate-config nixos-option nixos-rebuild nixos-enter;
        inherit nixos-generate-config nixos-install nixos-rebuild;
        nixos-option = lib.warn "Accessing nixos-option through `config.system.build` is deprecated, use `pkgs.nixos-option` instead." pkgs.nixos-option;
        nixos-enter = lib.warn "Accessing nixos-enter through `config.system.build` is deprecated, use `pkgs.nixos-enter` instead." pkgs.nixos-enter;
      };
  })];

    }
  ];
}