Skip to content

Commit

Permalink
Improve apps provided by Nix Flake (#497)
Browse files Browse the repository at this point in the history
* Improve Nix flake provides apps

* Make sure we can load another modules with additional `-r`
  • Loading branch information
kachick authored Mar 3, 2024
1 parent a136f26 commit 4fe3a85
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v3
- run: nix flake check
- run: nix develop --command echo 'This step should be done before any other "nix develop" steps because of measuring Nix build time'
- run: nix run .#console
- run: nix run .#ruby -- -rprime -e 'p Prime.first 5; p ULID.generate'
- run: nix develop --command bundle install
- name: Log current versions
run: nix develop --command bundle exec rake deps
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ If you would like to see released version's one. [Look at the ref](https://githu
In [Nix](https://nixos.org/), you can skip the installation steps for both ruby and ruby-ulid to try.

```console
> nix run github:kachick/ruby-ulid#console
> nix run github:kachick/ruby-ulid#ruby -- -e 'p ULID.generate'
ULID(2024-03-03 18:37:06.152 UTC: 01HR2SNY789ZZ027EDJEHAGQ62)

> nix run github:kachick/ruby-ulid#irb
irb(main):001:0> ULID.parse('01H66XG2A9WWYRCYGPA62T4AZA')
=> ULID(2023-07-25 16:18:12.937 UTC: 01H66XG2A9WWYRCYGPA62T4AZA)
```
Expand Down
11 changes: 0 additions & 11 deletions bin/pure-console.rb

This file was deleted.

28 changes: 19 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,40 @@
{
name = "ruby-ulid";
src = self;
# https://discourse.nixos.org/t/adding-runtime-dependency-to-flake/27785
buildInputs = with pkgs; [
makeWrapper
];
installPhase = ''
mkdir -p $out/bin
cp -rf ./lib $out
install -t $out/bin bin/pure-console.rb
makeWrapper $out/bin/pure-console.rb $out/bin/console \
--prefix PATH : ${nixpkgs.lib.makeBinPath [ pkgs.ruby_3_3 ]}
'';
runtimeDependencies = [
pkgs.ruby_3_3
pkgs.libyaml
];
};

packages.ruby = pkgs.writeShellScriptBin "ruby-with-ulid" ''
set -euo pipefail
${pkgs.ruby_3_3}/bin/ruby -r"${packages.ruby-ulid}/lib/ulid" "$@"
'';

packages.irb = pkgs.writeShellScriptBin "irb-with-ulid" ''
set -euo pipefail
${pkgs.ruby_3_3}/bin/irb -r"${packages.ruby-ulid}/lib/ulid" "$@"
'';

packages.default = packages.ruby-ulid;

# `nix run`
apps = {
console = {
ruby = {
type = "app";
program = "${packages.ruby}/bin/ruby-with-ulid";
};

irb = {
type = "app";
program = "${packages.ruby-ulid}/bin/console";
program = "${packages.irb}/bin/irb-with-ulid";
};
};
}
Expand Down

0 comments on commit 4fe3a85

Please sign in to comment.