This commit is contained in:
atagen 2024-08-20 11:19:45 +10:00
parent c8ee397794
commit 7f3dc64568
10 changed files with 302 additions and 47 deletions

38
flakes/meat/flake.lock generated Normal file
View file

@ -0,0 +1,38 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1723362943,
"narHash": "sha256-dFZRVSgmJkyM0bkPpaYRtG/kRMRTorUIDj8BxoOt1T4=",
"path": "/nix/store/h60m1fwahjd2mv6gsg77ji3vb4gpj4dk-source",
"rev": "a58bc8ad779655e790115244571758e8de055e3d",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"src": "src"
}
},
"src": {
"flake": false,
"locked": {
"lastModified": 1,
"narHash": "sha256-driDd0H33lcvEb5fnsUnLZ9Df+m7MNJvBvqQ7KB4+iA=",
"path": "src",
"type": "path"
},
"original": {
"path": "src",
"type": "path"
}
}
},
"root": "root",
"version": 7
}

74
flakes/meat/flake.nix Normal file
View file

@ -0,0 +1,74 @@
{
description = "the meat (package) manager";
inputs = {
# use registry nixpkgs
# nixpkgs.url = "nixpkgs/nixos-unstable";
src = {
url = "path:src";
flake = false;
};
};
outputs = {
self,
nixpkgs,
src,
}: let
# System types to support.
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
# overlays = [self.overlay];
});
in {
# Provide some binary packages for selected system types.
packages = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in {
meat = pkgs.callPackage ./meat.nix {
inherit src;
};
});
# The default package for 'nix build'. This makes sense if the
# flake provides only one package or there is a clear "main"
# package.
defaultPackage = forAllSystems (system: self.packages.${system}.meat);
# A NixOS module, if applicable (e.g. if the package provides a system service).
nixosModules.meat = {
pkgs,
config,
...
}: {
options.programs.meat = with pkgs.lib; {
flake = mkOption {
type = with types; nullOr (either path str);
default = null;
description = "path to your system flake";
};
};
config = {
environment.systemPackages = [self.defaultPackage.${pkgs.system}];
environment.sessionVariables = let
cfg = config.programs.meat;
in {
FLAKE =
if (cfg.flake == null)
then throw "Please set the programs.meat.flake option to your system flake."
else config.programs.meat.flake;
};
};
};
# Tests run by 'nix flake check' and by Hydra.
};
}

39
flakes/meat/meat.nix Normal file
View file

@ -0,0 +1,39 @@
{
lib,
src,
stdenvNoCC,
bash,
nix,
nh,
git,
sudo,
makeWrapper,
}: let
deps = [
bash
nix
nh
git
sudo
];
in
stdenvNoCC.mkDerivation {
inherit src;
name = "meat";
version = "0.0.1";
nativeBuildInputs = [
makeWrapper
];
buildInputs = deps;
installPhase = ''
mkdir -p $out/bin
cp meat $out/bin
'';
postFixup = ''
wrapProgram $out/bin/meat \
--set PATH ${lib.makeBinPath deps}
'';
meta = {
mainProgram = "meat";
};
}

54
flakes/meat/src/meat Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env bash
cmd=${1:help}
shift
call_nix() {
cd $(dirname $0)
nixpkgs_pin=$(nix eval --raw -f npins/default.nix nixpkgs)
nix_path="nixpkgs=${nixpkgs_pin}:nixos-config=${HOME}/.nix/entry.nix"
local cmd=$1
shift
env NIX_PATH="${nix_path}" nixos-rebuild "$cmd" --fast "$@"
}
cd $FLAKE
case $cmd in
look)
nix flake show
;;
fresh)
nix flake update "$@"
;;
yum)
nh os switch -- "$@"
# call_nix switch "$@"
;;
cook)
nh os build "$@"
# call_nix build "$@"
;;
poke)
nh os build -- --show-trace "$@"
# call_nix build --show-trace "$@"
;;
help|*)
printf "
--- MEAT ---------------------------------------------
FRESH \t\t| GET LATEST MEAT
YUM \t\t| CONSUME DELICIOUS MEAT
COOK \t\t| ONLY PREPARE MEAT
POKE \t\t| TRY COOK SUSPICIOUS MEAT
LOOK \t\t| INSPECT MEATS
------------------------------------------------------\n"
;;
esac
cd $PWD