Skip to content

Commit

Permalink
Provide inputs as Nickel records
Browse files Browse the repository at this point in the history
Generate Nickel record with all packages from each input and allow Nickel
code to access them directly without declaring them in `input_spec`.
  • Loading branch information
YorikSar committed Jul 6, 2023
1 parent 7c6c418 commit 8f86e78
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 124 deletions.
161 changes: 52 additions & 109 deletions builders.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
name = "hello",
version = "0.1",
build_command = {
cmd = nix-s%"%{inputs.bash}/bin/bash"%,
cmd = nix-s%"%{inputs.nixpkgs.bash}/bin/bash"%,
args = [ "-c",
nix-s%"
%{inputs.gcc}/bin/gcc %{nix.lib.import_file "hello.c"} -o hello
%{inputs.coreutils}/bin/mkdir -p $out/bin
%{inputs.coreutils}/bin/cp hello $out/bin/hello
%{inputs.nixpkgs.gcc}/bin/gcc %{nix.lib.import_file "hello.c"} -o hello
%{inputs.nixpkgs.coreutils}/bin/mkdir -p $out/bin
%{inputs.nixpkgs.coreutils}/bin/cp hello $out/bin/hello
"%
]
},
Expand All @@ -35,16 +35,7 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
= NickelDerivation,

BashShell = {
inputs_spec = {
bash = {},
# Setting the following as a default value conflicts with InputsSpec's
# contract default value (`"nixpkgs"`). Maybe InputsSpec shouldn't set a
# default value at all?
# That being said, `naked_std_env` is an internal compatibility value:
# there doesn't seem to be a good reason to make it a default value. It
# can still be overridden using `force` if really needed
naked_std_env.input = "nickel-nix-internals",
},
inputs_spec = {},
inputs,

output =
Expand All @@ -54,14 +45,14 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
# This is required otherwise nix develop will fail with a message that it
# only supports bash.
build_command = {
cmd = nix-s%"%{inputs.bash}/bin/bash"%,
cmd = nix-s%"%{inputs.nixpkgs.bash}/bin/bash"%,
args = [],
},

structured_env = {
# TODO: handle naked derivations without having to interpolate
stdenv.naked_std_env = nix-s%"%{inputs.naked_std_env}"%,
PATH.bash = nix-s%"%{inputs.bash}/bin"%,
stdenv.naked_std_env = nix-s%"%{inputs.nickel-nix-internals.naked_std_env}"%,
PATH.bash = nix-s%"%{inputs.nixpkgs.bash}/bin"%,
},

# Compute `env` from `structured_env`. Note that thanks to recursive
Expand All @@ -85,71 +76,57 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
RustShell =
BashShell
& {
inputs_spec = {
cargo = {},
rustc = {},
rustfmt = {},
rust-analyzer = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
cargo = nix-s%"%{inputs.cargo}/bin"%,
rustc = nix-s%"%{inputs.rustc}/bin"%,
rustfmt = nix-s%"%{inputs.rustfmt}/bin"%,
rust-analyzer = nix-s%"%{inputs.rust-analyzer}/bin"%,
cargo = nix-s%"%{inputs.nixpkgs.cargo}/bin"%,
rustc = nix-s%"%{inputs.nixpkgs.rustc}/bin"%,
rustfmt = nix-s%"%{inputs.nixpkgs.rustfmt}/bin"%,
rust-analyzer = nix-s%"%{inputs.nixpkgs.rust-analyzer}/bin"%,
},
},
},

GoShell =
BashShell
& {
inputs_spec = {
go = {},
gopls = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
go = nix-s%"%{inputs.go}/bin"%,
gopls = nix-s%"%{inputs.gopls}/bin"%,
go = nix-s%"%{inputs.nixpkgs.go}/bin"%,
gopls = nix-s%"%{inputs.nixpkgs.gopls}/bin"%,
},
},
},

ClojureShell =
BashShell
& {
inputs_spec = {
clojure = {},
clojure-lsp = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
clojure = nix-s%"%{inputs.clojure}/bin"%,
clojure-lsp = nix-s%"%{inputs.clojure-lsp}/bin"%,
clojure = nix-s%"%{inputs.nixpkgs.clojure}/bin"%,
clojure-lsp = nix-s%"%{inputs.nixpkgs.clojure-lsp}/bin"%,
},
},
},

CShell =
BashShell
& {
inputs_spec = {
clang = {},
clang-tools = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
clang = nix-s%"%{inputs.clang}/bin"%,
clang-tools = nix-s%"%{inputs.clang-tools}/bin"%,
clang = nix-s%"%{inputs.nixpkgs.clang}/bin"%,
clang-tools = nix-s%"%{inputs.nixpkgs.clang-tools}/bin"%,
},
},
},
Expand All @@ -158,35 +135,27 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
PhpShell =
BashShell
& {
inputs_spec = {
php = {},
intelephense = {
path = "nodePackages"."intelephense",
},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
php = nix-s%"%{inputs.php}/bin"%,
intelephense = nix-s%"%{inputs.intelephense}/bin"%,
php = nix-s%"%{inputs.nixpkgs.php}/bin"%,
intelephense = nix-s%"%{inputs.nixpkgs.nodePackages.intelephense}/bin"%,
},
},
},

ZigShell =
BashShell
& {
inputs_spec = {
zig = {},
zls = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
zig = nix-s%"%{inputs.zig}/bin"%,
zls = nix-s%"%{inputs.zls}/bin"%,
zig = nix-s%"%{inputs.nixpkgs.zig}/bin"%,
zls = nix-s%"%{inputs.nixpkgs.zls}/bin"%,
},
},
},
Expand All @@ -195,50 +164,40 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
JavascriptShell =
BashShell
& {
inputs_spec = {
nodejs = {},
typescript-language-server = {
path = "nodePackages_latest.typescript-language-server",
}
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
nodejs = nix-s%"%{inputs.nodejs}/bin"%,
ts-lsp = nix-s%"%{inputs.typescript-language-server}/bin"%,
nodejs = nix-s%"%{inputs.nixpkgs.nodejs}/bin"%,
ts-lsp = nix-s%"%{inputs.nixpkgs.nodePackages_latest.typescript-language-server}/bin"%,
},
},
},

RacketShell =
BashShell
& {
inputs_spec = {
racket = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
racket = nix-s%"%{inputs.racket}/bin"%,
racket = nix-s%"%{inputs.nixpkgs.racket}/bin"%,
},
},
},

ScalaShell =
BashShell
& {
inputs_spec = {
scala = {},
metals = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
scala = nix-s%"%{inputs.scala}/bin"%,
metals = nix-s%"%{inputs.metals}/bin"%,
scala = nix-s%"%{inputs.nixpkgs.scala}/bin"%,
metals = nix-s%"%{inputs.nixpkgs.metals}/bin"%,
},
},
},
Expand All @@ -248,35 +207,27 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
Python310Shell =
BashShell
& {
inputs_spec = {
python310 = {},
python-lsp-server = {
path = "python310Packages.python-lsp-server",
}
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
python = nix-s%"%{inputs.python310}/bin"%,
python-lsp = nix-s%"%{inputs.python-lsp-server}/bin"%,
python = nix-s%"%{inputs.nixpkgs.python310}/bin"%,
python-lsp = nix-s%"%{inputs.nixpkgs.python310Packages.python-lsp-server}/bin"%,
},
},
},

ErlangShell =
BashShell
& {
inputs_spec = {
erlang = {},
erlang-ls = {},
},
inputs_spec = {},
inputs,

output.structured_env = {
PATH = {
erlang = nix-s%"%{inputs.erlang}/bin"%,
erlang-lsp = nix-s%"%{inputs.erlang-ls}/bin"%,
erlang = nix-s%"%{inputs.nixpkgs.erlang}/bin"%,
erlang-lsp = nix-s%"%{inputs.nixpkgs.erlang-ls}/bin"%,
},
},
},
Expand All @@ -286,14 +237,6 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
& {
ghcVersion, # User-defined. To keep in sync with the one used by stack
inputs_spec = {
stack = {},
ormolu = {},
nix = {},
git = {},
coreutils = {},
haskell-language-server = {
path = "haskell.packages.ghc%{ghcVersion}.haskell-language-server",
},
# This will point to a copy of nixpkgs in nix store
path = {},
},
Expand All @@ -303,21 +246,21 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
let stack-wrapped =
{
name = "stack-wrapped",
version = inputs.stack.version,
version = inputs.nixpkgs.stack.version,
build_command = {
cmd = nix-s%"%{inputs.bash}/bin/bash"%,
cmd = nix-s%"%{inputs.nixpkgs.bash}/bin/bash"%,
args = [
"-c",
# Sorry about Topiary formatting of the following lines
nix-s%"
export PATH="%{inputs.coreutils}/bin:$PATH"
export PATH="%{inputs.nixpkgs.coreutils}/bin:$PATH"
mkdir -p $out/bin
echo "$0" > $out/bin/stack
chmod a+x $out/bin/*
"%,
nix-s%"
#!%{inputs.bash}/bin/bash
%{inputs.stack}/bin/stack \
#!%{inputs.nixpkgs.bash}/bin/bash
%{inputs.nixpkgs.stack}/bin/stack \
--nix \
--no-nix-pure \
--nix-path="nixpkgs=%{inputs.path}" \
Expand All @@ -330,11 +273,11 @@ let { NickelDerivation, .. } = import "contracts.ncl" in
{
PATH = {
stack = nix-s%"%{stack-wrapped}/bin"%,
stack' = nix-s%"%{inputs.stack}/bin"%,
ormolu = nix-s%"%{inputs.ormolu}/bin"%,
nix = nix-s%"%{inputs.nix}/bin"%,
git = nix-s%"%{inputs.git}/bin"%,
haskell-language-server = nix-s%"%{inputs.haskell-language-server}/bin"%,
stack' = nix-s%"%{inputs.nixpkgs.stack}/bin"%,
ormolu = nix-s%"%{inputs.nixpkgs.ormolu}/bin"%,
nix = nix-s%"%{inputs.nixpkgs.nix}/bin"%,
git = nix-s%"%{inputs.nixpkgs.git}/bin"%,
haskell-language-server = nix-s%"%{inputs.nixpkgs.haskell.packages.ghc%{ghcVersion}.haskell-language-server}/bin"%,
},
},
},
Expand Down
Loading

0 comments on commit 8f86e78

Please sign in to comment.