Skip to content

Commit 0669748

Browse files
committed
Obviate writeShellApplication in 'command'
1 parent e46b51d commit 0669748

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

example/flake.nix

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,17 @@
3333
'';
3434

3535
# Create .sqlite database from chinook database.
36-
sqlite-init.command = pkgs.writeShellApplication {
37-
name = "sqlite-init";
38-
text = ''
39-
echo "$(date): Importing Chinook database ($DATAFILE) ..."
40-
${lib.getExe pkgs.sqlite} "$DATAFILE" < ${inputs.chinookDb}/ChinookDatabase/DataSources/Chinook_Sqlite.sql
41-
echo "$(date): Done."
42-
'';
43-
};
36+
sqlite-init.command = ''
37+
echo "$(date): Importing Chinook database ($DATAFILE) ..."
38+
${lib.getExe pkgs.sqlite} "$DATAFILE" < ${inputs.chinookDb}/ChinookDatabase/DataSources/Chinook_Sqlite.sql
39+
echo "$(date): Done."
40+
'';
4441

4542
# Run sqlite-web on the local chinook database.
4643
sqlite-web = {
47-
command = pkgs.writeShellApplication {
48-
name = "sqlite-web";
49-
text = ''
50-
${pkgs.sqlite-web}/bin/sqlite_web "$DATAFILE"
51-
'';
52-
};
44+
command = ''
45+
${pkgs.sqlite-web}/bin/sqlite_web "$DATAFILE"
46+
'';
5347
# The 'depends_on' will have this process wait until the above one is completed.
5448
depends_on."sqlite-init".condition = "process_completed_successfully";
5549
};
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
{ lib, ... }:
1+
{ name, pkgs, lib, ... }:
22

33
args:
44
lib.mkOption (args // {
55
type = lib.types.either lib.types.package lib.types.str;
66
apply = pkg:
7-
if builtins.isString pkg then pkg else
8-
lib.getExe pkg;
7+
if builtins.isString pkg
8+
# process-compose is unreliable in handling environment variable, so let's
9+
# wrap it in a bash script.
10+
then lib.getExe (pkgs.writeShellApplication { inherit name; text = pkg; })
11+
else lib.getExe pkg;
912
})

nix/process-compose/settings/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ in
5252
default = "-c";
5353
example = "-c";
5454
};
55-
shell_command = import ./command.nix { inherit lib; } {
55+
shell_command = mkOption {
56+
type = types.str;
5657
description = ''
5758
The shell to use to run the process `command`s.
5859
5960
For reproducibility across systems, by default this uses
6061
`pkgs.bash`.
6162
'';
62-
default = pkgs.bash;
63+
default = lib.getExe pkgs.bash;
6364
};
6465
};
6566

nix/process-compose/settings/process.nix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, ... }:
1+
{ name, pkgs, lib, ... }:
22

33
let
44
inherit (lib) types mkOption;
@@ -9,12 +9,13 @@ let
99
in
1010
{
1111
options = {
12-
command = import ./command.nix { inherit lib; } {
12+
command = import ./command.nix { inherit name pkgs lib; } {
1313
description = ''
14-
The command that runs this process
14+
The command or script or package that runs this process
1515
16-
If a package is given, its executable is used as the command. This is
17-
useful to pass in a `writeShellApplication.`
16+
If a package is given, its executable is used as the command. Otherwise,
17+
the command string is wrapped in a `pkgs.writeShellApplication` which
18+
uses ShellCheck and runs the command in bash.
1819
'';
1920
};
2021

test/flake.nix

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,19 @@
3333
'';
3434
};
3535
in
36-
pkgs.writeShellApplication {
37-
name = "sqlite-init";
38-
text = ''
39-
echo "$(date): Creating database ($DATAFILE) ..."
40-
${lib.getExe pkgs.sqlite} "$DATAFILE" < ${sqlFile}
41-
echo "$(date): Done."
42-
'';
43-
};
36+
''
37+
echo "$(date): Creating database ($DATAFILE) ..."
38+
${lib.getExe pkgs.sqlite} "$DATAFILE" < ${sqlFile}
39+
echo "$(date): Done."
40+
'';
4441

4542
# Query something, write to result.txt
4643
sqlite-query = {
47-
command = pkgs.writeShellApplication {
48-
name = "sqlite-query";
49-
text = ''
50-
${lib.getExe pkgs.sqlite} "$DATAFILE" \
51-
'select val from demo where val = "Hello"' \
52-
> result.txt
53-
'';
54-
};
44+
command = ''
45+
${lib.getExe pkgs.sqlite} "$DATAFILE" \
46+
'select val from demo where val = "Hello"' \
47+
> result.txt
48+
'';
5549
# The 'depends_on' will have this process wait until the above one is completed.
5650
depends_on."sqlite-init".condition = "process_completed_successfully";
5751
availability.restart = "no";

0 commit comments

Comments
 (0)