From 187534454271910dcc023a9b0a0c27e9e79ecade Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 9 Oct 2018 23:10:45 +0200 Subject: [PATCH] nixos-*: init as package Move all the nixos-* scripts from the nixos distribution as real packages in the pkgs/ package set. This allows non-nixos users to run the script as well. For example, deploying a remote machine with: nixos-rebuild --target-host root@hostname --build-host root@hostname --- nixos/modules/installer/tools/tools.nix | 88 +++++-------------- pkgs/tools/nixos/nixos-build-vms/default.nix | 7 ++ .../nixos}/nixos-build-vms/nixos-build-vms.sh | 2 +- pkgs/tools/nixos/nixos-enter/default.nix | 7 ++ .../tools/nixos/nixos-enter}/nixos-enter.sh | 0 .../nixos/nixos-generate-config/default.nix | 16 ++++ .../nixos-generate-config.pl | 0 pkgs/tools/nixos/nixos-install/default.nix | 13 +++ .../nixos/nixos-install}/nixos-install.sh | 0 pkgs/tools/nixos/nixos-option/default.nix | 7 ++ .../tools/nixos/nixos-option}/nixos-option.sh | 0 pkgs/tools/nixos/nixos-rebuild/default.nix | 13 +++ .../nixos-rebuild}/nix-fallback-paths.nix | 0 .../nixos/nixos-rebuild}/nixos-rebuild.sh | 0 pkgs/tools/nixos/nixos-version/default.nix | 13 +++ .../nixos/nixos-version}/nixos-version.sh | 0 pkgs/top-level/all-packages.nix | 10 +++ 17 files changed, 110 insertions(+), 66 deletions(-) create mode 100644 pkgs/tools/nixos/nixos-build-vms/default.nix rename {nixos/modules/installer/tools => pkgs/tools/nixos}/nixos-build-vms/nixos-build-vms.sh (99%) create mode 100644 pkgs/tools/nixos/nixos-enter/default.nix rename {nixos/modules/installer/tools => pkgs/tools/nixos/nixos-enter}/nixos-enter.sh (100%) create mode 100644 pkgs/tools/nixos/nixos-generate-config/default.nix rename {nixos/modules/installer/tools => pkgs/tools/nixos/nixos-generate-config}/nixos-generate-config.pl (100%) create mode 100644 pkgs/tools/nixos/nixos-install/default.nix rename {nixos/modules/installer/tools => pkgs/tools/nixos/nixos-install}/nixos-install.sh (100%) create mode 100644 pkgs/tools/nixos/nixos-option/default.nix rename {nixos/modules/installer/tools => pkgs/tools/nixos/nixos-option}/nixos-option.sh (100%) create mode 100644 pkgs/tools/nixos/nixos-rebuild/default.nix rename {nixos/modules/installer/tools => pkgs/tools/nixos/nixos-rebuild}/nix-fallback-paths.nix (100%) rename {nixos/modules/installer/tools => pkgs/tools/nixos/nixos-rebuild}/nixos-rebuild.sh (100%) create mode 100644 pkgs/tools/nixos/nixos-version/default.nix rename {nixos/modules/installer/tools => pkgs/tools/nixos/nixos-version}/nixos-version.sh (100%) diff --git a/nixos/modules/installer/tools/tools.nix b/nixos/modules/installer/tools/tools.nix index af0a3a2fcc88..6d9ebf750825 100644 --- a/nixos/modules/installer/tools/tools.nix +++ b/nixos/modules/installer/tools/tools.nix @@ -6,77 +6,35 @@ with lib; let - makeProg = args: pkgs.substituteAll (args // { - dir = "bin"; - isExecutable = true; - }); - - nixos-build-vms = makeProg { - name = "nixos-build-vms"; - src = ./nixos-build-vms/nixos-build-vms.sh; - }; - - nixos-install = makeProg { - name = "nixos-install"; - src = ./nixos-install.sh; - nix = config.nix.package.out; - path = makeBinPath [ nixos-enter ]; - }; - - nixos-rebuild = - let fallback = import ./nix-fallback-paths.nix; in - makeProg { - name = "nixos-rebuild"; - src = ./nixos-rebuild.sh; - nix = config.nix.package.out; - nix_x86_64_linux = fallback.x86_64-linux; - nix_i686_linux = fallback.i686-linux; - }; - - nixos-generate-config = makeProg { - name = "nixos-generate-config"; - src = ./nixos-generate-config.pl; - path = [ pkgs.btrfs-progs ]; - perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl"; - inherit (config.system.nixos) release; - }; - - nixos-option = makeProg { - name = "nixos-option"; - src = ./nixos-option.sh; - }; - - nixos-version = makeProg { - name = "nixos-version"; - src = ./nixos-version.sh; - inherit (config.system.nixos) version codeName revision; - }; - - nixos-enter = makeProg { - name = "nixos-enter"; - src = ./nixos-enter.sh; - }; - + nixos-build-vms = pkgs.nixos-build-vms; + nixos-enter = pkgs.nixos-enter; + nixos-generate-config = pkgs.nixos-generate-config.override { inherit (config.system.nixos) release; }; + nixos-install = pkgs.nixos-install.override { nix = config.nix.package; }; + nixos-option = pkgs.nixos-option; + nixos-rebuild = pkgs.nixos-rebuild.override { nix = config.nix.package; }; + nixos-version = pkgs.nixos-version.override { inherit (config.system.nixos) version codeName revision; }; in { - config = { - - environment.systemPackages = - [ nixos-build-vms - nixos-install - nixos-rebuild - nixos-generate-config - nixos-option - nixos-version - nixos-enter - ]; + environment.systemPackages = [ + nixos-build-vms + nixos-enter + nixos-generate-config + nixos-install + nixos-option + nixos-rebuild + nixos-version + ]; system.build = { - inherit nixos-install nixos-generate-config nixos-option nixos-rebuild nixos-enter; + inherit + nixos-enter + nixos-generate-config + nixos-install + nixos-option + nixos-rebuild + ; }; - }; - } diff --git a/pkgs/tools/nixos/nixos-build-vms/default.nix b/pkgs/tools/nixos/nixos-build-vms/default.nix new file mode 100644 index 000000000000..579f80c8256c --- /dev/null +++ b/pkgs/tools/nixos/nixos-build-vms/default.nix @@ -0,0 +1,7 @@ +{ substituteAll }: +substituteAll { + name = "nixos-build-vms"; + dir = "bin"; + isExecutable = true; + src = ./nixos-build-vms.sh; +} diff --git a/nixos/modules/installer/tools/nixos-build-vms/nixos-build-vms.sh b/pkgs/tools/nixos/nixos-build-vms/nixos-build-vms.sh similarity index 99% rename from nixos/modules/installer/tools/nixos-build-vms/nixos-build-vms.sh rename to pkgs/tools/nixos/nixos-build-vms/nixos-build-vms.sh index 4e981c074a57..237a807609a0 100644 --- a/nixos/modules/installer/tools/nixos-build-vms/nixos-build-vms.sh +++ b/pkgs/tools/nixos/nixos-build-vms/nixos-build-vms.sh @@ -35,7 +35,7 @@ do exit 0 ;; esac - + shift done diff --git a/pkgs/tools/nixos/nixos-enter/default.nix b/pkgs/tools/nixos/nixos-enter/default.nix new file mode 100644 index 000000000000..ccf455c40dcf --- /dev/null +++ b/pkgs/tools/nixos/nixos-enter/default.nix @@ -0,0 +1,7 @@ +{ substituteAll }: +substituteAll { + name = "nixos-enter"; + dir = "bin"; + isExecutable = true; + src = ./nixos-enter.sh; +} diff --git a/nixos/modules/installer/tools/nixos-enter.sh b/pkgs/tools/nixos/nixos-enter/nixos-enter.sh similarity index 100% rename from nixos/modules/installer/tools/nixos-enter.sh rename to pkgs/tools/nixos/nixos-enter/nixos-enter.sh diff --git a/pkgs/tools/nixos/nixos-generate-config/default.nix b/pkgs/tools/nixos/nixos-generate-config/default.nix new file mode 100644 index 000000000000..3d9e26d1d08d --- /dev/null +++ b/pkgs/tools/nixos/nixos-generate-config/default.nix @@ -0,0 +1,16 @@ +{ substituteAll +, btrfs-progs +, perl +, perlPackages +, lib +, release ? lib.trivial.release +}: +substituteAll { + name = "nixos-generate-config"; + dir = "bin"; + isExecutable = true; + src = ./nixos-generate-config.pl; + path = [ btrfs-progs ]; + perl = "${perl}/bin/perl -I${perlPackages.FileSlurp}/lib/perl5/site_perl"; + inherit release; +} diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/pkgs/tools/nixos/nixos-generate-config/nixos-generate-config.pl similarity index 100% rename from nixos/modules/installer/tools/nixos-generate-config.pl rename to pkgs/tools/nixos/nixos-generate-config/nixos-generate-config.pl diff --git a/pkgs/tools/nixos/nixos-install/default.nix b/pkgs/tools/nixos/nixos-install/default.nix new file mode 100644 index 000000000000..c652fb67f62f --- /dev/null +++ b/pkgs/tools/nixos/nixos-install/default.nix @@ -0,0 +1,13 @@ +{ substituteAll +, lib +, nix +, nixos-enter +}: +substituteAll { + name = "nixos-install"; + dir = "bin"; + isExecutable = true; + src = ./nixos-install.sh; + nix = nix.out; + path = lib.makeBinPath [ nixos-enter ]; +} diff --git a/nixos/modules/installer/tools/nixos-install.sh b/pkgs/tools/nixos/nixos-install/nixos-install.sh similarity index 100% rename from nixos/modules/installer/tools/nixos-install.sh rename to pkgs/tools/nixos/nixos-install/nixos-install.sh diff --git a/pkgs/tools/nixos/nixos-option/default.nix b/pkgs/tools/nixos/nixos-option/default.nix new file mode 100644 index 000000000000..1fe84c01bced --- /dev/null +++ b/pkgs/tools/nixos/nixos-option/default.nix @@ -0,0 +1,7 @@ +{ substituteAll }: +substituteAll { + name = "nixos-option"; + dir = "bin"; + isExecutable = true; + src = ./nixos-option.sh; +} diff --git a/nixos/modules/installer/tools/nixos-option.sh b/pkgs/tools/nixos/nixos-option/nixos-option.sh similarity index 100% rename from nixos/modules/installer/tools/nixos-option.sh rename to pkgs/tools/nixos/nixos-option/nixos-option.sh diff --git a/pkgs/tools/nixos/nixos-rebuild/default.nix b/pkgs/tools/nixos/nixos-rebuild/default.nix new file mode 100644 index 000000000000..2216252f6cbf --- /dev/null +++ b/pkgs/tools/nixos/nixos-rebuild/default.nix @@ -0,0 +1,13 @@ +{ substituteAll, nix }: +let + fallback = import ./nix-fallback-paths.nix; +in + substituteAll { + name = "nixos-rebuild"; + dir = "bin"; + isExecutable = true; + src = ./nixos-rebuild.sh; + nix = nix.out; + nix_x86_64_linux = fallback.x86_64-linux; + nix_i686_linux = fallback.i686-linux; + } diff --git a/nixos/modules/installer/tools/nix-fallback-paths.nix b/pkgs/tools/nixos/nixos-rebuild/nix-fallback-paths.nix similarity index 100% rename from nixos/modules/installer/tools/nix-fallback-paths.nix rename to pkgs/tools/nixos/nixos-rebuild/nix-fallback-paths.nix diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/pkgs/tools/nixos/nixos-rebuild/nixos-rebuild.sh similarity index 100% rename from nixos/modules/installer/tools/nixos-rebuild.sh rename to pkgs/tools/nixos/nixos-rebuild/nixos-rebuild.sh diff --git a/pkgs/tools/nixos/nixos-version/default.nix b/pkgs/tools/nixos/nixos-version/default.nix new file mode 100644 index 000000000000..f81f9ac9927b --- /dev/null +++ b/pkgs/tools/nixos/nixos-version/default.nix @@ -0,0 +1,13 @@ +{ substituteAll +, lib +, version ? lib.trivial.version +, codeName ? "unknown" +, revision ? lib.trivial.revisionWithDefault "master" +}: +substituteAll { + name = "nixos-version"; + dir = "bin"; + isExecutable = true; + src = ./nixos-version.sh; + inherit version codeName revision; +} diff --git a/nixos/modules/installer/tools/nixos-version.sh b/pkgs/tools/nixos/nixos-version/nixos-version.sh similarity index 100% rename from nixos/modules/installer/tools/nixos-version.sh rename to pkgs/tools/nixos/nixos-version/nixos-version.sh diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0a3da230798e..6ecb95582725 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -21951,6 +21951,16 @@ with pkgs; nixStable nixUnstable; + # NixOS tools + nixos-build-vms = callPackage ../tools/nixos/nixos-build-vms { }; + nixos-enter = callPackage ../tools/nixos/nixos-enter { }; + nixos-generate-config = callPackage ../tools/nixos/nixos-generate-config { }; + nixos-install = callPackage ../tools/nixos/nixos-install { }; + nixos-option = callPackage ../tools/nixos/nixos-option { }; + nixos-rebuild = callPackage ../tools/nixos/nixos-rebuild { }; + nixos-version = callPackage ../tools/nixos/nixos-version { }; + + nixops = callPackage ../tools/package-management/nixops { }; nixopsUnstable = lowPrio (callPackage ../tools/package-management/nixops/unstable.nix { });