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 7, 2023
1 parent 75c65b2 commit bed296e
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 132 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, Derivation, .. } = 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, Derivation, .. } = 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,16 +45,16 @@ let { NickelDerivation, Derivation, .. } = 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}"%,
stdenv.naked_std_env = nix-s%"%{inputs.nickel-nix-internals.naked_std_env}"%,
},

packages = { bash = inputs.bash },
packages = { bash = inputs.nixpkgs.bash },

structured_env.PATH =
packages
Expand Down Expand Up @@ -94,143 +85,111 @@ let { NickelDerivation, Derivation, .. } = import "contracts.ncl" in
RustShell =
BashShell
& {
inputs_spec = {
cargo = {},
rustc = {},
rustfmt = {},
rust-analyzer = {},
},
inputs_spec = {},
inputs,

output.packages = {
cargo = inputs.cargo,
rustc = inputs.rustc,
rustfmt = inputs.rustfmt,
rust-analyzer = inputs.rust-analyzer,
cargo = inputs.nixpkgs.cargo,
rustc = inputs.nixpkgs.rustc,
rustfmt = inputs.nixpkgs.rustfmt,
rust-analyzer = inputs.nixpkgs.rust-analyzer,
},
},

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

output.packages = {
go = inputs.go,
gopls = inputs.gopls,
go = inputs.nixpkgs.go,
gopls = inputs.nixpkgs.gopls,
},
},

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

output.packages = {
clojure = inputs.clojure,
clojure-lsp = inputs.clojure-lsp,
clojure = inputs.nixpkgs.clojure,
clojure-lsp = inputs.nixpkgs.clojure-lsp,
},
},

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

output.packages = {
clang = inputs.clang,
clang-tools = inputs.clang-tools,
clang = inputs.nixpkgs.clang,
clang-tools = inputs.nixpkgs.clang-tools,
},
},

# intelephense is currently broken in nixpkgs
PhpShell =
BashShell
& {
inputs_spec = {
php = {},
intelephense = {
path = "nodePackages"."intelephense",
},
},
inputs_spec = {},
inputs,

output.packages = {
php = inputs.php,
intelephense = inputs.intelephense,
php = inputs.nixpkgs.php,
intelephense = inputs.nixpkgs.nodePackages.intelephense,
},
},

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

output.packages = {
zig = inputs.zig,
zls = inputs.zls,
zig = inputs.nixpkgs.zig,
zls = inputs.nixpkgs.zls,
},
},

# nodePackages_latest.typescript-language-server is marked broken in nixpkgs
JavascriptShell =
BashShell
& {
inputs_spec = {
nodejs = {},
typescript-language-server = {
path = "nodePackages_latest.typescript-language-server",
}
},
inputs_spec = {},
inputs,

output.packages = {
nodejs = inputs.nodejs,
ts-lsp = inputs.typescript-language-server,
nodejs = inputs.nixpkgs.nodejs,
ts-lsp = inputs.nixpkgs.nodePackages_latest.typescript-language-server,
},
},

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

output.packages = {
racket = inputs.racket,
racket = inputs.nixpkgs.racket,
},
},

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

output.packages = {
scala = inputs.scala,
metals = inputs.metals,
scala = inputs.nixpkgs.scala,
metals = inputs.nixpkgs.metals,
},
},

Expand All @@ -239,32 +198,24 @@ let { NickelDerivation, Derivation, .. } = import "contracts.ncl" in
Python310Shell =
BashShell
& {
inputs_spec = {
python310 = {},
python-lsp-server = {
path = "python310Packages.python-lsp-server",
}
},
inputs_spec = {},
inputs,

output.packages = {
python = inputs.python310,
python-lsp = inputs.python-lsp-server,
python = inputs.nixpkgs.python310,
python-lsp = inputs.nixpkgs.python310Packages.python-lsp-server,
},
},

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

output.packages = {
erlang = inputs.erlang,
erlang-lsp = inputs.erlang-ls,
erlang = inputs.nixpkgs.erlang,
erlang-lsp = inputs.nixpkgs.erlang-ls,
},
},

Expand All @@ -273,14 +224,6 @@ let { NickelDerivation, Derivation, .. } = 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 @@ -290,21 +233,21 @@ let { NickelDerivation, Derivation, .. } = 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 @@ -316,11 +259,11 @@ let { NickelDerivation, Derivation, .. } = import "contracts.ncl" in
in
{
stack = stack-wrapped,
stack' = inputs.stack,
ormolu = inputs.ormolu,
nix = inputs.nix,
git = inputs.git,
haskell-language-server = inputs.haskell-language-server,
stack' = inputs.nixpkgs.stack,
ormolu = inputs.nixpkgs.ormolu,
nix = inputs.nixpkgs.nix,
git = inputs.nixpkgs.git,
haskell-language-server = inputs.nixpkgs.haskell.packages."ghc%{ghcVersion}".haskell-language-server,
},
},
}
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@

# Internal nickel-nix library. Each value is a function that accepts inputs from user flake.
lib.nickel-nix-internals = {
naked_std_env = self.lib.${system}.importNcl ./. "naked-stdenv.ncl";
# Use importNclInternal to avoid infinite recursion over inputs
naked_std_env = lib.importNclInternal ./. "naked-stdenv.ncl";
};

# Helper function that generates ugly contents for "nickel.lock.ncl", see buildLockFile.
Expand Down
Loading

0 comments on commit bed296e

Please sign in to comment.