Skip to content

Commit 38b7c2e

Browse files
committed
Added nix flake
1 parent b44964e commit 38b7c2e

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
description = "Mongoose OS command line tool";
3+
4+
# Nixpkgs / NixOS version to use.
5+
inputs.nixpkgs.url = "github:NixOS/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+
# System types to support.
17+
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
18+
19+
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
20+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
21+
22+
# Nixpkgs instantiated for supported system types.
23+
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
24+
25+
in
26+
{
27+
28+
# Provide some binary packages for selected system types.
29+
packages = forAllSystems (system:
30+
let
31+
pkgs = nixpkgsFor.${system};
32+
in
33+
{
34+
default = pkgs.buildGoModule {
35+
pname = "mos";
36+
inherit version;
37+
# In 'nix develop', we don't need a copy of the source tree
38+
# in the Nix store.
39+
src = ./.;
40+
41+
# This hash locks the dependencies of this package. It is
42+
# necessary because of how Go requires network access to resolve
43+
# VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for
44+
# details. Normally one can build with a fake hash and rely on native Go
45+
# mechanisms to tell you what the hash should be or determine what
46+
# it should be "out-of-band" with other tooling (eg. gomod2nix).
47+
# To begin with it is recommended to set this, but one must
48+
# remember to bump this hash when your dependencies change.
49+
# vendorHash = pkgs.lib.fakeHash;
50+
51+
vendorHash = "sha256-PpzclrsG7HYwbowGCbMQFj6+/w+svyMzkxYh2VpR18Y=";
52+
53+
preBuild = ''
54+
echo "package version
55+
const (
56+
Version = \"${version}\"
57+
BuildId = \"${self.rev or self.dirtyRev}\"
58+
BuildTimestamp = \"${lastModifiedDate}\"
59+
)" > version/version.go
60+
'';
61+
62+
nativeBuildInputs = with pkgs; [ pkg-config ];
63+
64+
buildInputs = with pkgs; [ libusb1 libftdi1 ];
65+
};
66+
});
67+
68+
apps = forAllSystems (system: {
69+
default = {
70+
type = "app";
71+
program = "${self.packages.${system}.default}/bin/cli";
72+
};
73+
instance = {
74+
type = "app";
75+
program = "${self.packages.${system}.default}/bin/instance";
76+
};
77+
manager = {
78+
type = "app";
79+
program = "${self.packages.${system}.default}/bin/manager";
80+
};
81+
}
82+
);
83+
84+
# Add dependencies that are only needed for development
85+
devShells = forAllSystems (system:
86+
let
87+
pkgs = nixpkgsFor.${system};
88+
in
89+
{
90+
default = pkgs.mkShell {
91+
buildInputs = [ self.packages.${system}.default pkgs.esptool ];
92+
shellHook = ''
93+
alias mos=cli
94+
'';
95+
};
96+
});
97+
};
98+
}

0 commit comments

Comments
 (0)