diff --git a/home-manager/common.nix b/home-manager/common.nix index c4352dc..02c83a9 100644 --- a/home-manager/common.nix +++ b/home-manager/common.nix @@ -27,6 +27,9 @@ in { cat = lib.mkDefault "bat --paging=never"; nixfix = lib.mkDefault "nix fmt ./**/*.nix"; + aws-export-credentials = lib.mkDefault "aws configure export-credentials --format env --profile"; + # use curl-aws --aws-sigv4 "aws:amz:region:service" + curl-aws = lib.mkDefault "curl -H \"X-Amz-Security-Token: $AWS_SESSION_TOKEN\" --user \"$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY\""; } // ( if isDarwin then diff --git a/home-manager/flake-templates/c3c-flake.nix b/home-manager/flake-templates/c3c-flake.nix new file mode 100644 index 0000000..4913c6d --- /dev/null +++ b/home-manager/flake-templates/c3c-flake.nix @@ -0,0 +1,53 @@ +{ + inputs = { + nix.url = "git+ssh://git@git.c3c.cz/C3C/nix"; + }; + + outputs = + { self, nix }: + { + formatter = nix.formatter; + + devShells = nix.lib.forAllSystems (pkgs: { + default = nix.lib.mkDevenvShell { + inherit pkgs; + inputs = { + self = self; + nixpkgs = pkgs; + }; + + modules = [ + { + packages = with pkgs; [ + + ]; + + scripts = { + menu = { + description = "Print this menu"; + exec = '' + echo "Commands:" + echo -n ${ + builtins.toJSON ( + builtins.mapAttrs (s: value: value.description) self.devShells.${pkgs.system}.default.config.scripts + ) + }' | \ + ${pkgs.jq}/bin/jq -r 'to_entries | map(" \(.key)\n" + " - \(if .value == "" then "no description provided" else .value end)") | "" + .[]' + ''; + }; + + fix = { + exec = '' + ${nix.lib.cd_root} + nix fmt ./*.nix + ${pkgs.golangci-lint}/bin/golangci-lint run --sort-results --out-format tab --config ${nix.lib.golangci-config-file} --fix --issues-exit-code 0 ./... + stylua ./src + ''; + }; + }; + } + ]; + }; + }); + }; +} diff --git a/home-manager/lcech-mac-veracode.nix b/home-manager/lcech-mac-veracode.nix index 9ce861e..73b8ebb 100644 --- a/home-manager/lcech-mac-veracode.nix +++ b/home-manager/lcech-mac-veracode.nix @@ -15,6 +15,9 @@ in (import ./veracode/aws-cli.nix { inherit homedir lib pkgs; }) + (import ./nix-init-scripts.nix { + inherit lib pkgs; + }) ]; home.username = username; diff --git a/home-manager/nix-init-scripts.nix b/home-manager/nix-init-scripts.nix new file mode 100644 index 0000000..2e20dc4 --- /dev/null +++ b/home-manager/nix-init-scripts.nix @@ -0,0 +1,56 @@ +{ lib, pkgs, ... }: +let + git-nix-clone = '' + # Input is a git repository such as git@github.com:group/project-name.git + run() { + local repo="$1" + local projectName=$(echo "$repo" | sed 's/.*\///' | sed 's/\.git//') + + if [ "$repo" = "" ]; then + echo "Usage: git-nix-clone " + exit 1 + fi + + echo "Clone $repo into ''${projectName}-nix/''${projectName}?" + read -p "continue?" answer + + if [ "$answer" != "" ]; then + echo "Aborting" + exit 1 + fi + + mkdir -p "$projectName"-nix + cd "$projectName"-nix + + git init + + # Insert the nix flake + cp ${./flake-templates/c3c-flake.nix} flake.nix + chmod 644 flake.nix + + echo '/.envrc' > .gitignore + echo '/.devenv' >> .gitignore + echo '/.direnv' >> .gitignore + echo 'use flake . --impure' > .envrc + + git add flake.nix .gitignore + git commit -m "Setup initial flake" + + direnv allow + eval "$(direnv export bash)" + + git add flake.lock + git commit -m "Lock flakes" + + git clone "$repo" + } + + run "$@" + ''; +in +{ + programs.zsh.shellAliases = { + git-nix-clone = lib.mkDefault "${pkgs.writeShellScript "git-nix-clone" git-nix-clone}"; + }; + +}