From 4ca0521a5f50fb295b32279ffa6e186d90c24957 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 4 Aug 2024 21:55:46 +0200 Subject: [PATCH] implement nix rbuild nushell command --- .config/nushell/conf.d/99-attic.nu | 14 -------- .config/nushell/conf.d/99-nix.nu | 51 ++++++++++++++++++++++++++++++ flake.lock | 6 ++-- 3 files changed, 54 insertions(+), 17 deletions(-) delete mode 100644 .config/nushell/conf.d/99-attic.nu create mode 100644 .config/nushell/conf.d/99-nix.nu diff --git a/.config/nushell/conf.d/99-attic.nu b/.config/nushell/conf.d/99-attic.nu deleted file mode 100644 index 4494122..0000000 --- a/.config/nushell/conf.d/99-attic.nu +++ /dev/null @@ -1,14 +0,0 @@ -def "attic bpush" [ - cache:string, # The Attic cache to push to - flake:string, # The flake reference to build - ...nixargs:string, # Extra arguments for Nix - --nom(-n), # Use Nom -] { - let outpath = (^(if $nom { "nom" } else { "nix" }) - build - --no-link - --print-out-paths - $flake - ...$nixargs) - attic push $cache $outpath -} diff --git a/.config/nushell/conf.d/99-nix.nu b/.config/nushell/conf.d/99-nix.nu new file mode 100644 index 0000000..b28fb3a --- /dev/null +++ b/.config/nushell/conf.d/99-nix.nu @@ -0,0 +1,51 @@ +# Build a flake reference on a remote host. Creates a `result` symlink. +# The nix-command and flakes experimental features must be active both locally and on the target host. +def "nix rbuild" [ + host:string, # The remote host to build on + flakeref:string, # A flake reference to build + ...nixargs:string, # Additional arguments to pass to the eval command + --no-link(-n), # Don't create a `result` link + --nom, # Invoke `nom` on the remote machine instead of `nix` + --remote-eval(-r), # Evaluate the derivation on the remote. Note that this will incorrectly handle path-based flake references. +]: nothing -> list { + let outpaths = if $remote_eval { + print "Eval & Build on Remote..." + ssh $host $"(if $nom { "nom" } else { "nix" }) build --no-link --print-out-paths '($flakeref)' ($nixargs | str join ' ')" | lines + } else { + print "Eval..." + let eval_output = nix eval $flakeref ...$nixargs + if $eval_output =~ "error:" { + error make { + msg: "Derivation evaluation failed!", + help: $eval_output, + } | return $in + } + let drv_path = $eval_output | parse "«derivation {drv}»" | get 0.drv + + print "Copy drv to Remote..." + nix copy --substitute-on-destination --derivation --to $"ssh://($host)" $drv_path + + print "Build on Remote..." + ssh $host $"(if $nom { "nom" } else { "nix" }) build --no-link --print-out-paths '($drv_path)^*'" | lines + } + + print "Copy from Remote..." + nix copy --substitute-on-destination --no-check-sigs --from $"ssh://($host)" ...$outpaths + + $outpaths +} + +def "attic bpush" [ + cache:string, # The Attic cache to push to + flake:string, # The flake reference to build + ...nixargs:string, # Extra arguments for Nix + --nom(-n), # Use Nom +] { + let outpath = (^(if $nom { "nom" } else { "nix" }) + build + --no-link + --print-out-paths + $flake + ...$nixargs) + attic push $cache $outpath +} diff --git a/flake.lock b/flake.lock index 24ffdf2..f5947f6 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1722062969, - "narHash": "sha256-QOS0ykELUmPbrrUGmegAUlpmUFznDQeR4q7rFhl8eQg=", + "lastModified": 1722630782, + "narHash": "sha256-hMyG9/WlUi0Ho9VkRrrez7SeNlDzLxalm9FwY7n/Noo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b73c2221a46c13557b1b3be9c2070cc42cf01eb3", + "rev": "d04953086551086b44b6f3c6b7eeb26294f207da", "type": "github" }, "original": {