Use writeShellApplication for packaging

This commit is contained in:
Ilan Joselevich 2023-01-10 20:50:35 +02:00
parent 28ce0f04e5
commit 52e7ab3910
No known key found for this signature in database
7 changed files with 26 additions and 45 deletions

View File

@ -24,7 +24,7 @@
{
default = self.packages.${system}.nixos-remote;
docs = pkgs.callPackage ./docs { };
nixos-remote = pkgs.callPackage ./nixos-remote.nix { };
nixos-remote = pkgs.callPackage ./src { };
});
checks.x86_64-linux =
let
@ -32,6 +32,7 @@
inputs = {
inherit pkgs;
inherit (disko.nixosModules) disko;
nixos-remote = self.packages.x86_64-linux.nixos-remote;
kexec-installer = "${nixos-images.packages.${pkgs.system}.kexec-installer-nixos-unstable}/nixos-kexec-installer-${pkgs.stdenv.hostPlatform.system}.tar.gz";
};
in

View File

@ -1,39 +0,0 @@
{ stdenvNoCC
, makeWrapper
, lib
, openssh
, gitMinimal
, nix
, coreutils
, shellcheck
, rsync
, curl
}:
let
runtimeDeps = [
openssh
gitMinimal # for git flakes
rsync
nix
coreutils
curl # when uploading tarballs
];
in
stdenvNoCC.mkDerivation {
name = "nixos-remote";
src = ./.;
nativeBuildInputs = [
makeWrapper
shellcheck
];
installPhase = ''
install -D -m755 nixos-remote $out/bin/nixos-remote
wrapProgram "$out/bin/nixos-remote" \
--prefix PATH : "${lib.makeBinPath runtimeDeps}"
'';
doCheck = true;
checkPhase = ''
shellcheck ./nixos-remote
'';
}

20
src/default.nix Normal file
View File

@ -0,0 +1,20 @@
{ writeShellApplication
, openssh
, gitMinimal
, rsync
, nix
, coreutils
, curl
}:
writeShellApplication {
name = "nixos-remote";
text = builtins.readFile ./nixos-remote.sh;
runtimeInputs = [
openssh
gitMinimal # for git flakes
rsync
nix
coreutils
curl # when uploading tarballs
];
}

View File

@ -1,6 +1,3 @@
#!/usr/bin/env bash
set -eufo pipefail
showUsage() {
cat <<USAGE
Usage: nixos-remote [options] ssh-host

View File

@ -8,7 +8,7 @@
start_all()
installer.succeed("echo super-secret > /tmp/disk-1.key")
output = installer.succeed("""
${../nixos-remote} \
nixos-remote \
--no-ssh-copy-id \
--debug \
--kexec /etc/nixos-remote/kexec-installer \

View File

@ -18,7 +18,7 @@
installer.succeed("mkdir -p /tmp/extra-files/var/lib/secrets")
installer.succeed("echo value > /tmp/extra-files/var/lib/secrets/key")
installer.succeed("""
${../nixos-remote} \
nixos-remote \
--no-ssh-copy-id \
--debug \
--kexec /etc/nixos-remote/kexec-installer \

View File

@ -12,6 +12,8 @@ in
${pkgs.coreutils}/bin/install -D -m600 ${./ssh-keys/ssh} /root/.ssh/id_rsa
'';
environment.systemPackages = [ inputs.nixos-remote ];
environment.etc = {
"nixos-remote/disko".source = system-to-install.config.system.build.disko;
"nixos-remote/system-to-install".source = system-to-install.config.system.build.toplevel;