From efd59cafa39a475b3a392b0fc164b9211044e91e Mon Sep 17 00:00:00 2001 From: devcontainer-features <> Date: Thu, 17 Nov 2022 22:40:23 +0100 Subject: [PATCH] Initial commit --- .../dev_shell/devcontainer-feature.json | 6 ++ .devcontainer/dev_shell/install.sh | 4 + .devcontainer/devcontainer.json | 40 ++++++++++ .devcontainer/postCreateCommand.sh | 3 + .gitignore | 1 + CHANGELOG | 1 + LICENSE | 9 +++ README.md | 26 +++++++ flake.lock | 26 +++++++ flake.nix | 76 +++++++++++++++++++ src/hello.sh | 3 + 11 files changed, 195 insertions(+) create mode 100644 .devcontainer/dev_shell/devcontainer-feature.json create mode 100644 .devcontainer/dev_shell/install.sh create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/postCreateCommand.sh create mode 100644 .gitignore create mode 100644 CHANGELOG create mode 100644 LICENSE create mode 100644 README.md create mode 100644 flake.lock create mode 100644 flake.nix create mode 100755 src/hello.sh diff --git a/.devcontainer/dev_shell/devcontainer-feature.json b/.devcontainer/dev_shell/devcontainer-feature.json new file mode 100644 index 0000000..62ddc72 --- /dev/null +++ b/.devcontainer/dev_shell/devcontainer-feature.json @@ -0,0 +1,6 @@ +{ + "name": "DevShell", + "id": "dev_shell", + "version": "1.0.0", + "description": "A nix based dev shell" +} \ No newline at end of file diff --git a/.devcontainer/dev_shell/install.sh b/.devcontainer/dev_shell/install.sh new file mode 100644 index 0000000..911923c --- /dev/null +++ b/.devcontainer/dev_shell/install.sh @@ -0,0 +1,4 @@ +#!/bin/env sh + +echo 'nix --experimental-features "nix-command flakes" develop' >/usr/bin/devShell +chmod +x /usr/bin/devShell diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..24044ad --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +{ + "name": "Ubuntu", + "image": "mcr.microsoft.com/devcontainers/base:jammy", + // Features to add to the dev container. More info: https://containers.dev/implementors/features. + "features": { + "ghcr.io/devcontainers/features/docker-from-docker:1": {}, + "ghcr.io/devcontainers/features/nix:1": {}, + "./dev_shell": {} + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": ".devcontainer/postCreateCommand.sh", + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.profiles.linux": { + "dev": { + "path": "/usr/bin/devShell", + "icon": "terminal-bash" + } + }, + "terminal.integrated.defaultProfile.linux": "dev" + }, + "extensions": [ + "jnoortheen.nix-ide", + "ms-azuretools.vscode-docker", + "eamodio.gitlens", + "streetsidesoftware.code-spell-checker", + "timonwong.shellcheck", + "foxundermoon.shell-format" + ] + } + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100755 index 0000000..e0d4895 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,3 @@ +#!/bin/env sh + +nix-env -i nixpkgs-fmt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2f5dd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/CHANGELOG @@ -0,0 +1 @@ +# Changelog diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..04d8fab --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2022 stubbfel + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..156d603 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# + +## Nix Flake commands + +```sh +# nix flake are experimental and required following options --experimental-features 'nix-command flakes' +# create alias for nix --experimental-features 'nix-command flakes' + +alias nixe && echo Alias for nixe exists || alias nixe="nix --experimental-features 'nix-command flakes'" + +# build +nixe build + +# run +nixe run + +# open development shell +nixe develop + +# update flake.lock +nixe run .#devTasks.updateFlakeLock + +# tag project +nixe run .#devTasks.autoTag + +``` \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..bcb4a4e --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1668595291, + "narHash": "sha256-j8cyfbtT5sAYPYwbERgTDzfD48ZernL0/V668eGpXAM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6474d93e007e4d165bcf48e7f87de2175c93d10b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.05-small", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..dfa2fa0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,76 @@ +{ + description = "A `devcontainer` feature which install a nix based dev shell "; + inputs.nixpkgs.url = "nixpkgs/nixos-22.05-small"; + + outputs = { self, nixpkgs }: + let + name = "nix-dev-shell"; + version = "0.0.1"; + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + devTaskScripts = forAllSystems (system: + { + autoTag = nixpkgsFor.system.writeScript "auto_tag.sh" '' + git tag --force vversion + git push origin vversion + ''; + }); + in + rec { + packages = forAllSystems (system: + { + default = nixpkgsFor.system.stdenv.mkDerivation { + name = name; + src = self; + buildPhase = "echo nothing todo"; + installPhase = "mkdir -p out/bin; install -t out/bin src/hello.sh"; + }; + }); + + apps = forAllSystems (system: + let + updateLockScript = nixpkgsFor.system.writeShellScriptBin "update_flake_lock.sh" '' + nix --experimental-features 'nix-command flakes' flake lock --update-input nixpkgs + nix --experimental-features 'nix-command flakes' build + ''; + in + { + default = { type = "app"; program = "packages.${system.default}/bin/hello.sh"; }; + devTasks = { + updateFlakeLock = { type = "app"; program = "updateLockScript/bin/update_flake_lock.sh"; }; + autoTag = { type = "app"; program = "devTaskScripts.${system.autoTag}"; }; + }; + }); + + devShells = forAllSystems (system: + { + default = nixpkgsFor.system.mkShell { + name = "dev-shell"; + packages = [ ]; + shellHook = '' + alias nixe="nix --experimental-features 'nix-command flakes'" + ''; + }; + }); + + hydraJobs = { + tarball = nixpkgsFor.x86_64-linux.releaseTools.sourceTarball { + name = name; + src = self; + version = version; + officialRelease = true; + bootstrapBuildInputs = [ ]; + distPhase = '' + mkdir out/tarballs + tar -czvf out/tarballs/name-version.tar.gz * + ''; + }; + + runCommandHook = { + recurseForDerivations = { }; + autoTag = devTaskScripts.x86_64-linux.autoTag; + }; + }; + }; +} diff --git a/src/hello.sh b/src/hello.sh new file mode 100755 index 0000000..2202fe7 --- /dev/null +++ b/src/hello.sh @@ -0,0 +1,3 @@ +#!/bin/env bash + +echo "hello world" \ No newline at end of file