St: Difference between revisions

From NixOS Wiki
imported>Artturin
add with pkgs; and add paths
imported>IgorM
m Fixed syntax highlighting
 
(16 intermediate revisions by 8 users not shown)
Line 1: Line 1:
st the suckless terminal or the simple terminal
{{Lowercase title}}
[[Category:Applications]]


in the following examples it is assumed that <syntaxhighlight lang="nix" inline>environment.systemPackages</syntaxhighlight> is in <code>/etc/nixos/</code> and there is a <code>/etc/nixos/programs/st/</code>
<code>st</code> the suckless terminal or the simple terminal
 
most things here apply for dwm and other suckless software too
 
The examples below only assume you are running Linux (at the time of this writing, darwin/OS X does not support <code>st</code>).


== Installing ==
== Installing ==
=== NixOS ===
Add <code>st</code> to the list of available packages in your <code>configuration.nix</code>.
System-wide:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
   st
   st
];</syntaxhighlight>
];</syntaxhighlight>
Only available to certain users:
<syntaxhighlight lang="nix">
users.users.alice.packages = with pkgs; [
  st
];</syntaxhighlight>
=== Other Linux distributions ===
You will need to write a roughly equivalent nix expression and install it the imperative way.
E.g.
<code>my-custom-st</code>
<syntaxhighlight lang="nix">
# pinned nixpkgs from nix.dev > "toward reproducibility"
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/3590f02e7d5760e52072c1a729ee2250b5560746.tar.gz") {}
}:
# specifics elided for brevity
pkgs.st.overrideAttrs { ... }</syntaxhighlight>
Followed by:
<syntaxhighlight lang=console>
$ nix-env -i -f my-custom-st
</syntaxhighlight>


== Patching ==
== Patching ==


=== Official Patches ===
Most customization of <code>st</code> that alters its base feature set comes in the form of applying patches to the source code.


Can be applied by first downloading them from `st.suckless.org/patches` like so:
=== Obtaining hashes ===


curl https://st.suckless.org/patches/rightclickpaste/st-rightclickpaste-0.8.2.diff > /etc/nixos/programs/st/rightclicktopaste.diff
To apply a patch you need to obtain the hash, the hash should be obtained with the following command


And then including them in an attribute override in your systemPackages declaration:
<syntaxhighlight lang="console">
$ nix-prefetch-url <url>
</syntaxhighlight>
example
<syntaxhighlight lang="console">
$ nix-prefetch-url https://st.suckless.org/patches/rightclickpaste/st-rightclickpaste-0.8.2.diff
</syntaxhighlight>
 
=== Patches ===
 
Can be applied by including them in an attribute override in your systemPackages declaration:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 23: Line 72:
   (st.overrideAttrs (oldAttrs: rec {
   (st.overrideAttrs (oldAttrs: rec {
     patches = [
     patches = [
       ./programs/st/rightclicktopaste.diff
      # You can specify local patches
       # Patches can also be fetched directly
       ./path/to/local.diff
       (pkgs.fetchpatch {
       # Fetch them directly from `st.suckless.org`
       (fetchpatch {
         url = "https://st.suckless.org/patches/rightclickpaste/st-rightclickpaste-0.8.2.diff";
         url = "https://st.suckless.org/patches/rightclickpaste/st-rightclickpaste-0.8.2.diff";
         sha256 = "1y4fkwn911avwk3nq2cqmgb2rynbqibgcpx7yriir0lf2x2ww1b6";
         sha256 = "1y4fkwn911avwk3nq2cqmgb2rynbqibgcpx7yriir0lf2x2ww1b6";
      })
      # Or from any other source
      (fetchpatch {
        url = "https://raw.githubusercontent.com/fooUser/barRepo/1111111/somepatch.diff";
        sha256 = "222222222222222222222222222222222222222222";
       })
       })
     ];
     ];
Line 33: Line 88:
];</syntaxhighlight>
];</syntaxhighlight>


=== Unofficial Patches ===
=== Patch Dependencies ===


Hosted on GitHub can be applied in a similar fashion using:
Can be included with the <code>buildInputs</code> line like in the following ligature patch example:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
   (st.overrideAttrs (oldAttrs: rec {
   (st.overrideAttrs (oldAttrs: rec {
    buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
     patches = [
     patches = [
       "${fetchFromGitHub { owner = "foo"; repo = "bar"; rev = "0.0.1"; sha256 = "111111111111111111111111111111111111111111111111111"; }}/some-custom-patch.diff"
       (fetchpatch {
        url = "https://st.suckless.org/patches/ligatures/0.8.3/st-ligatures-20200430-0.8.3.diff";
        sha256 = "67b668c77677bfcaff42031e2656ce9cf173275e1dfd6f72587e8e8726298f09";
      })
     ];
     ];
   }))
   }))
];</syntaxhighlight>
];</syntaxhighlight>


=== Patch Dependencies ===
== Config ==


Can be included with the `buildInputs` line like in the following ligature patch example:
Configuration is accomplished through a <code>config.h</code> file.


curl https://st.suckless.org/patches/ligatures/0.8.3/st-ligatures-20200430-0.8.3.diff > /etc/nixos/programs/st/ligatures.diff
=== Header file ===


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
   (st.overrideAttrs (oldAttrs: rec {
   (st.overrideAttrs (oldAttrs: rec {
     buildInputs = oldAttrs.buildInputs ++ (with pkgs; [ harfbuzz ]);
     # Using a local file
     patches = [
    configFile = writeText "config.def.h" (builtins.readFile ./path/to/local/config.h);
      ./programs/st/ligatures.diff
     # Or one pulled from GitHub
     ];
    # configFile = writeText "config.def.h" (builtins.readFile "${fetchFromGitHub { owner = "LukeSmithxyz"; repo = "st"; rev = "8ab3d03681479263a11b05f7f1b53157f61e8c3b"; sha256 = "1brwnyi1hr56840cdx0qw2y19hpr0haw4la9n0rqdn0r2chl8vag"; }}/config.h");
     postPatch = "${oldAttrs.postPatch}\n cp ${configFile} config.def.h";
   }))
   }))
];</syntaxhighlight>
];</syntaxhighlight>


== Config ==
== All together now ==
 
=== Local config ===


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
   (st.overrideAttrs (oldAttrs: rec {
   (st.overrideAttrs (oldAttrs: rec {
     configFile = pkgs.writeText "config.def.h" (builtins.readFile ./programs/st/config.h);
    # ligatures dependency
    buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
    patches = [
      # ligatures patch
      (fetchpatch {
        url = "https://st.suckless.org/patches/ligatures/0.8.3/st-ligatures-20200430-0.8.3.diff";
        sha256 = "67b668c77677bfcaff42031e2656ce9cf173275e1dfd6f72587e8e8726298f09";
      })
    ];
    # version controlled config file
     configFile = writeText "config.def.h" (builtins.readFile "${fetchFromGitHub { owner = "me"; repo = "my-custom-st-stuff"; rev = "1111222233334444"; sha256 = "11111111111111111111111111111111111"; }}/config.h");
     postPatch = oldAttrs.postPatch ++ ''cp ${configFile} config.def.h'';
     postPatch = oldAttrs.postPatch ++ ''cp ${configFile} config.def.h'';
   }))
   }))
];</syntaxhighlight>
];</syntaxhighlight>


=== Remote config ===
== Using DWM ==
 
However, this will not work for <code>dwm</code>.  (Probably <code>services.xserver.windowManager.dwm</code> can only see the <code>dwm</code> in <code>pkgs</code>, not the one in <code>environment.systemPackages</code>.)  But you can use an overlay, like this:
 
<syntaxhighlight lang="nix">
nixpkgs.overlays = [
  (self: super: {
    dwm = super.dwm.overrideAttrs (oldAttrs: rec {
      patches = [
        ./path/to/my-dwm-patch.patch
        ];
      configFile = super.writeText "config.h" (builtins.readFile ./dwm-config.h);
      postPatch = oldAttrs.postPatch or "" + "\necho 'Using own config file...'\n cp ${configFile} config.def.h";
      });
    })
  ];
</syntaxhighlight>
 
It should also be mentioned that the <code>st.overrideAttrs</code> should be added to the overlays when using <code>dwm</code> with dwm changes and st changes the overlay could look like this
 
<syntaxhighlight lang="nix">
nixpkgs.overlays = [
  (self: super: {
    dwm = super.dwm.overrideAttrs (oldAttrs: rec {
      patches = [
        ./path/to/my-dwm-patch.patch
        ];
      configFile = super.writeText "config.h" (builtins.readFile ./dwm-config.h);
      postPatch = oldAttrs.postPatch or "" + "\necho 'Using own config file...'\n cp ${configFile} config.def.h";
      });
    })
    st = super.st.overrideAttrs (oldAttrs: rec {
      patches = [
        ./path/to/my-dwm-patch.patch
        ];
      configFile = super.writeText "config.h" (builtins.readFile ./st-config.h);
      postPatch = "${oldAttrs.postPatch}\ncp ${configFile} config.def.h\n"
      });
    })
  ];
</syntaxhighlight>
 
== Remote config ==
 
If instead, you would prefer to build a pre-configured repository or realize more intense configuration, fork the mainline repository (or find one you like) and replace the value of the <code>src</code> attribute in the override.
 
=== Forks ===
 
Luke smiths st fork is used as the example
Luke smiths st fork is used as the example


Line 80: Line 195:
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
   (st.overrideAttrs (oldAttrs: rec {
   (st.overrideAttrs (oldAttrs: rec {
     src = pkgs.fetchFromGitHub {
     src = fetchFromGitHub {
       owner = "LukeSmithxyz";
       owner = "LukeSmithxyz";
       repo = "st";
       repo = "st";
Line 86: Line 201:
       sha256 = "1brwnyi1hr56840cdx0qw2y19hpr0haw4la9n0rqdn0r2chl8vag";
       sha256 = "1brwnyi1hr56840cdx0qw2y19hpr0haw4la9n0rqdn0r2chl8vag";
     };
     };
     buildInputs = oldAttrs.buildInputs ++ (with super; [ harfbuzz ]);
    # Make sure you include whatever dependencies the fork needs to build properly!
   # If you want it to be always up to date use fetchTarball instead of fetchFromGitHuh
     buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
   # src = pkgs.fetchTarball {
   # If you want it to be always up to date use fetchTarball instead of fetchFromGitHub
   # src = builtins.fetchTarball {
   #  url = "https://github.com/lukesmithxyz/st/archive/master.tar.gz";
   #  url = "https://github.com/lukesmithxyz/st/archive/master.tar.gz";
   # };
   # };
   }))
   }))
];</syntaxhighlight>
];</syntaxhighlight>
== Troubleshooting ==
=== See files after patching ===
{{file|st-test.nix|nix|
with import <nixpkgs> {};
<nowiki>
(st.overrideAttrs (oldAttrs: rec {
  buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
  patches = [
    (fetchpatch {
      url = "https://st.suckless.org/patches/ligatures/0.8.3/st-ligatures-20200430-0.8.3.diff";
      sha256 = "18fllssg5d5gik1x0ppz232vdphr0y2j5z8lhs5j9zjs8m9ria5w";
    })
  ];
}))
</nowiki>}}
<syntaxhighlight lang="console">
$ nix-shell st-test.nix
$ unpackPhase
$ ls
$ cd theunpackeddir
$ patchPhase
</syntaxhighlight>
[https://nixos.org/manual/nixpkgs/stable/#sec-stdenv-phases Additional phases]

Latest revision as of 09:41, 30 September 2023

st the suckless terminal or the simple terminal

most things here apply for dwm and other suckless software too

The examples below only assume you are running Linux (at the time of this writing, darwin/OS X does not support st).

Installing

NixOS

Add st to the list of available packages in your configuration.nix.

System-wide:

environment.systemPackages = with pkgs; [
  st
];

Only available to certain users:

users.users.alice.packages = with pkgs; [
  st
];

Other Linux distributions

You will need to write a roughly equivalent nix expression and install it the imperative way.

E.g.

my-custom-st

# pinned nixpkgs from nix.dev > "toward reproducibility"
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/3590f02e7d5760e52072c1a729ee2250b5560746.tar.gz") {}
}:
# specifics elided for brevity
pkgs.st.overrideAttrs { ... }

Followed by:

$ nix-env -i -f my-custom-st

Patching

Most customization of st that alters its base feature set comes in the form of applying patches to the source code.

Obtaining hashes

To apply a patch you need to obtain the hash, the hash should be obtained with the following command

$ nix-prefetch-url <url>

example

$ nix-prefetch-url https://st.suckless.org/patches/rightclickpaste/st-rightclickpaste-0.8.2.diff

Patches

Can be applied by including them in an attribute override in your systemPackages declaration:

environment.systemPackages = with pkgs; [
  (st.overrideAttrs (oldAttrs: rec {
    patches = [
      # You can specify local patches
      ./path/to/local.diff
      # Fetch them directly from `st.suckless.org`
      (fetchpatch {
        url = "https://st.suckless.org/patches/rightclickpaste/st-rightclickpaste-0.8.2.diff";
        sha256 = "1y4fkwn911avwk3nq2cqmgb2rynbqibgcpx7yriir0lf2x2ww1b6";
      })
      # Or from any other source
      (fetchpatch {
        url = "https://raw.githubusercontent.com/fooUser/barRepo/1111111/somepatch.diff";
        sha256 = "222222222222222222222222222222222222222222";
      })
    ];
  }))
];

Patch Dependencies

Can be included with the buildInputs line like in the following ligature patch example:

environment.systemPackages = with pkgs; [
  (st.overrideAttrs (oldAttrs: rec {
    buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
    patches = [
      (fetchpatch {
        url = "https://st.suckless.org/patches/ligatures/0.8.3/st-ligatures-20200430-0.8.3.diff";
        sha256 = "67b668c77677bfcaff42031e2656ce9cf173275e1dfd6f72587e8e8726298f09";
      })
    ];
  }))
];

Config

Configuration is accomplished through a config.h file.

Header file

environment.systemPackages = with pkgs; [
  (st.overrideAttrs (oldAttrs: rec {
    # Using a local file
    configFile = writeText "config.def.h" (builtins.readFile ./path/to/local/config.h);
    # Or one pulled from GitHub
    # configFile = writeText "config.def.h" (builtins.readFile "${fetchFromGitHub { owner = "LukeSmithxyz"; repo = "st"; rev = "8ab3d03681479263a11b05f7f1b53157f61e8c3b"; sha256 = "1brwnyi1hr56840cdx0qw2y19hpr0haw4la9n0rqdn0r2chl8vag"; }}/config.h");
    postPatch = "${oldAttrs.postPatch}\n cp ${configFile} config.def.h";
  }))
];

All together now

environment.systemPackages = with pkgs; [
  (st.overrideAttrs (oldAttrs: rec {
    # ligatures dependency
    buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
    patches = [
      # ligatures patch
      (fetchpatch {
        url = "https://st.suckless.org/patches/ligatures/0.8.3/st-ligatures-20200430-0.8.3.diff";
        sha256 = "67b668c77677bfcaff42031e2656ce9cf173275e1dfd6f72587e8e8726298f09";
      })
    ];
    # version controlled config file
    configFile = writeText "config.def.h" (builtins.readFile "${fetchFromGitHub { owner = "me"; repo = "my-custom-st-stuff"; rev = "1111222233334444"; sha256 = "11111111111111111111111111111111111"; }}/config.h");
    postPatch = oldAttrs.postPatch ++ ''cp ${configFile} config.def.h'';
  }))
];

Using DWM

However, this will not work for dwm. (Probably services.xserver.windowManager.dwm can only see the dwm in pkgs, not the one in environment.systemPackages.) But you can use an overlay, like this:

nixpkgs.overlays = [
  (self: super: {
    dwm = super.dwm.overrideAttrs (oldAttrs: rec {
      patches = [
        ./path/to/my-dwm-patch.patch
        ];
      configFile = super.writeText "config.h" (builtins.readFile ./dwm-config.h);
      postPatch = oldAttrs.postPatch or "" + "\necho 'Using own config file...'\n cp ${configFile} config.def.h";
      });
    })
  ];

It should also be mentioned that the st.overrideAttrs should be added to the overlays when using dwm with dwm changes and st changes the overlay could look like this

nixpkgs.overlays = [
  (self: super: {
    dwm = super.dwm.overrideAttrs (oldAttrs: rec {
      patches = [
        ./path/to/my-dwm-patch.patch
        ];
      configFile = super.writeText "config.h" (builtins.readFile ./dwm-config.h);
      postPatch = oldAttrs.postPatch or "" + "\necho 'Using own config file...'\n cp ${configFile} config.def.h";
      });
    })
    st = super.st.overrideAttrs (oldAttrs: rec {
      patches = [
        ./path/to/my-dwm-patch.patch
        ];
      configFile = super.writeText "config.h" (builtins.readFile ./st-config.h);
      postPatch = "${oldAttrs.postPatch}\ncp ${configFile} config.def.h\n"
      });
    })
  ];

Remote config

If instead, you would prefer to build a pre-configured repository or realize more intense configuration, fork the mainline repository (or find one you like) and replace the value of the src attribute in the override.

Forks

Luke smiths st fork is used as the example

environment.systemPackages = with pkgs; [
  (st.overrideAttrs (oldAttrs: rec {
    src = fetchFromGitHub {
      owner = "LukeSmithxyz";
      repo = "st";
      rev = "8ab3d03681479263a11b05f7f1b53157f61e8c3b";
      sha256 = "1brwnyi1hr56840cdx0qw2y19hpr0haw4la9n0rqdn0r2chl8vag";
    };
    # Make sure you include whatever dependencies the fork needs to build properly!
    buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
  # If you want it to be always up to date use fetchTarball instead of fetchFromGitHub
  # src = builtins.fetchTarball {
  #   url = "https://github.com/lukesmithxyz/st/archive/master.tar.gz";
  # };
  }))
];

Troubleshooting

See files after patching

st-test.nix
with import <nixpkgs> {};

(st.overrideAttrs (oldAttrs: rec {
  buildInputs = oldAttrs.buildInputs ++ [ harfbuzz ];
  patches = [
    (fetchpatch {
      url = "https://st.suckless.org/patches/ligatures/0.8.3/st-ligatures-20200430-0.8.3.diff";
      sha256 = "18fllssg5d5gik1x0ppz232vdphr0y2j5z8lhs5j9zjs8m9ria5w";
    })
  ];
}))
$ nix-shell st-test.nix
$ unpackPhase
$ ls
$ cd theunpackeddir
$ patchPhase

Additional phases