Skip to content

Commit f68c6c8

Browse files
author
Yves Pares
committed
Updated nu_plugin_httpserve
1 parent 27a144d commit f68c6c8

File tree

5 files changed

+123
-101
lines changed

5 files changed

+123
-101
lines changed

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,25 @@
5858
packages = nixpkgs.lib.genAttrs supported-systems (system:
5959
let
6060
pkgs = import nixpkgs { inherit system; };
61+
6162
inputs-for-libs = {
6263
inherit pkgs;
6364
inherit system;
6465
} // (builtins.removeAttrs flake-inputs [
6566
"nixpkgs"
6667
"flake-utils"
6768
]);
69+
6870
std-plugins = with pkgs.nushellPlugins; [
6971
formats
7072
gstat
7173
polars
7274
query
7375
];
76+
7477
nu-libs-and-plugins =
7578
import ./nix-src/nu-libs-and-plugins.nix inputs-for-libs;
79+
7680
nu-with = name: libs: plugins:
7781
self.lib.nushellWith {
7882
inherit pkgs name;
@@ -86,7 +90,9 @@
8690
in
8791
nu-libs-and-plugins // (with nu-libs-and-plugins; {
8892
nushellWithStdPlugins = nu-with "nushell-with-std-plugins" [ ] [ ];
89-
nushellWithExtras = nu-with "nushell-with-extras" [ nu-batteries ] [
93+
nushellWithExtras = nu-with "nushell-with-extras" [
94+
nu-batteries
95+
] [
9096
nu_plugin_file
9197
nu_plugin_plotters
9298
nu_plugin_vec

nix-src/lib.nix

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ flake-inputs: rec {
1111
'';
1212

1313
# Patch a nushell library so it refers to a specific PATH
14-
makeNuLibrary = { pkgs, # Nixpkgs imported
15-
name, # Name of the library
16-
src, # Folder containing the library source
17-
path ? [], # Dependencies (list of folders to add to the PATH)
14+
makeNuLibrary =
15+
{ pkgs
16+
, # Nixpkgs imported
17+
name
18+
, # Name of the library
19+
src
20+
, # Folder containing the library source
21+
path ? [ ]
22+
, # Dependencies (list of folders to add to the PATH)
1823
}:
1924
runNuScript pkgs "${name}-patched" ../nu-src/patch-deps.nu ([ src ] ++ path);
2025
}

nix-src/nu-libs-and-plugins.nix

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,87 @@
55

66
let
77

8-
nu-libraries = let # Shortcut to build a nu library without too much fuss:
9-
simpleNuLib = name: extraArgs:
10-
self.lib.makeNuLibrary ({
11-
inherit pkgs name;
12-
src = inputs."${name}-src";
13-
} // extraArgs);
14-
in {
8+
nu-libraries =
9+
let # Shortcut to build a nu library without too much fuss:
10+
simpleNuLib = name: extraArgs:
11+
self.lib.makeNuLibrary ({
12+
inherit pkgs name;
13+
src = inputs."${name}-src";
14+
} // extraArgs);
15+
in
16+
{
17+
nu-batteries = simpleNuLib "nu-batteries" { };
1518

16-
nu-batteries = simpleNuLib "nu-batteries" { };
17-
webserver-nu = simpleNuLib "webserver-nu" {
18-
path = with pkgs; [ "${netcat}/bin" "${coreutils}/bin" ];
19+
webserver-nu = simpleNuLib "webserver-nu" {
20+
path = with pkgs; [ "${netcat}/bin" "${coreutils}/bin" ];
21+
};
1922
};
2023

21-
};
22-
23-
nu-plugins = let
24-
craneLib = inputs.crane.mkLib pkgs;
24+
nu-plugins =
25+
let
26+
craneLib = inputs.crane.mkLib pkgs;
2527

26-
cratesIoJsonIndex = self.lib.runNuScript pkgs "plugins-in-crates.io-index"
27-
../nu-src/list-plugins-in-index.nu [ inputs.crates-io-index ];
28+
cratesIoJsonIndex = self.lib.runNuScript pkgs "plugins-in-crates.io-index"
29+
../nu-src/list-plugins-in-index.nu [ inputs.crates-io-index ];
2830

29-
cratesIoIndex =
30-
builtins.fromJSON (builtins.readFile "${cratesIoJsonIndex}/plugins.json");
31+
cratesIoIndex =
32+
builtins.fromJSON (builtins.readFile "${cratesIoJsonIndex}/plugins.json");
3133

32-
pluginsBaseBuildInputs = with pkgs;
33-
[ pkg-config ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
34-
iconv
35-
darwin.apple_sdk.frameworks.IOKit
36-
darwin.apple_sdk.frameworks.Security
37-
];
34+
pluginsBaseBuildInputs = with pkgs;
35+
[ pkg-config ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
36+
iconv
37+
darwin.apple_sdk.frameworks.IOKit
38+
darwin.apple_sdk.frameworks.Security
39+
];
3840

39-
# Non-rust dependencies for plugins from crates.io
40-
#
41-
# Deps are to be added here on a case-by-case fashion
42-
buildInputsForPluginsFromCratesIo = with pkgs; {
43-
binaryview = [ xorg.libX11 ];
44-
cloud = [ openssl ];
45-
dbus = [ dbus ];
46-
fetch = [ openssl ];
47-
from_dhall = [ openssl ];
48-
gstat = [ openssl ];
49-
plotters = [ fontconfig ];
50-
polars = [ openssl ];
51-
post = [ openssl ];
52-
prometheus = [ openssl ];
53-
query = [ openssl ];
54-
s3 = [ openssl ];
55-
};
56-
57-
buildPluginFromCratesIo = { name, ... }@nameVerCksum:
58-
let
59-
src = craneLib.downloadCargoPackage (nameVerCksum // {
60-
source = "registry+https://github.com/rust-lang/crates.io-index";
61-
});
62-
shortName = builtins.replaceStrings ["nu_plugin_"] [""] name;
63-
buildInputs = pluginsBaseBuildInputs
64-
++ (buildInputsForPluginsFromCratesIo.${shortName} or [ ]);
65-
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
66-
in craneLib.buildPackage {
67-
inherit src buildInputs cargoArtifacts;
68-
doCheck = false;
41+
# Non-rust dependencies for plugins from crates.io
42+
#
43+
# Deps are to be added here on a case-by-case fashion
44+
buildInputsForPluginsFromCratesIo = with pkgs; {
45+
binaryview = [ xorg.libX11 ];
46+
cloud = [ openssl ];
47+
dbus = [ dbus ];
48+
fetch = [ openssl ];
49+
from_dhall = [ openssl ];
50+
gstat = [ openssl ];
51+
plotters = [ fontconfig ];
52+
polars = [ openssl ];
53+
post = [ openssl ];
54+
prometheus = [ openssl ];
55+
query = [ openssl ];
56+
s3 = [ openssl ];
6957
};
7058

71-
in ( # All the plugins from crates.io:
72-
# (Each attr is of the form "nu_plugin_<name>")
73-
builtins.mapAttrs (_: buildPluginFromCratesIo) cratesIoIndex) // {
59+
buildPluginFromCratesIo = { name, ... }@nameVerCksum:
60+
let
61+
src = craneLib.downloadCargoPackage (nameVerCksum // {
62+
source = "registry+https://github.com/rust-lang/crates.io-index";
63+
});
64+
shortName = builtins.replaceStrings [ "nu_plugin_" ] [ "" ] name;
65+
buildInputs = pluginsBaseBuildInputs
66+
++ (buildInputsForPluginsFromCratesIo.${shortName} or [ ]);
67+
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
68+
in
69+
craneLib.buildPackage {
70+
inherit src buildInputs cargoArtifacts;
71+
doCheck = false;
72+
};
73+
74+
in
75+
(# All the plugins from crates.io:
76+
# (Each attr is of the form "nu_plugin_<name>")
77+
builtins.mapAttrs (_: buildPluginFromCratesIo) cratesIoIndex) // {
7478
# Nu plugins from sources other than crates.io:
7579

76-
nu_plugin_httpserve = let
77-
src = craneLib.cleanCargoSource inputs.nu_plugin_httpserve-src;
78-
buildInputs = pluginsBaseBuildInputs;
79-
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
80-
in craneLib.buildPackage { inherit src buildInputs cargoArtifacts; };
80+
nu_plugin_httpserve =
81+
let
82+
src = craneLib.cleanCargoSource inputs.nu_plugin_httpserve-src;
83+
buildInputs = pluginsBaseBuildInputs;
84+
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
85+
in
86+
craneLib.buildPackage { inherit src buildInputs cargoArtifacts; };
8187

8288
};
8389

84-
in nu-libraries // nu-plugins
90+
in
91+
nu-libraries // nu-plugins

nix-src/nushell-with.nix

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
let
22
defcfg = ../default-config-files/config.nu;
33
defenv = ../default-config-files/env.nu;
4-
in flake-inputs:
4+
in
5+
flake-inputs:
56
{
6-
# Obtained from `import nixpkgs {...}`
7-
pkgs,
8-
# How to name the produced derivation
9-
name ? "nushell-wrapper",
10-
# Which plugins to use. Can contain `nix` and `source` attributes (both lists)
11-
plugins ? { },
12-
# Which nushell libraries to use. Can contain a `source` attribute (a list)
13-
libraries ? { },
14-
# Which nix paths to add to the PATH. Useful if you directly use libraries
15-
# downloaded from raw sources
16-
path ? [ ],
17-
# Whether to append to the PATH of the parent process
18-
# (for more hermeticity) or overwrite it
19-
keep-path ? false,
20-
# Which nushell derivation to use
21-
nushell ? pkgs.nushell,
22-
# Which config.nu file to set at build time
23-
config-nu ? defcfg,
24-
# Which env.nu file to set at build time
25-
env-nu ? defenv,
26-
# Should we additionally source the user's config.nu & env.nu at runtime?
27-
# If true, then ~/.config/nushell/{config,env}.nu MUST EXIST
28-
source-user-config ? false,
29-
# A sh script describing env vars to add to the nushell process
30-
env-vars-file ? null, }:
7+
# Obtained from `import nixpkgs {...}`
8+
pkgs
9+
, # How to name the produced derivation
10+
name ? "nushell-wrapper"
11+
, # Which plugins to use. Can contain `nix` and `source` attributes (both lists)
12+
plugins ? { }
13+
, # Which nushell libraries to use. Can contain a `source` attribute (a list)
14+
libraries ? { }
15+
, # Which nix paths to add to the PATH. Useful if you directly use libraries
16+
# downloaded from raw sources
17+
path ? [ ]
18+
, # Whether to append to the PATH of the parent process
19+
# (for more hermeticity) or overwrite it
20+
keep-path ? false
21+
, # Which nushell derivation to use
22+
nushell ? pkgs.nushell
23+
, # Which config.nu file to set at build time
24+
config-nu ? defcfg
25+
, # Which env.nu file to set at build time
26+
env-nu ? defenv
27+
, # Should we additionally source the user's config.nu & env.nu at runtime?
28+
# If true, then ~/.config/nushell/{config,env}.nu MUST EXIST
29+
source-user-config ? false
30+
, # A sh script describing env vars to add to the nushell process
31+
env-vars-file ? null
32+
,
33+
}:
3134
with pkgs.lib;
3235
let
3336
crane-builder = flake-inputs.crane.mkLib pkgs;
@@ -96,4 +99,5 @@ let
9699
destination = "/bin/nu";
97100
};
98101

99-
in deriv // { inherit plugins-env; }
102+
in
103+
deriv // { inherit plugins-env; }

0 commit comments

Comments
 (0)