Skip to content

Instantly share code, notes, and snippets.

@hbjydev
Last active May 25, 2024 01:14
Show Gist options
  • Save hbjydev/566df3e92a35fcd89c4d6aa611cd0a71 to your computer and use it in GitHub Desktop.
Save hbjydev/566df3e92a35fcd89c4d6aa611cd0a71 to your computer and use it in GitHub Desktop.
Flake for including ipcalc Perl script, its license file (as you should be doing) and the man page for it
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = inputs.nixpkgs.lib.systems.flakeExposed;
perSystem = { pkgs, ... }: {
packages.default = pkgs.runCommand "ipcalc" {
src = pkgs.fetchFromGitHub {
owner = "kjokjo";
repo = "ipcalc";
rev = "0.51";
sha256 = "sha256-260GJ0UwEdXFaINa0o8Od/nhyReNyXL8GrfKncx63jI=";
};
} ''
mkdir -p $out/bin $out/share/man $out/share/doc/ipcalc
# Documentation
cp $src/ipcalc.1 $out/share/man/ipcalc.1
# This seems like the correct place:
# https://discourse.nixos.org/t/collision-between-2-license-txt-from-2-different-packages/22071/5
cp $src/license $out/share/doc/ipcalc/LICENSE.txt
# Hotpatch for Perl shebang
cp $src/ipcalc ./ipcalc
sed -i 's|#!/usr/bin/perl|#!${pkgs.perl}/bin/perl|' ./ipcalc
# Store ipcalc executable in output
cp ./ipcalc $out/bin/ipcalc
chmod +x $out/bin/ipcalc
'';
};
};
}
@hbjydev
Copy link
Author

hbjydev commented May 25, 2024

To build this, put it in a folder somewhere (or preferably a GitHub repo) and run nix build . against it. In result, there'll be two directories:

  • bin (which has ipcalc in it)
  • share (which has the man pages and license files)

To run it, just do result/bin/ipcalc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment