Skip to content

Commit

Permalink
Updated nu_plugin_httpserve
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves Pares committed Nov 18, 2024
1 parent 27a144d commit f68c6c8
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 101 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,25 @@
packages = nixpkgs.lib.genAttrs supported-systems (system:
let
pkgs = import nixpkgs { inherit system; };

inputs-for-libs = {
inherit pkgs;
inherit system;
} // (builtins.removeAttrs flake-inputs [
"nixpkgs"
"flake-utils"
]);

std-plugins = with pkgs.nushellPlugins; [
formats
gstat
polars
query
];

nu-libs-and-plugins =
import ./nix-src/nu-libs-and-plugins.nix inputs-for-libs;

nu-with = name: libs: plugins:
self.lib.nushellWith {
inherit pkgs name;
Expand All @@ -86,7 +90,9 @@
in
nu-libs-and-plugins // (with nu-libs-and-plugins; {
nushellWithStdPlugins = nu-with "nushell-with-std-plugins" [ ] [ ];
nushellWithExtras = nu-with "nushell-with-extras" [ nu-batteries ] [
nushellWithExtras = nu-with "nushell-with-extras" [
nu-batteries
] [
nu_plugin_file
nu_plugin_plotters
nu_plugin_vec
Expand Down
13 changes: 9 additions & 4 deletions nix-src/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ flake-inputs: rec {
'';

# Patch a nushell library so it refers to a specific PATH
makeNuLibrary = { pkgs, # Nixpkgs imported
name, # Name of the library
src, # Folder containing the library source
path ? [], # Dependencies (list of folders to add to the PATH)
makeNuLibrary =
{ pkgs
, # Nixpkgs imported
name
, # Name of the library
src
, # Folder containing the library source
path ? [ ]
, # Dependencies (list of folders to add to the PATH)
}:
runNuScript pkgs "${name}-patched" ../nu-src/patch-deps.nu ([ src ] ++ path);
}
133 changes: 70 additions & 63 deletions nix-src/nu-libs-and-plugins.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,87 @@

let

nu-libraries = let # Shortcut to build a nu library without too much fuss:
simpleNuLib = name: extraArgs:
self.lib.makeNuLibrary ({
inherit pkgs name;
src = inputs."${name}-src";
} // extraArgs);
in {
nu-libraries =
let # Shortcut to build a nu library without too much fuss:
simpleNuLib = name: extraArgs:
self.lib.makeNuLibrary ({
inherit pkgs name;
src = inputs."${name}-src";
} // extraArgs);
in
{
nu-batteries = simpleNuLib "nu-batteries" { };

nu-batteries = simpleNuLib "nu-batteries" { };
webserver-nu = simpleNuLib "webserver-nu" {
path = with pkgs; [ "${netcat}/bin" "${coreutils}/bin" ];
webserver-nu = simpleNuLib "webserver-nu" {
path = with pkgs; [ "${netcat}/bin" "${coreutils}/bin" ];
};
};

};

nu-plugins = let
craneLib = inputs.crane.mkLib pkgs;
nu-plugins =
let
craneLib = inputs.crane.mkLib pkgs;

cratesIoJsonIndex = self.lib.runNuScript pkgs "plugins-in-crates.io-index"
../nu-src/list-plugins-in-index.nu [ inputs.crates-io-index ];
cratesIoJsonIndex = self.lib.runNuScript pkgs "plugins-in-crates.io-index"
../nu-src/list-plugins-in-index.nu [ inputs.crates-io-index ];

cratesIoIndex =
builtins.fromJSON (builtins.readFile "${cratesIoJsonIndex}/plugins.json");
cratesIoIndex =
builtins.fromJSON (builtins.readFile "${cratesIoJsonIndex}/plugins.json");

pluginsBaseBuildInputs = with pkgs;
[ pkg-config ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
iconv
darwin.apple_sdk.frameworks.IOKit
darwin.apple_sdk.frameworks.Security
];
pluginsBaseBuildInputs = with pkgs;
[ pkg-config ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
iconv
darwin.apple_sdk.frameworks.IOKit
darwin.apple_sdk.frameworks.Security
];

# Non-rust dependencies for plugins from crates.io
#
# Deps are to be added here on a case-by-case fashion
buildInputsForPluginsFromCratesIo = with pkgs; {
binaryview = [ xorg.libX11 ];
cloud = [ openssl ];
dbus = [ dbus ];
fetch = [ openssl ];
from_dhall = [ openssl ];
gstat = [ openssl ];
plotters = [ fontconfig ];
polars = [ openssl ];
post = [ openssl ];
prometheus = [ openssl ];
query = [ openssl ];
s3 = [ openssl ];
};

buildPluginFromCratesIo = { name, ... }@nameVerCksum:
let
src = craneLib.downloadCargoPackage (nameVerCksum // {
source = "registry+https://github.com/rust-lang/crates.io-index";
});
shortName = builtins.replaceStrings ["nu_plugin_"] [""] name;
buildInputs = pluginsBaseBuildInputs
++ (buildInputsForPluginsFromCratesIo.${shortName} or [ ]);
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
in craneLib.buildPackage {
inherit src buildInputs cargoArtifacts;
doCheck = false;
# Non-rust dependencies for plugins from crates.io
#
# Deps are to be added here on a case-by-case fashion
buildInputsForPluginsFromCratesIo = with pkgs; {
binaryview = [ xorg.libX11 ];
cloud = [ openssl ];
dbus = [ dbus ];
fetch = [ openssl ];
from_dhall = [ openssl ];
gstat = [ openssl ];
plotters = [ fontconfig ];
polars = [ openssl ];
post = [ openssl ];
prometheus = [ openssl ];
query = [ openssl ];
s3 = [ openssl ];
};

in ( # All the plugins from crates.io:
# (Each attr is of the form "nu_plugin_<name>")
builtins.mapAttrs (_: buildPluginFromCratesIo) cratesIoIndex) // {
buildPluginFromCratesIo = { name, ... }@nameVerCksum:
let
src = craneLib.downloadCargoPackage (nameVerCksum // {
source = "registry+https://github.com/rust-lang/crates.io-index";
});
shortName = builtins.replaceStrings [ "nu_plugin_" ] [ "" ] name;
buildInputs = pluginsBaseBuildInputs
++ (buildInputsForPluginsFromCratesIo.${shortName} or [ ]);
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
in
craneLib.buildPackage {
inherit src buildInputs cargoArtifacts;
doCheck = false;
};

in
(# All the plugins from crates.io:
# (Each attr is of the form "nu_plugin_<name>")
builtins.mapAttrs (_: buildPluginFromCratesIo) cratesIoIndex) // {
# Nu plugins from sources other than crates.io:

nu_plugin_httpserve = let
src = craneLib.cleanCargoSource inputs.nu_plugin_httpserve-src;
buildInputs = pluginsBaseBuildInputs;
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
in craneLib.buildPackage { inherit src buildInputs cargoArtifacts; };
nu_plugin_httpserve =
let
src = craneLib.cleanCargoSource inputs.nu_plugin_httpserve-src;
buildInputs = pluginsBaseBuildInputs;
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
in
craneLib.buildPackage { inherit src buildInputs cargoArtifacts; };

};

in nu-libraries // nu-plugins
in
nu-libraries // nu-plugins
58 changes: 31 additions & 27 deletions nix-src/nushell-with.nix
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
let
defcfg = ../default-config-files/config.nu;
defenv = ../default-config-files/env.nu;
in flake-inputs:
in
flake-inputs:
{
# Obtained from `import nixpkgs {...}`
pkgs,
# How to name the produced derivation
name ? "nushell-wrapper",
# Which plugins to use. Can contain `nix` and `source` attributes (both lists)
plugins ? { },
# Which nushell libraries to use. Can contain a `source` attribute (a list)
libraries ? { },
# Which nix paths to add to the PATH. Useful if you directly use libraries
# downloaded from raw sources
path ? [ ],
# Whether to append to the PATH of the parent process
# (for more hermeticity) or overwrite it
keep-path ? false,
# Which nushell derivation to use
nushell ? pkgs.nushell,
# Which config.nu file to set at build time
config-nu ? defcfg,
# Which env.nu file to set at build time
env-nu ? defenv,
# Should we additionally source the user's config.nu & env.nu at runtime?
# If true, then ~/.config/nushell/{config,env}.nu MUST EXIST
source-user-config ? false,
# A sh script describing env vars to add to the nushell process
env-vars-file ? null, }:
# Obtained from `import nixpkgs {...}`
pkgs
, # How to name the produced derivation
name ? "nushell-wrapper"
, # Which plugins to use. Can contain `nix` and `source` attributes (both lists)
plugins ? { }
, # Which nushell libraries to use. Can contain a `source` attribute (a list)
libraries ? { }
, # Which nix paths to add to the PATH. Useful if you directly use libraries
# downloaded from raw sources
path ? [ ]
, # Whether to append to the PATH of the parent process
# (for more hermeticity) or overwrite it
keep-path ? false
, # Which nushell derivation to use
nushell ? pkgs.nushell
, # Which config.nu file to set at build time
config-nu ? defcfg
, # Which env.nu file to set at build time
env-nu ? defenv
, # Should we additionally source the user's config.nu & env.nu at runtime?
# If true, then ~/.config/nushell/{config,env}.nu MUST EXIST
source-user-config ? false
, # A sh script describing env vars to add to the nushell process
env-vars-file ? null
,
}:
with pkgs.lib;
let
crane-builder = flake-inputs.crane.mkLib pkgs;
Expand Down Expand Up @@ -96,4 +99,5 @@ let
destination = "/bin/nu";
};

in deriv // { inherit plugins-env; }
in
deriv // { inherit plugins-env; }

0 comments on commit f68c6c8

Please sign in to comment.