nicknovitski / nix-develop

Apache License 2.0
41 stars 2 forks source link

[Feature request] Using with specific attribute #4

Closed 573 closed 1 year ago

573 commented 1 year ago

I have

    matrix:
        nix-command:
          - develop .#cljShell --impure --accept-flake-config --command clj --version
          - develop .#rustyShell --impure --accept-flake-config --command rustc --version
          - develop .#rustShell --impure --accept-flake-config --command rustc --version
          - develop .#yaocaml --impure --accept-flake-config --command ocaml --version
          - develop .#agda --impure --accept-flake-config --command ghci --version
          - develop .#haskell --impure --accept-flake-config --command ghci --version

Is that translatable to nix-develop syntax i. e. not using the default .# ?

Right now I only see

- uses: nicknovitski/nix-develop@v1
  with:
    arguments: .#cljShell --impure --accept-flake-config
- run: clj --version

but that alone wouldn't help DRY either.

nicknovitski commented 1 year ago

Ohhh, using a matrix? Cool!  I'd try splitting apart those commands into just the parts which vary, and use includes:, maybe like this:

jobs:
  nix-checks:
    strategy:
      matrix:
        includes:
          - shell: cljShell
            command: clj --version
          - shell: rustyShell
            command: rustc --version
          - shell: rustShell
            command: rustc --version
          # ...etc
    steps:
      - uses: actions/checkout@v4
      - uses: nicknovitski/nix-develop@v1
        with:
          arguments: ./#${{ matrix.shell }} --impure --accept-flake-config
      - run: ${{ matrix.command }}
nicknovitski commented 1 year ago

But if you only ever need to run a single command in a given shell, that's actually great, and you're past the point of needing this action. I personally think it's a big improvement to move commands from multiple CI yaml steps into single locally executable scripts.

For example, here's a refactor that I would approve on a project

# before
      - uses: nicknovitski/nix-develop@v1
      - run: cargo fmt --check
      - run: cargo-deny check
      - run: eclint \
               -exclude "Cargo.lock"
      - run: codespell \
              --skip target,.git \
              --ignore-words-list crate
# after
      - run: nix develop --command ./run-checks.sh # bash script which calls those other things

I should probably add that advice to the readme...

Does any of this help you?

573 commented 1 year ago

Awesome! Thx!

573 commented 1 year ago
        with:
          arguments: .#${{ matrix.shell }} --impure --accept-flake-config

./#/.# but somehow not working:

/tmp/nix-shell.epBN0p: line 113: mktemp: command not found /tmp/nix-shell.epBN0p: line 179: mkdir: command not found /tmp/nix-shell.epBN0p: line 180: rm: command not found /tmp/nix-shell.epBN0p: line 181: ln: command not found /tmp/nix-shell.epBN0p: line 119: rm: command not found /tmp/nix-shell.epBN0p: line 120: exec: true: not found

nicknovitski commented 1 year ago

Ah, are you using devenv with flakes? At the moment that requires the flags --impure --keep PATH, but that's because of something in the action i've now decided to change; it surprised me and it surprised you, so i bet it will surprise other people too.

I just made a new release, v1.1.0, that makes --keep PATH unnecessary.