diff options
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3308ce1 --- /dev/null +++ b/flake.nix | |||
@@ -0,0 +1,58 @@ | |||
1 | { | ||
2 | description = "A very basic flake"; | ||
3 | |||
4 | inputs = { | ||
5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; | ||
6 | }; | ||
7 | |||
8 | outputs = | ||
9 | { self | ||
10 | , nixpkgs | ||
11 | }: | ||
12 | let | ||
13 | supportedSystems = [ "x86_64-linux" ]; | ||
14 | forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); | ||
15 | |||
16 | nixpkgsFor = forAllSystems (system: | ||
17 | import nixpkgs { inherit system; } | ||
18 | ); | ||
19 | |||
20 | in | ||
21 | { | ||
22 | devShell = forAllSystems | ||
23 | (system: | ||
24 | let | ||
25 | pkgs = nixpkgsFor."${system}"; | ||
26 | in | ||
27 | with pkgs; | ||
28 | mkShell { | ||
29 | nativeBuildInputs = [ gcc ]; | ||
30 | }); | ||
31 | |||
32 | apps = forAllSystems | ||
33 | (system: | ||
34 | let | ||
35 | pkgs = nixpkgsFor."${system}"; | ||
36 | execs = with builtins; map toString [ 1 2 ]; | ||
37 | mkApp = name: with pkgs; stdenv.mkDerivation { | ||
38 | name = "${name}"; | ||
39 | src = ./src; | ||
40 | buildInputs = [ gcc ]; | ||
41 | unpackPhase = '' | ||
42 | true | ||
43 | ''; | ||
44 | buildPhase = '' | ||
45 | gcc -o main $src/${name}/main.c -fopenmp | ||
46 | ''; | ||
47 | installPhase = '' | ||
48 | install -Dm755 main $out/bin/main | ||
49 | ''; | ||
50 | }; | ||
51 | in | ||
52 | with pkgs; | ||
53 | lib.genAttrs execs (p: { | ||
54 | type = "app"; | ||
55 | program = "${mkApp p}/bin/main"; | ||
56 | })); | ||
57 | }; | ||
58 | } | ||