Skip to content

Instantly share code, notes, and snippets.

@jbboehr
Last active February 8, 2024 17:00
Show Gist options
  • Save jbboehr/3a5d0dd52a0c1139ce88b76ab82a9cb0 to your computer and use it in GitHub Desktop.
Save jbboehr/3a5d0dd52a0c1139ce88b76ab82a9cb0 to your computer and use it in GitHub Desktop.
{
description = "A very basic flake";
inputs = {
ugit-src = {
url = "github:Bhupesh-V/ugit";
flake = false;
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
ugit-src,
} @ args:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
pkgs' = pkgs;
fzf = pkgs.fzf.overrideAttrs (o:
o
// {
# blow away some stuff we don't need
postInstall = ''
${o.postInstall}
rm -rf $out/share
rm -rf $out/bin/fzf-tmux
rm -rf $out/bin/fzf-share
'';
});
mkPackages = pkgs: let
lib = pkgs.lib;
makeWrapper = pkgs.makeWrapper;
in rec {
busybox = pkgs.busybox.override {
#enableMinimal = true;
};
git = pkgs.git.override {
curl = pkgs.curlMinimal;
svnSupport = false;
perlSupport = false;
nlsSupport = false;
osxkeychainSupport = false;
guiSupport = false;
withManual = false;
pythonSupport = false;
withpcre2 = false;
doInstallCheck = false;
withSsh = false;
sendEmailSupport = false;
};
ncurses = pkgs.ncurses.override {
mouseSupport = false;
#unicodeSupport = false;
};
ugit = pkgs.stdenv.mkDerivation {
name = "ugit";
src = ugit-src;
nativeBuildInputs = [makeWrapper];
configurePhase = "";
buildPhase = "";
installPhase = ''
mkdir -p $out/bin
cp $src/ugit $out/bin/ugit
chmod +x $out/bin/ugit
wrapProgram $out/bin/ugit --set PATH $BIN_PATH
'';
BIN_PATH = lib.makeBinPath [busybox fzf git ncurses];
};
ugit-docker = pkgs'.dockerTools.buildImage {
name = "ugit";
tag = "latest";
created = "now";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [ugit busybox git fzf ncurses];
pathsToLink = ["/bin"];
};
config.Cmd = ["/bin/ugit"];
};
};
glibc = mkPackages pkgs;
musl = mkPackages pkgs.pkgsMusl;
in {
packages = rec {
ugit-glibc = glibc.ugit;
ugit-docker-glibc = glibc.ugit-docker;
ugit-musl = musl.ugit;
ugit-docker-musl = musl.ugit-docker;
default = ugit-glibc;
};
formatter = pkgs.alejandra;
}
);
}
@Bhupesh-V
Copy link

Hey, the author of ugit here.

  • Just want to say thanks for writing this. I still haven't managed to dive into the nix ecosystem. Hopefully when I do all of this might make sense, until then. Do drop in any resources you think would be good for me.

@jbboehr
Copy link
Author

jbboehr commented Feb 8, 2024

To be clear, I had attempted to use dockerTools.buildImage before and was somewhat disappointed in how large the images were, so this was mainly meant as an exercise in optimizing image size using that tool.

I do like Nix quite a bit, but don't have much advice outside of the standard sources:

I often refer to nixpkgs when developing a derivation.

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