Rework skal to be the shared nix-wrapper module
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
imports =
|
imports =
|
||||||
[
|
[
|
||||||
../../config-manager/default.nix
|
../../config-manager/default.nix
|
||||||
|
../../nix-wrapper/default.nix
|
||||||
../../shared-modules/syncthing.nix
|
../../shared-modules/syncthing.nix
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
./modules
|
./modules
|
||||||
@@ -74,11 +75,11 @@
|
|||||||
flakePath = "/home/alex/config";
|
flakePath = "/home/alex/config";
|
||||||
};
|
};
|
||||||
|
|
||||||
mod = {
|
nix-wrapper = {
|
||||||
skal = {
|
flakesPath = "/home/alex/code/own/flakes";
|
||||||
path = "/home/alex/code/own/skal";
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
mod = {
|
||||||
nix-index.enable = false;
|
nix-index.enable = false;
|
||||||
greetd.enable = true;
|
greetd.enable = true;
|
||||||
hyprland.enable = true;
|
hyprland.enable = true;
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
{ pkgs, lib, config, ... }:
|
|
||||||
let
|
|
||||||
skalPath = config.mod.skal.path;
|
|
||||||
|
|
||||||
skal =
|
|
||||||
if skalPath == "" then
|
|
||||||
throw "'skal.path' cannot be empty"
|
|
||||||
else
|
|
||||||
pkgs.writeShellScriptBin "skal" ''
|
|
||||||
URL=`git config --get remote.origin.url`
|
|
||||||
GITHOST=`echo $URL | sed -e s/.*@// | sed -e s/:.*//`
|
|
||||||
GITPATH=`echo $URL | sed -e s/.*:// | sed -e s/.git$//`
|
|
||||||
|
|
||||||
FLAKE_DIR="${skalPath}/$GITHOST/$GITPATH"
|
|
||||||
|
|
||||||
if [ "$1" == "create" ]; then
|
|
||||||
if [ ! -d "$FLAKE_DIR" ]; then
|
|
||||||
PWD=$(pwd)
|
|
||||||
echo Creating flake '"$FLAKE_DIR' using '$PWD' as source path"
|
|
||||||
mkdir -p "$FLAKE_DIR"
|
|
||||||
|
|
||||||
FLAKE="$FLAKE_DIR"/flake.nix
|
|
||||||
cp ${./flake-template.nix} "$FLAKE"
|
|
||||||
chmod 700 "$FLAKE"
|
|
||||||
sed -i -e "s|SRC_PATH|$PWD|" "$FLAKE"
|
|
||||||
|
|
||||||
${pkgs.vim}/bin/vim "$FLAKE"
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo Flake already exist
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d $FLAKE_DIR ]; then
|
|
||||||
echo No flake exist for "$FLAKE_DIR"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo Using "$FLAKE_DIR"
|
|
||||||
nix develop $FLAKE_DIR $*
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
mod.skal = {
|
|
||||||
path = lib.mkOption {
|
|
||||||
description = "path to where all flake.nix reside";
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
|
||||||
home-manager.users.alex = {
|
|
||||||
home.packages = [ skal ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
101
nix-wrapper/default.nix
Normal file
101
nix-wrapper/default.nix
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
{ pkgs, lib, config, ... }:
|
||||||
|
let
|
||||||
|
flakesPath = config.nix-wrapper.flakesPath;
|
||||||
|
|
||||||
|
nix-wrapper =
|
||||||
|
if flakesPath == "" then
|
||||||
|
throw "'nix-wrapper.flakesPath' cannot be empty"
|
||||||
|
else
|
||||||
|
pkgs.writeShellScriptBin "nix-wrapper" ''
|
||||||
|
URL=`git config --get remote.origin.url`
|
||||||
|
GITHOST=`echo $URL | sed -e s/.*@// | sed -e s/:.*//`
|
||||||
|
GITPATH=`echo $URL | sed -e s/.*:// | sed -e s/.git$//`
|
||||||
|
FLAKE_PATH="${flakesPath}/$GITHOST/$GITPATH"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat << EOF
|
||||||
|
Usage:
|
||||||
|
nix-wrapper [options]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c create a flake.nix for the current path
|
||||||
|
-e edit the flake.nix for the current path
|
||||||
|
-a <attribute> target a specific attribute
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
create() {
|
||||||
|
if [ -d "$FLAKE_PATH" ]; then
|
||||||
|
echo "flake.nix already exist at $FLAKE_PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
PWD=$(pwd)
|
||||||
|
echo "Creating flake.nix in '$FLAKE_PATH' using '$PWD' as source path"
|
||||||
|
mkdir -p "$FLAKE_PATH"
|
||||||
|
|
||||||
|
FLAKE="$FLAKE_PATH"/flake.nix
|
||||||
|
cp ${./flake-template.nix} "$FLAKE"
|
||||||
|
chmod 700 "$FLAKE"
|
||||||
|
sed -i -e "s|./SRC_PATH|$PWD|" "$FLAKE"
|
||||||
|
|
||||||
|
${pkgs.vim}/bin/vim "$FLAKE"
|
||||||
|
}
|
||||||
|
|
||||||
|
edit() {
|
||||||
|
if [ ! -d "$FLAKE_PATH" ]; then
|
||||||
|
echo "no flake.nix exist for '$FLAKE_PATH'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
${pkgs.vim}/bin/vim "$FLAKE_PATH/flake.nix"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "$#" -eq 0 ] && usage && exit 0
|
||||||
|
|
||||||
|
ATTR=""
|
||||||
|
while getopts "cea:" opt; do
|
||||||
|
case "$opt" in
|
||||||
|
c)
|
||||||
|
create
|
||||||
|
exit 0 ;;
|
||||||
|
e)
|
||||||
|
edit
|
||||||
|
exit 0 ;;
|
||||||
|
a)
|
||||||
|
ATTR="$OPTARG" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift "$((OPTIND-1))"
|
||||||
|
|
||||||
|
if [ ! -d "$FLAKE_PATH" ]; then
|
||||||
|
echo "no flake.nix exist for '$FLAKE_PATH'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -n "$ATTR" ] && FLAKE_PATH="$FLAKE_PATH#$ATTR"
|
||||||
|
nix $@ "$FLAKE_PATH"
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
nix-wrapper = {
|
||||||
|
flakesPath = lib.mkOption {
|
||||||
|
description = "path to where all flake.nix reside";
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
environment = {
|
||||||
|
shellAliases = {
|
||||||
|
nw = "${nix-wrapper}/bin/nix-wrapper";
|
||||||
|
};
|
||||||
|
|
||||||
|
systemPackages = [ nix-wrapper ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -11,13 +11,17 @@
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages = nixpkgs.lib.genAttrs systems (system:
|
packages = nixpkgs.lib.genAttrs systems (system:
|
||||||
# let
|
let
|
||||||
# pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
# in
|
in
|
||||||
{
|
{
|
||||||
default = {
|
# `derivation` may be filled out or switched
|
||||||
src = SRC_PATH;
|
# to something like `pkgs.buildGoModule`
|
||||||
|
default = derivation {
|
||||||
|
src = ./SRC_PATH;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hello = pkgs.hello;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Reference in New Issue
Block a user