I’m a nixos newbie. Today I tried to create (or wrap?) a package using nix for my first time.
The package that I tried to create is logisim-ita, a fork of logisim, for educational purposes.
After reading some blogs on nix packaging, and after going through some trials and errors, I finally made it.
- I first cloned nur-package-template to my machine
- and according to its readme, I added those codes to default.nix
logisim-ita = pkgs.callPackage ./pkgs/logisim-ita { inherit (pkgs) fetchurl jre makeWrapper copyDesktopItems makeDesktopItem unzip ; };
- There’s is already a derivation for logisim in nixpkgs and logisim-ita should be similar. So I did some tiny tweaks to logisim’s derivation and put the codes into pkgs/logisim-ita/default.nix
{ lib, stdenv, fetchurl, jre, makeWrapper, copyDesktopItems, makeDesktopItem, unzip }:
stdenv.mkDerivation rec {
pname = "logisim-ita";
version = "2.16.1.4";
src = fetchurl {
url = "https://github.com/Logisim-Ita/Logisim/releases/download/v${version}/Logisim-ITA.jar";
sha256 = "d27b92e38188309be935e6355faef8689594537b8e280d79b84372e1f85a38d7";
};
dontUnpack = true;
nativeBuildInputs = [ makeWrapper copyDesktopItems unzip ];
desktopItems = [
(makeDesktopItem {
name = pname;
desktopName = "Logisim-ITA";
exec = "logisim-ita";
icon = "logisim-ita";
comment = meta.description;
categories = [ "Education" ];
})
];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
makeWrapper ${jre}/bin/java $out/bin/${pname} --add-flags "-jar $src"
# Create icons
unzip $src "resources/logisim/img/*"
for size in 16 20 24 48 64 128
do
install -D "./resources/logisim/img/logisim-icon-$size.png" "$out/share/icons/hicolor/''${size}x''${size}/apps/logisim-ita.png"
done
runHook postInstall
'';
meta = with lib; {
homepage = "logisim.altervista.org";
description = "Logisim Italian Fork";
maintainers = with maintainers; [ A7R7 ];
sourceProvenance = with sourceTypes; [ binaryBytecode ];
license = licenses.gpl3Plus;
platforms = platforms.unix;
};
}
- run
nix build '.#logisim-ita'
thennix profile install '.#logisim-ita'
for a temporary install.
And boom! logisim-ita is avaliable on my machine
Although managed to create the package, I still felt somewhat strange and curious, so I just raise my questions here.
-
what is exactly ‘A’ ‘#’ and ‘B’ in the format
A#B
?
When I donix profile install nixpkgs#XXX
, why does my system know that it should reference the nixpkgs repo from github, but not a local dir called ‘nixpkgs’?
And why it knows to reference the local dir when it is ‘.#XXX’?
And most importantly, where should I find the manual page that describes this in detail? -
the default.nix has an argument set
{ lib, stdenv, fetchurl, jre, makeWrapper, copyDesktopItems, makeDesktopItem, unzip }
but I call default.nix with
{ inherit (pkgs) fetchurl jre makeWrapper copyDesktopItems makeDesktopItem unzip ; };
I did not pass lib
and stdenv
. How does default.nix know their value?
Also, what is the best practice to call default.nix when the argument set is as long as this?
You may check my nur repo if you’re interested. currently there’s only one package logisim-ita