Add nix-based build environment

This commit is contained in:
Konstantin Nazarov 2023-09-30 14:41:23 +01:00
parent 3c0f0f157c
commit 2b00252635
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
3 changed files with 501 additions and 422 deletions

26
flake.lock Normal file
View file

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1696078222,
"narHash": "sha256-QBqNSFSPitmvpF2SPqTXbPKo7Wr3kv7cY4zjhCTsHRU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e4f393e78df6fe1986f24b018e60264e89b5c8de",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

53
flake.nix Normal file
View file

@ -0,0 +1,53 @@
{
description = "Nix notes.sh dev environment";
# Flake inputs
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
# Flake outputs
outputs = { self, nixpkgs }:
let
# Systems supported
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
# Helper to provide system-specific attributes
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
make_package = pkgs: pkgs.stdenv.mkDerivation {
name = "notes-sh";
src = self;
nativeBuildInputs = [pkgs.makeWrapper];
installPhase = ''
mkdir -p $out/bin
cp notes.sh $out/bin
'';
postFixup = ''
wrapProgram $out/bin/notes.sh \
--prefix PATH : ${pkgs.lib.makeBinPath (with pkgs; [ gawk findutils gnused coreutils])}
'';
};
in
{
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell {
packages = with pkgs; [
fzf
];
};
});
packages = forAllSystems({ pkgs }: rec {notes-sh = make_package pkgs; default=notes-sh;});
overlays.default = final: prev: {
notes-sh = make_package prev;
};
};
}

View file

@ -354,7 +354,7 @@ input_note() {
EOF EOF
OLD_DIR="$(pwd)" OLD_DIR="$(pwd)"
cd "$DIR" cd "$DIR"
"$EDITOR" "$ENTRY_FILE" $EDITOR "$ENTRY_FILE"
cd "$OLD_DIR" cd "$OLD_DIR"
else else
while read -r line ; do while read -r line ; do
@ -466,7 +466,7 @@ edit_entry() {
OLD_DIR="$(pwd)" OLD_DIR="$(pwd)"
cd "$DIR" cd "$DIR"
if ! "$EDITOR" "$DIR/note.md"; then if ! $EDITOR "$DIR/note.md"; then
die "Editor returned non-zero exit code. Leaving the note untouched." die "Editor returned non-zero exit code. Leaving the note untouched."
fi fi
cd "$OLD_DIR" cd "$OLD_DIR"