Skip to content

Commit 7cdfd74

Browse files
committed
flake: add template
1 parent 9a34f9d commit 7cdfd74

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

flake.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,19 @@
199199
# Use nixpkgs-fmt for 'nix fmt'
200200
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
201201

202+
# Each subdirectory in ./templates/<template-name> is a
203+
# template, which can be used for new proects with:
204+
# `nix flake init`
205+
templates = builtins.listToAttrs (
206+
map (name: {
207+
inherit name;
208+
value = {
209+
path = ./templates + "/${name}";
210+
description = (import (./templates + "/${name}/flake.nix")).description;
211+
};
212+
}) (builtins.attrNames (builtins.readDir ./templates))
213+
);
214+
202215
# Output all modules in ./modules/<module-name> to flake. Modules should be in
203216
# individual subdirectories and contain a default.nix file.
204217
# Each subdirectory in ./modules/<module-name> is a nixos module

home-manager/modules/shell/default.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ in
7171
pinpox.defaults.shell.abbrev-aliases = [
7272

7373
# Aliases expanded only at beginning of lines
74+
{
75+
alias = "flake-init";
76+
command = "nix flake init -t github:pinpox/nixos";
77+
}
7478
{
7579
alias = "g";
7680
command = "git";

templates/default/flake.nix

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
description = "A simple Go package";
3+
4+
# Nixpkgs / NixOS version to use.
5+
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
6+
7+
outputs = { self, nixpkgs }:
8+
let
9+
10+
# to work with older version of flakes
11+
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
12+
13+
# Generate a user-friendly version number.
14+
version = builtins.substring 0 8 lastModifiedDate;
15+
16+
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
17+
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
18+
19+
# Nixpkgs instantiated for supported system types.
20+
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
21+
22+
in
23+
{
24+
25+
# Provide some binary packages for selected system types.
26+
packages = forAllSystems (system:
27+
let
28+
pkgs = nixpkgsFor.${system};
29+
in
30+
{
31+
default = pkgs.buildGoModule {
32+
pname = "go-hello";
33+
inherit version;
34+
# In 'nix develop', we don't need a copy of the source tree
35+
# in the Nix store.
36+
src = ./.;
37+
38+
# This hash locks the dependencies of this package. It is
39+
# necessary because of how Go requires network access to resolve
40+
# VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for
41+
# details. Normally one can build with a fake hash and rely on native Go
42+
# mechanisms to tell you what the hash should be or determine what
43+
# it should be "out-of-band" with other tooling (eg. gomod2nix).
44+
# To begin with it is recommended to set this, but one must
45+
# remember to bump this hash when your dependencies change.
46+
# vendorHash = pkgs.lib.fakeHash;
47+
48+
vendorHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
49+
};
50+
});
51+
52+
# Add dependencies that are only needed for development
53+
devShells = forAllSystems (system:
54+
let
55+
pkgs = nixpkgsFor.${system};
56+
in
57+
{
58+
default = pkgs.mkShell {
59+
buildInputs = with pkgs; [ go gopls gotools go-tools ];
60+
};
61+
});
62+
};
63+
}

0 commit comments

Comments
 (0)