oliverdavies.uk/content/node.57f28cf3-4474-4668-8222-c430cbe9b88b.yml

76 lines
4.2 KiB
YAML

uuid:
- value: 57f28cf3-4474-4668-8222-c430cbe9b88b
langcode:
- value: en
type:
- target_id: daily_email
target_type: node_type
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
revision_timestamp:
- value: '2025-05-11T09:00:08+00:00'
revision_uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
revision_log: { }
status:
- value: true
uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
title:
- value: 'Writing bash scripts with Nix'
created:
- value: '2024-08-20T00:00:00+00:00'
changed:
- value: '2025-05-11T09:00:08+00:00'
promote:
- value: false
sticky:
- value: false
default_langcode:
- value: true
revision_translation_affected:
- value: true
path:
- alias: /daily/2024/08/20/writing-bash-scripts-with-nix
langcode: en
body:
- value: |
<p>Yesterday, I wrote about <a href="/daily/2024/08/19/bash-scripting-for-fun-and-profit">a bash script I've written</a> to export a list of videos on my external hard drive.</p>
<p>If you <a href="https://github.com/opdavies/dotfiles.nix/blob/a1ef2d1402c9c607e7a3e4427ce125d0cabeddcd/lib/shared/scripts/export-video-list.nix#L12-L31">looked at the script on GitHub</a> and you're familiar with bash scripting, you may have thought it looked a bit odd or missing some things.</p>
<p>That's because I wrote it <a href="/daily/2022/09/26/experimenting-with-the-nix-package-manager">with Nix</a> - the tool I've been using for almost two years to manage my dotfiles and operating system configuration.</p>
<p>Using Nix for bash scripts has advantages, like automatically adding the shebang line, setting sensible defaults for error handling, and automatically running <code>shellcheck</code> when switching.</p>
<p>I think the main advantage, though, is it can inject any dependency packages into the script.</p>
<p>This script needs <code>tree</code> and <code>jq</code>, so they are dependencies of the script and the script can't run if they aren't installed.</p>
<p>But, I don't need to assume they are available. Nix can do it automatically and make any packages added as build inputs available.</p>
<p>Now, if anyone else wanted to use this script, or I wanted to share another script with colleagues or a client, they can use it without needing to install any dependencies separately and the script will continue to work in the future using its explicitly-added dependencies.</p>
format: full_html
processed: |
<p>Yesterday, I wrote about <a href="http://default/daily/2024/08/19/bash-scripting-for-fun-and-profit">a bash script I've written</a> to export a list of videos on my external hard drive.</p>
<p>If you <a href="https://github.com/opdavies/dotfiles.nix/blob/a1ef2d1402c9c607e7a3e4427ce125d0cabeddcd/lib/shared/scripts/export-video-list.nix#L12-L31">looked at the script on GitHub</a> and you're familiar with bash scripting, you may have thought it looked a bit odd or missing some things.</p>
<p>That's because I wrote it <a href="http://default/daily/2022/09/26/experimenting-with-the-nix-package-manager">with Nix</a> - the tool I've been using for almost two years to manage my dotfiles and operating system configuration.</p>
<p>Using Nix for bash scripts has advantages, like automatically adding the shebang line, setting sensible defaults for error handling, and automatically running <code>shellcheck</code> when switching.</p>
<p>I think the main advantage, though, is it can inject any dependency packages into the script.</p>
<p>This script needs <code>tree</code> and <code>jq</code>, so they are dependencies of the script and the script can't run if they aren't installed.</p>
<p>But, I don't need to assume they are available. Nix can do it automatically and make any packages added as build inputs available.</p>
<p>Now, if anyone else wanted to use this script, or I wanted to share another script with colleagues or a client, they can use it without needing to install any dependencies separately and the script will continue to work in the future using its explicitly-added dependencies.</p>
summary: null
field_daily_email_cta: { }