From adfdaf186573a02c8654d142c8548e614804b4f0 Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Thu, 9 Nov 2023 22:05:18 +0100 Subject: [PATCH] pinwheel: Add `skal` to handle `nix develop` shells --- hosts/pinwheel/configuration.nix | 4 ++ hosts/pinwheel/modules/skal/default.nix | 55 +++++++++++++++++++ .../pinwheel/modules/skal/flake-template.nix | 18 ++++++ 3 files changed, 77 insertions(+) create mode 100644 hosts/pinwheel/modules/skal/default.nix create mode 100644 hosts/pinwheel/modules/skal/flake-template.nix diff --git a/hosts/pinwheel/configuration.nix b/hosts/pinwheel/configuration.nix index 3040c68..c52e452 100644 --- a/hosts/pinwheel/configuration.nix +++ b/hosts/pinwheel/configuration.nix @@ -75,6 +75,10 @@ }; mod = { + skal = { + path = "/home/alex/code/own/skal"; + }; + nix-index.enable = false; greetd.enable = true; hyprland.enable = true; diff --git a/hosts/pinwheel/modules/skal/default.nix b/hosts/pinwheel/modules/skal/default.nix new file mode 100644 index 0000000..b45c749 --- /dev/null +++ b/hosts/pinwheel/modules/skal/default.nix @@ -0,0 +1,55 @@ +{ 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 + echo Creating flake "$FLAKE_DIR" + mkdir -p "$FLAKE_DIR" + FLAKE="$FLAKE_DIR"/flake.nix + cp ${./flake-template.nix} "$FLAKE" + chmod 700 "$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 ]; + }; + }; +} diff --git a/hosts/pinwheel/modules/skal/flake-template.nix b/hosts/pinwheel/modules/skal/flake-template.nix new file mode 100644 index 0000000..2f280cf --- /dev/null +++ b/hosts/pinwheel/modules/skal/flake-template.nix @@ -0,0 +1,18 @@ +{ + description = ""; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + + outputs = { nixpkgs, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells."${system}".default = pkgs.mkShell { + packages = []; + }; + }; +}