feat: initialise Nix tooling
Adds a package, and a dev shell for Discorss. `nix run .#` and `nix develop` will be allowed in the current mechanism, but direnv users can simply use `direnv allow` to enter a shell directly.
This commit is contained in:
parent
457e2c3315
commit
a22a2235c5
4 changed files with 115 additions and 0 deletions
53
nix/package.nix
Normal file
53
nix/package.nix
Normal file
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
lib,
|
||||
stdenvNoCC,
|
||||
makeWrapper,
|
||||
python312,
|
||||
...
|
||||
}:
|
||||
stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
pname = "discorss";
|
||||
version = "0.0.1";
|
||||
|
||||
# Point to the repository root for the source. `builtins.path` is used to construct
|
||||
# a pure and reproducible source path that doesn't change based on the name
|
||||
# of the directory our source code lives in. Alternative to this is to just use it
|
||||
# directly, as follows:
|
||||
# `src = ../.;`
|
||||
src = builtins.path {
|
||||
path = ../.;
|
||||
name = "discorss"; # the directory will always be named discorss in the eyes of Nix
|
||||
filter = lib.cleanSourceFilter; # avoid copying junk files and vsc dirs to the store
|
||||
};
|
||||
|
||||
# programs and libraries *used at build-time* that, if they are a compiler or similar tool, produce
|
||||
# code to run at run-time. In other words, tools used to build the new derivation
|
||||
# Alternative is buildInputs, which includes programs and libraries used by the new derivation at run-time
|
||||
nativeBuildInputs = [makeWrapper];
|
||||
|
||||
# Normally propagatedBuildInputs get, well, propagated to the final build. This is not the
|
||||
# case for s since we omit a handful of shell hooks that would handle it for us. We can
|
||||
# still use propagatedBuildInputs to remain close to the standard, but we will have to
|
||||
# pass it to the wrapper manually.
|
||||
propagatedBuildInputs = [
|
||||
# Create a python wrapper with the dependencies that we need.
|
||||
# This will produce a /nix/store/some-hash-python/bin/python3 that has the modules
|
||||
# our program needs.
|
||||
(python312.withPackages (ps: with ps; [feedparser requests]))
|
||||
];
|
||||
|
||||
dontUnpack = true; # source is not an archive
|
||||
dontConfigure = true; # there is no configure script
|
||||
dontPatch = true; # we are building from source, patches are redundant
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
# Create a wrapper for Discorss with the specific version of Python (with dependencies)
|
||||
# added to its PATH.
|
||||
makeWrapper $src/discorss.py $out/bin/discorss \
|
||||
--prefix PATH : "${lib.makeBinPath finalAttrs.propagatedBuildInputs}"
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue